Write safer and cleaner HTML using Python
Project description
htmldoom
Write safer and cleaner HTML using Python
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>
Q/A
What is the goal here?
The primary goal is to make writing HTML cleaner, easier, safer and intuitive using Python.
What about performance?
Although performance is not the primary goal here, it should not be a roadblock. htmldoom is copying the syntax and properties of elm, an existing fast and purely functional programming language that specializes in rendering HTML in virtual doms. Elm does all the optimisation internally which I'm sure can be implemented in Python to a great extent.
All the elements and attributes in htmldoom is supposed to be immutable (unless you want to hack it for some reason). Being immutable enables them to be cachable and sharable making use of the flyweight pattern, thus improving the speed of rendering.
Furthermore, if we follow the the DOM size recommendations, i.e.
- less than 1500 nodes total.
- maximum depth of 32 nodes.
- no parent node with more than 60 child nodes.
Plugins and ecosystem
- moodlmth: Convert raw HTML pages into python source code
- pyramid_htmldoom: htmldoom rendering library plugin for Pyramid
Benchmarks
Very basic benchmark done using this script and IPython
htmldoom
Jinja2
Mako
Chameleon
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file htmldoom-0.2.2.tar.gz
.
File metadata
- Download URL: htmldoom-0.2.2.tar.gz
- Upload date:
- Size: 11.3 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5dbb8693ede17eaf2a27f79b15cca980ebe50896ff709168dd58bd329cf5745 |
|
MD5 | 5a24874463cb35c76bee12926edccee0 |
|
BLAKE2b-256 | f29e6ea61222ad2c7fbfd1d3395799e731db9f75673df40f06a6742112759168 |
File details
Details for the file htmldoom-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: htmldoom-0.2.2-py3-none-any.whl
- Upload date:
- Size: 10.7 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7f8843c80e094f734a6d4cfc56177b0ed17d4af37a3f91917a1f3a1ff587f57 |
|
MD5 | a2c457b6a959af665975bafe27ca244f |
|
BLAKE2b-256 | 24d472ddad7ac11c8dabc8a241aec7023087d3b96b9f2e6bfe2ae08e48303865 |