Skip to main content

Write safer and cleaner HTML using Python

Project description

htmldoom

Write safer and cleaner HTML using Python

PyPI version PyPI version Build Status codecov Code style: black

Usage

>>> from htmldoom import elements as e
>>> 
>>> e.P(style=e.style(color="red"))("This is a paragraph")
<p style="color:'red';">This is a paragraph</p>

>>> from htmldoom import elements as e
>>> from htmldoom.layouts import BaseLayout
>>> 
>>> class MyLayout(BaseLayout):
...     @property
...     def title(self) -> e.Title:
...         return e.Title()(self["title"])
...     @property
...     def body(self) -> e.Body:
...         return e.Body()(f"Welcome {self['user']['name']}")

... >>> MyLayout({"title": "foo", "user": {"name": "bar"}}) <!DOCTYPE html> <html><head><title>foo</title></head><body>Welcome bar</body></html>

Find more examples here

Benchmarks

Very basic benchmark done using this script and IPython

htmldoom

htmldoom stats

Jinja2

Jinja2 stats

Mako

Mako stats

Chameleon

Chameleon stats

Conclusion

htmldoom performs best upto a certain number of loops which is generally high enough.
NOTE: These measurements are very naive and shows very basic information.

Contributing

Check out the contributing guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

htmldoom-0.2.tar.gz (8.7 kB view hashes)

Uploaded Source

Built Distribution

htmldoom-0.2-py3-none-any.whl (8.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page