sodom if you like to write HTML in Python.
Project description
sodom
sodom if you like to write HTML in Python. Faster x2~ than dominate
Installation
python -m pip install sodom[cli]
Examples
You can check demo via python -m sodom or preview code in sodom.__main__.
from sodom import *
...
def card(_header: str, _price: str, _submit_text: str, *_conditions: str):
with div(class_='card mb-4 box-shadow'):
with div(class_='card-header'), h4(class_='my-0 font-weight-normal'):
text(_header)
with div(class_='card-body'):
with h1(class_='card-title pricing-card-title'):
text(_price)
with small(class_='text-muted'):
text(' mo')
with ul(class_='list-unstyled mt-3 mb-4'):
for _c in _conditions:
li(_c)
with button(type_='button', class_='btn btn-lg btn-block btn-primary'):
text(_submit_text)
...
Also added special operations:
Attrs(foo='bar').merge(foo='baz')
Attrs(foo='bar').merge(**Attrs(foo='baz'))
Attrs(foo='bar').merge(**dict(foo='baz'))
Attrs(foo='bar') | Attrs(foo='baz')
Attrs(foo='bar') | {'foo': 'baz'}
# return `Attrs(foo='bar baz'})`
with div() < Attrs(foo='bar') as doc: ...
with div() < {'foo': 'bar'} as doc: ...
# return `<div foo="bar"></div>`
with div() < Attrs(foo='bar') | {'foo': 'baz'} as doc: ...
# return `<div foo="bar baz"></div>`
CLI Generation
Require [cli] extra.
python -m pip install sodom[cli]
Check out --help.
python -m sodom --help
Features
- supported standart html element (normal/void). Check
sodom.literals.NORMAL_TAGSandsodom.literals.VOID_TAGS. - by default, all underscores(
_) will be replaced by minus(-). Usereplace_underscoresin renderers to replace only special attributes likedata-,v-... Checksodom.literals.SPECIAL_ATTRS. You can extend list in runtime before library usage. - sodom is x2~ times faster than
dominateand x4+ times thanfast_html. Checksodom.tests.test_performance_*. - avoided builtin keyword trouble via cutting off leading and ending
_of element names. For example,[py]class_='button'equals[html]class="button". Checkpython -m sodom demoorsodom.__main__.demo - supported
ContextVar. Tested onasyncioandThreadPoolExecutor. - supported python generation from
.html. - include simple integrations with
aiohttp,flask,sanic,quart. Checksodom.ext.
Feedback
If you have any feedback, text me at inbox@protaz.ru
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
sodom-1.4.0.tar.gz
(18.7 kB
view details)
File details
Details for the file sodom-1.4.0.tar.gz.
File metadata
- Download URL: sodom-1.4.0.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3eb0e771c3665d5f002351e0e6cc423233721c3ee5215b35ecd66f6e1e030f5
|
|
| MD5 |
16f222f019eb470c7850006de1f6812a
|
|
| BLAKE2b-256 |
69dada2de79e05a1be6276ca60d5d07b1001a0d8544eb6fb89a0a602a8d35fcb
|