Last active
November 11, 2025 16:47
-
-
Save twolfson/b861c182107cefcef086266c3b4b83a6 to your computer and use it in GitHub Desktop.
Revisions
-
twolfson revised this gist
Oct 16, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ gist-python-templating-evaluation :format: html Evaluation and comparison of various Python templating libraries Last updated: October 2023 -
twolfson revised this gist
Oct 16, 2023 . No changes.There are no files selected for viewing
-
twolfson revised this gist
Oct 16, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -243,7 +243,7 @@ Running eval notes - [x] "pug python" - [x] Slim variations - [x] "slim python" (nothing) -
twolfson revised this gist
Oct 16, 2023 . No changes.There are no files selected for viewing
-
twolfson revised this gist
Oct 16, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -198,7 +198,7 @@ Comparison | | - https://github.com/nyaruka/django-hamlpy (archived) | | | - https://pypi.org/project/python-jade/#history (2017 + 0 stars) | | | - https://github.com/multiversecoder/pug4py (2020) | | | - https://pypi.org/project/slim4py/#history (2019) | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ Running eval notes -
twolfson revised this gist
Oct 16, 2023 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,11 @@ Conclusion and recommendation - Either Django, Jinja2, Mako, or Cheetah seem like decent choices (though Cheetah feels more like a bet) - I'd prob run Mako through some proof of concept work since it's closest to my preferences, then choose it - If the proof of concept fails, then I'd try Jinja2 (which I think I've used before) - Worst case is Django since I **know** that works (though not the friendliest) - Alternatively, I could try using PyPugJS or Plim since those get me even more mileage on preferences and possibly better syntax highlighting support -
twolfson revised this gist
Oct 16, 2023 . 1 changed file with 59 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,6 +12,16 @@ An evaluation and comparison of various Python templating libraries Last updated: October 2023 Conclusion and recommendation ----------------------------- - Either Django, Jinja2, Mako, or Cheetah seem like decent choices (though Cheetah feels more like a bet) - I'd prob run Mako through some proof of concept work since it's closest to my preferences - Alternatively, I could try using PyPugJS or Plim since those get me even more mileage on preferences and possibly better syntax highlighting support Criteria -------- @@ -117,19 +127,43 @@ Comparison | | (:raw-html:`<a href="https://github.com/youtube/spitfire/blob/1916e68d50ed30f395928585ef2f0d3ba1468ab0/doc/SpitfireVsCheetah.md">GitHub</a>`) | | | and the docs are much more absent than present =/ | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Kaijiki | https://github.com/jackrosenthal/kajiki | | | | | | 43 stars + last commit in Nov 2022 -- but... | | | | | | Copying Genshi and Jinja so not getting much new content | | | and seems to lack many features, https://docs.kajiki.io/templating-basics.html#template-expressions-and-code-blocks | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | PyPugJS | https://github.com/kakulukia/pypugjs | | | | | | 246 stars O_O + last commit Aug 2023! | | | | | | Transpiles from Pug to relevant language (e.g. Django, Jinja, Mako, Tornado) | | | and there's a loader for Django to avoid manually transpiling every time | | | | | | Does seem quite nice and expressive, but also guessing solo maintainer | | | and iffy longevity =/ (previous fork it's based on got archived before) | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Tornado | https://www.tornadoweb.org/en/stable/template.html | | | | | | Some pretty good features (though no better than Django or Jinja2) but stuck inside Tornado framework | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Plim | https://github.com/avanov/Plim | | | | | | Slim port for Python =D | | | | | | 2022 and 173 stars! | | | | | | Built on top of Mako, not digging much deeper since it's not independent ._. | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Not enough traction | - https://github.com/tetframework/Tonnikala, Some life (2022 update) but only 14 stars | | | - https://github.com/cesbit/trender, 2022 update but only 20 stars | | | - https://github.com/mikeboers/PyHAML (2019 + no Python 3 support) | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Too lightweight | - https://docs.python.org/3.4/library/string.html#template-strings | | | - https://www.stringtemplate.org/ | | | - Mustache (no inheritance and such) | | | - https://github.com/defunkt/pystache (it's just Mustache) | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Not maintained | - https://github.com/mll/ctemplate-python (last touched 2015) | | | - http://airspeed.pythonconsulting.com/ (site down) | @@ -156,6 +190,11 @@ Comparison | | - thrases: https://sourceforge.net/projects/the-next-please/ (2013) | | | - https://bitbucket.org/akorn/wheezy.template (repo gone + stated as lightweight) | | | - https://github.com/Hrabal/TemPy (says not maintained) | | | - https://github.com/breily/juno (2015) | | | - https://github.com/nyaruka/django-hamlpy (archived) | | | - https://pypi.org/project/python-jade/#history (2017 + 0 stars) | | | - https://github.com/multiversecoder/pug4py (2020) | | | - https://pypi.org/project/slim4py/#history (2019) | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ Running eval notes @@ -168,7 +207,7 @@ Running eval notes - As well as criteria - [x] General Python templates - [x] "python templating" @@ -180,24 +219,32 @@ Running eval notes - [x] Kajiki - [x] https://www.fullstackpython.com/template-engines.html - [x] Diazo - Not a templating engine, something about themes? https://docs.diazo.org/en/latest/ - [x] Juno - [x] pystache - [x] HAML variations - [x] "haml python" - [x] Jade variations - [x] "jade python" - [x] Pug variations - [x] "pug python" - [ ] Slim variations - [x] "slim python" (nothing) - [x] "slim python template" (something) Fwiw, in my experience the "this templating language ported to your language" almost never lasts as a supported library =/ (unless it's something intentionally universal like Mustache) -
twolfson revised this gist
Oct 16, 2023 . 1 changed file with 115 additions and 102 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -45,105 +45,118 @@ Criteria Comparison ---------- +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Name | Notes | +=====================+===============================================================================================================================================+ | Django | :raw-html:`<a href="https://docs.djangoproject.com/en/4.2/topics/templates/">URL</a>`, | | | (:raw-html:`<a href="https://github.com/django/django">GitHub</a>`), | | | Well established, only really available in Django, | | | but has large headache around not raising errors for missing variables =/ | | | (:raw-html:`<a href="https://docs.djangoproject.com/en/4.2/ref/templates/api/#how-invalid-variables-are-handled">Django Docs</a>`) | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Jinja2 | :raw-html:`<a href="https://jinja.palletsprojects.com/en/3.1.x/templates/">URL</a>` | | | (:raw-html:`<a href="https://github.com/pallets/jinja">GitHub</a>`), | | | Another well established Python library with plenty of good features (e.g. inheritance, Python Methods) | | | :raw-html:`<br/>` | | | Can do multi-line Python if needed it seems, though quite verbose ._. | | | (:raw-html:`<a href="https://stackoverflow.com/a/72249038/1960509">StackOverflow</a>`) | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Mako | :raw-html:`<a href="https://www.makotemplates.org/">URL</a>` | | | (:raw-html:`<a href="https://github.com/sqlalchemy/mako">GitHub</a>`), | | | Not nearly as many stars as others (286) but it's got recent development, | | | is owned by SQLAlchemy, and Reddit uses it (as per homepage) | | | so prob a safe bet | | | | | | | | | :raw-html:`<a href="https://docs.makotemplates.org/en/latest/syntax.html">Syntax</a>` | | | seems pretty straight forward (it's Python with a twist of ``endfor`` and such) | | | and some of the most expressive/sanest (though a little too unguarded) experiences I've had | | | have been in EJS and ERB | | | | | | | | | The `Python Block <https://docs.makotemplates.org/en/latest/syntax.html#python-blocks>`_ | | | syntax seems like such a killer feature ._. | | | | | | It also has includes, and even early returns O_O (getting some PHP vibes right there) | | | :raw-html:`<br/>` | | | And covers inheritance, https://docs.makotemplates.org/en/latest/inheritance.html | | | | | | So prob worth exploring further (and prob the front runner for me) | | | | | | There's a syntax highlighting package, https://packagecontrol.io/packages/Mako, though not touched in a while | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Chameleon | https://chameleon.readthedocs.io/en/latest/reference.html | | | | | | It's maintained but the syntax is to use ``<div tal:condition="comments">`` to include/exclude an element, | | | not straightforward expression and I'd be wary of footguns from it =/ | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Cheetah | https://cheetahtemplate.org/ | | | | | | It's maintained (https://github.com/CheetahTemplate3/cheetah3) and some good support, | | | though the website feels like it hasn't been touched in a while, | | | which makes me concerned around how feature rich it is =/ | | | | | | There's a syntax highlighting package, https://packagecontrol.io/packages/Cheetah%20Syntax%20Highlighting, | | | though not touched in a while | | | | | | Has good inheritance support, https://cheetahtemplate.org/users_guide/inheritanceEtc.html | | | though it's def its own DSL, not just Python =/ (which means more learning/ramping up -- but that's prob fine) | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Genshi | https://github.com/edgewall/genshi | | | | | | Gets some maintenacne (e.g. last year) and has some stars (78) | | | | | | https://genshi.edgewall.org/wiki/Documentation docs seems kind of confusing | | | | | | I'm going to just sidestep this one ._. | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Spitfire | https://github.com/youtube/spitfire | | | | | | Good traction (390 stars) and 2019 commit, | | | but docs not touched in a long while | | | (:raw-html:`<a href="https://github.com/youtube/spitfire/blob/1916e68d50ed30f395928585ef2f0d3ba1468ab0/doc/SpitfireVsCheetah.md">GitHub</a>`) | | | and the docs are much more absent than present =/ | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Kaijiki | https://github.com/jackrosenthal/kajiki | | | | | 43 stars + last commit in Nov 2022 -- but... | | | | | | Copying Genshi and Jinja so not getting much new content | | | and seems to lack many features, https://docs.kajiki.io/templating-basics.html#template-expressions-and-code-blocks | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Not enough traction | - https://github.com/tetframework/Tonnikala, Some life (2022 update) but only 14 stars | | | - https://github.com/cesbit/trender, 2022 update but only 20 stars | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Too lightweight | - https://docs.python.org/3.4/library/string.html#template-strings | | | - https://www.stringtemplate.org/ | | | - Mustache (no inheritance and such) | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ | Not maintained | - https://github.com/mll/ctemplate-python (last touched 2015) | | | - http://airspeed.pythonconsulting.com/ (site down) | | | - https://pypi.org/project/cubictemp/#history (last touched 2013) | | | - https://www.nthwave.net/elements/ (site down) | | | - http://www.alcyone.com/software/empy/ (version is from 2004) | | | - https://pypi.org/project/evoque/#history (last release 2009) | | | - https://blog.aerojockey.com/post/hrl (dropped for Mako in 2010) | | | - https://github.com/mahmoud/ashes#ashes (last touched 4 years ago) | | | - https://github.com/etianen/moody-templates (2013) | | | - https://pypi.org/project/Myghty/#history (2010) | | | - Qpy: https://www.mems-exchange.org/software/DurusWorks/ (2013) | | | - https://github.com/avelino/quik (2013) | | | - https://codingrecipes.com/pml-a-python-template-engine (timeout) | | | - https://www.simple-is-better.org/template/pyratemp.html (2013) | | | - https://wiki.python.org/moin/Spyce (2006) | | | - https://pypi.org/project/suit/#history (2010) | | | - https://pythonpaste.org/tempita (spam site) | | | - http://tt2.org/python/index.html (SVN?! doubt maintained) | | | - http://davidbau.com/archives/2011/09/09/python_templating_with_stringfunction.html (2011) | | | - Templite+: https://git.joonis.de/snippets/4 (snippet, not a project) | | | - https://www.kuwata-lab.com/tenjin/ (SSL error) | | | - http://texthon.chipsforbrain.org/ (2013) | | | - thrases: https://sourceforge.net/projects/the-next-please/ (2013) | | | - https://bitbucket.org/akorn/wheezy.template (repo gone + stated as lightweight) | | | - https://github.com/Hrabal/TemPy (says not maintained) | +---------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ Running eval notes ------------------ @@ -161,11 +174,11 @@ Running eval notes - [x] https://wiki.python.org/moin/Templating - [x] https://opensource.com/resources/python/template-libraries - [x] Tempy - [x] Kajiki - [ ] https://www.fullstackpython.com/template-engines.html -
twolfson revised this gist
Oct 16, 2023 . 1 changed file with 111 additions and 59 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,8 +19,12 @@ Criteria - Inheritance system(s) (ideally both include style as well as extension style) - Syntax highlighting well supported in IDEs - Nice to have: Has escape tools for JS and JSON - Nice to have: Linter and formatter support - Preferred: Raises an error when a variable is not defined - `Django templates don't do this <https://docs.djangoproject.com/en/4.2/ref/templates/api/#how-invalid-variables-are-handled>`_ @@ -41,53 +45,105 @@ Criteria Comparison ---------- +---------------------+--------------------------------------------------------------------------------------------------------------------------------+ | Name | Notes | +=====================+================================================================================================================================+ | Django | :raw-html:`<a href="https://docs.djangoproject.com/en/4.2/topics/templates/">URL</a>`, | | | (:raw-html:`<a href="https://github.com/django/django">GitHub</a>`), | | | Well established, only really available in Django, | | | but has large headache around not raising errors for missing variables =/ | | | (:raw-html:`<a href="https://docs.djangoproject.com/en/4.2/ref/templates/api/#how-invalid-variables-are-handled">Django Docs`) | +---------------------+--------------------------------------------------------------------------------------------------------------------------------+ | Jinja2 | :raw-html:`<a href="https://jinja.palletsprojects.com/en/3.1.x/templates/">URL</a>` | | | (:raw-html:`<a href="https://github.com/pallets/jinja">GitHub</a>`), | | | Another well established Python library with plenty of good features (e.g. inheritance, Python Methods) | | | :raw-html:`<br/>` | | | Can do multi-line Python if needed it seems, though quite verbose ._. | | | (:raw-html:`<a href="https://stackoverflow.com/a/72249038/1960509">StackOverflow`) | +---------------------+--------------------------------------------------------------------------------------------------------------------------------+ | Mako | :raw-html:`<a href="https://www.makotemplates.org/">URL</a>` | | | (:raw-html:`<a href="https://github.com/sqlalchemy/mako">GitHub</a>`), | | | Not nearly as many stars as others (286) but it's got recent development, | | | is owned by SQLAlchemy, and Reddit uses it (as per homepage) | | | so prob a safe bet | | | | | | | | | :raw-html:`<a href="https://docs.makotemplates.org/en/latest/syntax.html">Syntax</a>` | | | seems pretty straight forward (it's Python with a twist of ``endfor`` and such) | | | and some of the most expressive/sanest (though a little too unguarded) experiences I've had | | | have been in EJS and ERB | | | | | | | | | The `Python Block <https://docs.makotemplates.org/en/latest/syntax.html#python-blocks>`_ | | | syntax seems like such a killer feature ._. | | | | | | It also has includes, and even early returns O_O (getting some PHP vibes right there) | | | :raw-html:`<br/>` | | | And covers inheritance, https://docs.makotemplates.org/en/latest/inheritance.html | | | | | | So prob worth exploring further (and prob the front runner for me) | | | | | | There's a syntax highlighting package, https://packagecontrol.io/packages/Mako, though not touched in a while | +---------------------+--------------------------------------------------------------------------------------------------------------------------------+ | Chameleon | https://chameleon.readthedocs.io/en/latest/reference.html | | | | | | It's maintained but the syntax is to use ``<div tal:condition="comments">`` to include/exclude an element, | | | not straightforward expression and I'd be wary of footguns from it =/ | +---------------------+--------------------------------------------------------------------------------------------------------------------------------+ | Cheetah | https://cheetahtemplate.org/ | | | | | | It's maintained (https://github.com/CheetahTemplate3/cheetah3) and some good support, | | | though the website feels like it hasn't been touched in a while, | | | which makes me concerned around how feature rich it is =/ | | | | | | There's a syntax highlighting package, https://packagecontrol.io/packages/Cheetah%20Syntax%20Highlighting, | | | though not touched in a while | | | | | | Has good inheritance support, https://cheetahtemplate.org/users_guide/inheritanceEtc.html | | | though it's def its own DSL, not just Python =/ (which means more learning/ramping up -- but that's prob fine) | +---------------------+--------------------------------------------------------------------------------------------------------------------------------+ | Genshi | https://github.com/edgewall/genshi | | | | | | Gets some maintenacne (e.g. last year) and has some stars (78) | | | | | | https://genshi.edgewall.org/wiki/Documentation docs seems kind of confusing | | | | | | I'm going to just sidestep this one ._. | +---------------------+--------------------------------------------------------------------------------------------------------------------------------+ | Spitfire | TODO: https://github.com/youtube/spitfire | +---------------------+--------------------------------------------------------------------------------------------------------------------------------+ | Not enough traction | - https://github.com/tetframework/Tonnikala, Some life (2022 update) but only 14 stars | | | - https://github.com/cesbit/trender, 2022 update but only 20 stars | +---------------------+--------------------------------------------------------------------------------------------------------------------------------+ | Too lightweight | - https://docs.python.org/3.4/library/string.html#template-strings | | | - https://www.stringtemplate.org/ | | | - Mustache (no inheritance and such) | +---------------------+--------------------------------------------------------------------------------------------------------------------------------+ | Not maintained | - https://github.com/mll/ctemplate-python (last touched 2015) | | | - http://airspeed.pythonconsulting.com/ (site down) | | | - https://pypi.org/project/cubictemp/#history (last touched 2013) | | | - https://www.nthwave.net/elements/ (site down) | | | - http://www.alcyone.com/software/empy/ (version is from 2004) | | | - https://pypi.org/project/evoque/#history (last release 2009) | | | - https://blog.aerojockey.com/post/hrl (dropped for Mako in 2010) | | | - https://github.com/mahmoud/ashes#ashes (last touched 4 years ago) | | | - https://github.com/etianen/moody-templates (2013) | | | - https://pypi.org/project/Myghty/#history (2010) | | | - Qpy: https://www.mems-exchange.org/software/DurusWorks/ (2013) | | | - https://github.com/avelino/quik (2013) | | | - https://codingrecipes.com/pml-a-python-template-engine (timeout) | | | - https://www.simple-is-better.org/template/pyratemp.html (2013) | | | - https://wiki.python.org/moin/Spyce (2006) | | | - https://pypi.org/project/suit/#history (2010) | | | - https://pythonpaste.org/tempita (spam site) | | | - http://tt2.org/python/index.html (SVN?! doubt maintained) | | | - http://davidbau.com/archives/2011/09/09/python_templating_with_stringfunction.html (2011) | | | - Templite+: https://git.joonis.de/snippets/4 (snippet, not a project) | | | - https://www.kuwata-lab.com/tenjin/ (SSL error) | | | - http://texthon.chipsforbrain.org/ (2013) | | | - thrases: https://sourceforge.net/projects/the-next-please/ (2013) | | | - https://bitbucket.org/akorn/wheezy.template (repo gone + stated as lightweight) | +---------------------+--------------------------------------------------------------------------------------------------------------------------------+ Running eval notes ------------------ @@ -101,32 +157,22 @@ Running eval notes - [ ] General Python templates - [x] "python templating" - [x] https://wiki.python.org/moin/Templating - [ ] https://opensource.com/resources/python/template-libraries - [ ] Tempy - [ ] Kajiki - [ ] https://www.fullstackpython.com/template-engines.html - [ ] Diazo - [ ] Juno - [ ] pyratemp - [ ] pystache @@ -139,6 +185,12 @@ Running eval notes - [ ] Slim variations Fwiw, in my experience the "this templating language ported to your language" almost never lasts as a supported library =/ (unless it's something intentionally universal like Mustache) So usually a pretty bad idea to build on top of ._. Why is this document in reStructuredText? ----------------------------------------- RST is required for multiline behavior in tables. Markdown doesn't support this =( -
twolfson revised this gist
Oct 16, 2023 . 1 changed file with 98 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,6 @@ gist-python-templating-evaluation ================================= .. Workaround for occasional headaches from RST (e.g. inline links needing unique names) .. role:: raw-html(raw) @@ -14,9 +12,8 @@ An evaluation and comparison of various Python templating libraries Last updated: October 2023 Criteria -------- - Escapes variables for HTML, with escape hatch for no escaping @@ -27,7 +24,7 @@ Criteria: - Preferred: Raises an error when a variable is not defined - `Django templates don't do this <https://docs.djangoproject.com/en/4.2/ref/templates/api/#how-invalid-variables-are-handled>`_ (:raw-html:`<a href="https://stackoverflow.com/a/40506337/1960509">StackOverflow</a>`) - Preferred: Escape hatch to Python, since sometimes we to map variables, and bespoke DSLs are frustrating/limited @@ -41,6 +38,57 @@ Criteria: .. _`HAML`: https://haml.info/ .. _`Slim`: https://slim-template.github.io/ Comparison ---------- +-----------------+--------------------------------------------------------------------------------------------------------------------------------+ | Name | Notes | +=================+================================================================================================================================+ | Django | :raw-html:`<a href="https://docs.djangoproject.com/en/4.2/topics/templates/">URL</a>`, | | | (:raw-html:`<a href="https://github.com/django/django">GitHub</a>`), | | | Well established, only really available in Django, | | | but has large headache around not raising errors for missing variables =/ | | | (:raw-html:`<a href="https://docs.djangoproject.com/en/4.2/ref/templates/api/#how-invalid-variables-are-handled">Django Docs`) | +-----------------+--------------------------------------------------------------------------------------------------------------------------------+ | Jinja2 | :raw-html:`<a href="https://jinja.palletsprojects.com/en/3.1.x/templates/">URL</a>` | | | (:raw-html:`<a href="https://github.com/pallets/jinja">GitHub</a>`), | | | Another well established Python library with plenty of good features (e.g. inheritance, Python Methods) | | | :raw-html:`<br/>` | | | Can do multi-line Python if needed it seems, though quite verbose ._. | | | (:raw-html:`<a href="https://stackoverflow.com/a/72249038/1960509">StackOverflow`) | +-----------------+--------------------------------------------------------------------------------------------------------------------------------+ | Mako | :raw-html:`<a href="https://www.makotemplates.org/">URL</a>` | | | (:raw-html:`<a href="https://github.com/sqlalchemy/mako">GitHub</a>`), | | | Not nearly as many stars as others (286) but it's got recent development, | | | is owned by SQLAlchemy, and Reddit uses it (as per homepage) | | | so prob a safe bet | | | | | | | | | :raw-html:`<a href="https://docs.makotemplates.org/en/latest/syntax.html">Syntax</a>` | | | seems pretty straight forward (it's Python with a twist of ``endfor`` and such) | | | and some of the most expressive/sanest (though a little too unguarded) experiences I've had | | | have been in EJS and ERB | | | | | | | | | The `Python Block <https://docs.makotemplates.org/en/latest/syntax.html#python-blocks>`_ | | | syntax seems like such a killer feature ._. | | | | | | It also has includes, and even early returns O_O (getting some PHP vibes right there) | | | :raw-html:`<br/>` | | | And covers inheritance, https://docs.makotemplates.org/en/latest/inheritance.html | | | | | | So prob worth exploring further (and prob the front runner for me) | +-----------------+--------------------------------------------------------------------------------------------------------------------------------+ | Too lightweight | - https://docs.python.org/3.4/library/string.html#template-strings | | | | | | - https://www.stringtemplate.org/ | | | | | | - Mustache (no inheritance and such) | +-----------------+--------------------------------------------------------------------------------------------------------------------------------+ | Not maintained | - https://github.com/mll/ctemplate-python | | | | +-----------------+--------------------------------------------------------------------------------------------------------------------------------+ Running eval notes ------------------ @@ -50,3 +98,47 @@ Running eval notes - Starting with known templates - As well as criteria - [ ] General Python templates - [ ] "python templating" - [ ] https://wiki.python.org/moin/Templating - [ ] https://opensource.com/resources/python/template-libraries - [ ] Genshi - [ ] Tempy - [ ] Kajiki - [ ] https://www.fullstackpython.com/template-engines.html - [ ] Chameleon - [ ] Cheetah - [ ] Diazo - [ ] evoque - [ ] Juno - [ ] Myghty - [ ] pyratemp - [ ] pystache - [ ] HAML variations - [ ] Jade variations - [ ] Pug variations - [ ] Slim variations Why is this document in reStructuredText? ----------------------------------------- RST is required for multiline behavior in tables. Markdown doesn't support this =( -
twolfson revised this gist
Oct 16, 2023 . 1 changed file with 44 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,50 @@ gist-python-templating-evaluation .. RST required for multiline behavior in tables .. Workaround for occasional headaches from RST (e.g. inline links needing unique names) .. role:: raw-html(raw) :format: html An evaluation and comparison of various Python templating libraries Last updated: October 2023 Evaluation table ---------------- Criteria: - Escapes variables for HTML, with escape hatch for no escaping - Inheritance system(s) (ideally both include style as well as extension style) - Nice to have: Has escape tools for JS and JSON - Preferred: Raises an error when a variable is not defined - `Django templates don't do this <https://docs.djangoproject.com/en/4.2/ref/templates/api/#how-invalid-variables-are-handled>`_ (:raw-html:`<a href="https://stackoverflow.com/a/40506337/1960509>StackOverflow</a>`( - Preferred: Escape hatch to Python, since sometimes we to map variables, and bespoke DSLs are frustrating/limited - Bonus: Can express multiple tags in 1 line (a la Jade/Pug) - ``strong > a`` - Bonus: Can express ids and classes easily (a la Jade/Pug, HAML, Slim) .. _`Jade/Pug`: https://pugjs.org/api/getting-started.html .. _`HAML`: https://haml.info/ .. _`Slim`: https://slim-template.github.io/ Running eval notes ------------------ 2023-10-16 ^^^^^^^^^^ - Starting with known templates - As well as criteria -
twolfson revised this gist
Oct 16, 2023 . No changes.There are no files selected for viewing
-
twolfson revised this gist
Oct 16, 2023 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ gist-python-templating-evaluation ================================= .. RST required for multiline behavior in tables An evaluation and comparison of various Python templating libraries Last updated: October 2023 -
twolfson created this gist
Oct 16, 2023 .There are no files selected for viewing