Skip to main content

Write safer and cleaner HTML using Python

Project description

htmldoom

Write safer and cleaner HTML using Python

PyPI version Build Status codecov Code style: black

Usage

>>> from htmldoom import elements as e
>>> 
>>> e.P(style=e.css(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.data["title"])
...     @property
...     def body(self) -> e.Body:
...         return e.Body(f"Welcome {self.data['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 recursions which is generally high enough. These measurements are very naive and shows very basic information. Some templating engines might have performance optimizations (such caching) enabled by default. However, In case of htmldoom, it's upto to developer (for now) to optimize it.

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.0.8.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

htmldoom-0.0.8-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file htmldoom-0.0.8.tar.gz.

File metadata

  • Download URL: htmldoom-0.0.8.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5

File hashes

Hashes for htmldoom-0.0.8.tar.gz
Algorithm Hash digest
SHA256 861ac352c4477648a92e39f7229c7c2eee0d9a37bf0b428705f16bb006b5cc99
MD5 9a3dfd90f98d1270a78f2303416e73b4
BLAKE2b-256 06157fca37cf9fa224466bc854679f96447e151fcca51c78ff20630ab0a89396

See more details on using hashes here.

File details

Details for the file htmldoom-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: htmldoom-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5

File hashes

Hashes for htmldoom-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 56748933728d0cd93a74a7784f8398b7621b480287b29772e630fbaefcc92118
MD5 5f76c2adce0bca320a2584ddc24b4a19
BLAKE2b-256 49973d04a607a02ca0c608edc518fba170b3582e459a5b533a1d42202b8bfd24

See more details on using hashes here.

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