{"id":13605075,"url":"https://github.com/pfalcon/utemplate","last_synced_at":"2025-03-16T12:33:03.572Z","repository":{"id":17558697,"uuid":"20361645","full_name":"pfalcon/utemplate","owner":"pfalcon","description":"Micro template engine in Python with low memory usage, designed for Pycopy, a minimalist Python dialect, but also compatible with other Pythons.","archived":false,"fork":false,"pushed_at":"2021-08-17T06:16:05.000Z","size":48,"stargazers_count":78,"open_issues_count":6,"forks_count":8,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-02-27T09:13:26.638Z","etag":null,"topics":["micropython","minimalist","nano-framework","pycopy","python","suckless","template-engine","unbloated"],"latest_commit_sha":null,"homepage":"https://github.com/pfalcon/pycopy","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pfalcon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-31T17:56:57.000Z","updated_at":"2024-12-04T01:43:56.000Z","dependencies_parsed_at":"2022-08-26T12:34:11.857Z","dependency_job_id":null,"html_url":"https://github.com/pfalcon/utemplate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pfalcon%2Futemplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pfalcon%2Futemplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pfalcon%2Futemplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pfalcon%2Futemplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pfalcon","download_url":"https://codeload.github.com/pfalcon/utemplate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814913,"owners_count":20352058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["micropython","minimalist","nano-framework","pycopy","python","suckless","template-engine","unbloated"],"created_at":"2024-08-01T19:00:54.443Z","updated_at":"2025-03-16T12:33:03.309Z","avatar_url":"https://github.com/pfalcon.png","language":"Python","funding_links":[],"categories":["Networking"],"sub_categories":[],"readme":"utemplate\n=========\n\n`utemplate` is a lightweight and memory-efficient template engine for\nPython, primarily designed for use with Pycopy, a lightweight Python\nimplementation (https://github.com/pfalcon/pycopy). It is also fully\ncompatible with CPython and other compliant Python implementations.\n\n`utemplate` syntax is roughly based on Django/Jinja2 syntax (e.g.\n`{% if %}`, `{{var}}`), but only the most needed features are offered\n(for example, \"filters\" (`{{var|filter}}`) are syntactic sugar for\nfunction calls, and so far are not planned to be implemented, function\ncalls can be used directly instead: `{{filter(var)}}`).\n\n`utemplate` compiles templates to Python source code, specifically to\na generator function which, being iterated over, produces consecutive\nparts (substrings) of the rendered template. This allows for minimal\nmemory usage during template substitution (with Pycopy, it starts\nfrom mere hundreds of bytes). Generated Python code can be imported as\na module directly, or a simple loader class (`utemplate.compiled.Loader`)\nis provided for convenience.\n\nThere is also a loader class which will compile templates on the fly,\nif not already compiled - `utemplate.source.Loader`.\n\nFinally, there's a loader which will automatically recompile a template\nmodule if source template is changed - `utemplate.recompile.Loader`.\nThis loader class is the most convenient to use during development, but\non the other hand, it performs extra processing not required for a\nfinished/deployed application.\n\nTo test/manage templates, `utemplate_util.py` tool is provided. For\nexample, to quickly try a template (assuming you are already in\n`examples/` dir):\n\n    pycopy ../utemplate_util.py run squares.tpl\n\nor\n\n    python3 ../utemplate_util.py run squares.tpl\n\nTemplates can take parameters (that's how dynamic content is generated).\nTemplate parameters are passed as arguments to a generator function\nproduced from a template. They also can be passed on the `utemplate_util.py`\ncommand line (arguments will be treated as strings in this case, but\ncan be of any types if called from your code):\n\n    pycopy ../utemplate_util.py run test1.tpl foo bar\n\nQuick Syntax Reference\n----------------------\n\nEvaluating Python expression, converting it to a string and outputting to\nrendered content:\n\n* `{{\u003cexpr\u003e}}`\n\nWhere `expr` is an arbitrary Python expression - from a bare variable name,\nto function calls, `yield from`/`await` expressions, etc.\n\nSupported statements:\n\n* `{% args \u003cvar1\u003e, \u003cvar2\u003e, ... %}` - specify arguments to a template\n  (optional, should be at the beginning of a template if you want to\n  pass any arguments). All argument types as supported by Python can\n  be used: positional and keyword, with default values, `*args` and\n  `**kwargs` forms, etc.\n* `{% if \u003cexpr\u003e %}`, `{% elif \u003cexpr\u003e %}`, `{% else %}`, `{% endif %}` -\n  similar to Python's `if` statement\n* `{% for \u003cvar\u003e in \u003cexpr\u003e %}`, `{% endfor %}` - similar to Python's\n  `for` statement\n* `{% while \u003cexpr\u003e %}`, `{% endwhile %}` - similar to Python's `while`\n  statement\n* `{% set \u003cvar\u003e = \u003cexpr\u003e %}` - assignment statement\n* `{% include \"name.tpl\" %}` - statically include another template\n* `{% include {{name}} %}` - dynamically include template whose name is\n  stored in variable `name`.\n\nFile Naming Conventions\n-----------------------\n\n* The recommended extension for templates is `.tpl`, e.g. `example.tpl`.\n* When template is compiled, dot (`.`) in its name is replaced\n  with underscore (`_`) and `.py` appended, e.g. `example_tpl.py`. It\n  thus can be imported with `import example_tpl`.\n* The name passed to `{% include %}` statement should be full name of\n  a template with extension, e.g. `{% include \"example.tpl\" %}`.\n* For dynamic form of the `include`, a variable should similarly contain\n  a full name of the template, e.g. `{% set name = \"example.tpl\" %}` /\n  `{% include {{name}} %}`.\n\nExamples\n--------\n\n`examples/squares.tpl` as mentioned in the usage examples above has the\nfollowing content:\n\n```\n{% args n=5 %}\n{% for i in range(n) %}\n| {{i}} | {{\"%2d\" % i ** 2}} |\n{% endfor %}\n```\n\nMore examples are available in the [examples/](examples/) directory.\n\nIf you want to see a complete example web application which uses `utemplate`,\nrefer to https://github.com/pfalcon/notes-pico .\n\nLicense\n-------\n\n`utemplate` is written and maintained by Paul Sokolovsky. It's available\nunder the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpfalcon%2Futemplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpfalcon%2Futemplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpfalcon%2Futemplate/lists"}