An evaluation and comparison of various Python templating libraries
Last updated: October 2023
- Escapes variables for HTML, with escape hatch for no escaping
- 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
- 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)
- Starting with known templates
- As well as criteria
- [ ] General Python templates
- [x] "python templating"
- [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
- [ ] Diazo
- [ ] Juno
- [ ] pyratemp
- [ ] pystache
- [ ] HAML variations
- [ ] Jade variations
- [ ] Pug variations
- [ ] 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 ._.
RST is required for multiline behavior in tables. Markdown doesn't support this =(
I suggest reconsidering EmPy. After 4 years it was now updated and released a new version 4.0, which makes it maintained.