Skip to main content

Write safer and cleaner HTML using Python

Project description

htmldoom

Write safer and cleaner HTML using Python

PyPI version PyPI pyversions 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.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 loops which is generally high enough. These measurements are very naive and shows very basic information. Some templating engines might have performance optimizations (such as caching) enabled by default. However, In case of htmldoom, it's upto to the 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.1.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: htmldoom-0.1.1.tar.gz
  • Upload date:
  • Size: 6.1 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.1.1.tar.gz
Algorithm Hash digest
SHA256 5140b49493437020e2e71c937228df6419d6d95822c44889305d948c4ddfb87d
MD5 cafcedd6e14d8d479dd8aaf36d56e825
BLAKE2b-256 0d5c1b680ee5cdcfaab0374b38119ff84f8f467f74e1ae7e7055d1894815cce1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: htmldoom-0.1.1-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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1cc2a9f2d07207186b4bf4ccdba6aa948258eac83aad3b86df7727ae2a6f0274
MD5 3126ba1e1b99f9a9c438528a714d6e36
BLAKE2b-256 f298a5bc0c9506a6f8ae9bb7b647c4f3dcc6f12896a4299693b9d35512cdbc39

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