Hacker News new | ask | show | jobs
Show HN: Embedded Python for HTML Templates (github.com)
2 points by slaybear 601 days ago
empyt is a new python library for embedding python directly into HTML templates.

I contribute on a few different python web projects, and grew tired of remembering the varying syntax - just let me write python!

This is not a full templating language like Jinja, and does not support things like template inheritance, etc. Rather, empyt can be used as an 'extension' alongside other templating engines.

Fully functional, but considered a very early v1. Biggest thing ATM is that security needs to be thought through a lot more.

2 comments

>This is not a full templating language like Jinja, and does not support things like template inheritance, etc. Rather, empyt can be used as an 'extension' alongside other templating engines.

It would probably be helpful to show examples of what it does support, and how that complements an existing templating engine like Jinja. In the README it looks like empyt wraps an existing templating engine, but it isn't clear what that wrapping accomplishes.

This is some great feedback {and actually filed as the first issue :) } https://github.com/crypto-rizzo/empyt/issues/1

Documentation + examples are definitely lacking ATM. Will be rectified in short order. To answer your question now, the goal is pretty simple: enable python to be directly used in HTML templates.

For usage with another template engine, I see it as more of a convenience / speed factor. Quickly write frontend logic in python without reaching for a new (albeit similar) syntax.

empyt can also be used standalone, in situations where people want to avoid a templating engine altogether, and just want to use python on the frontend.

with templating engine: https://github.com/crypto-rizzo/empyt/blob/master/examples/t...

without templating engine: https://github.com/crypto-rizzo/empyt/blob/master/examples/t...

I've gone the other way and use Dominate to generate most of my html content dynamically and then use some barebones templates. Jinja was just giving me headaches all the time.

But this is interesting and I could see using it, maybe passing in more complicated functions through the interface if needed.

Interesting approach! Hadn't heard of Dominate before now, but reminds me of FastHTML which was making waves the other month. I gave that a whirl, but quickly realized I really like the simplicity of writing HTML without working around a DOM API.

Anyway thanks for the kind words, and let me know of any feedback you have if you do take empyt for a joy ride. Planning to have a public roadmap before EOY