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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: htmldoom-0.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.tar.gz
Algorithm Hash digest
SHA256 51ed23a38db74fbb604625c353328094e7ef87a6146f85fa76763213a6721a69
MD5 46d0c307add9bf26a41deb7c23dc441b
BLAKE2b-256 332b6dc6b2721958076cdf9131f39c9fd6f6397d054e473f9151d2c0138f24bc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: htmldoom-0.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-py3-none-any.whl
Algorithm Hash digest
SHA256 1bdc0636bcdce89e37f42ddd8781f9bb901636ed6948a4e997392ddd01519522
MD5 3cc0d28d975d503abc28f417e09da558
BLAKE2b-256 340f0204437e0a904b42b0cbed1418c9aed005f32f36587145a7c740f4e3c5ae

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