DOM Tree syntax for python
Project description
DOM Tree
Simple API to create DOM trees in Python. A bit like JSX, but with native Python syntax.
Aims to include useful autocompletion. Currently this works for SVGs.
Basic example
from domtree.svg import *
print(
svg(viewBox="0 0 100 100", xmlns="http://www.w3.org/2000/svg")(
circle(cx=50, cy=50, r=50),
)
)
# <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
# <circle cx="50" cy="50" r="50" />
# </svg>
Generated content
from domtree.svg import *
print(
svg(
circle(x=0, y=i * 10, r=2) for i in range(5)
)
)
# <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
# <circle x="0" y="0" r="2" />
# <circle x="0" y="10" r="2" />
# <circle x="0" y="20" r="2" />
# <circle x="0" y="30" r="2" />
# <circle x="0" y="40" r="2" />
# </svg>
Custom nodes
from domtree import Node
ul = Node("ul")
li = Node("li")
print(
ul(
li("First item"),
li(className="second")("Second item")
)
)
# <ul>
# <li>
# First item
# </li>
# <li class="second">
# Second item
# </li>
# </ul>
Autocomplete
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
domtree-0.0.5.tar.gz
(240.9 kB
view details)
Built Distribution
domtree-0.0.5-py3-none-any.whl
(21.5 kB
view details)
File details
Details for the file domtree-0.0.5.tar.gz
.
File metadata
- Download URL: domtree-0.0.5.tar.gz
- Upload date:
- Size: 240.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b33fe5a800d8a261594584b59aead58f984ea0b1f9b61eeed787a78bb01952c1 |
|
MD5 | ecea70ed6be3fe547743e5704a6b2069 |
|
BLAKE2b-256 | edff8b5bcf64793ad3a8f1bd6fa7a8199f5c374db72a48e7a68fdc4101274366 |
File details
Details for the file domtree-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: domtree-0.0.5-py3-none-any.whl
- Upload date:
- Size: 21.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eeb82846eb42cdc21ce0fa3a84195fec8cadd91ebff4a47885982676a2d10de |
|
MD5 | 7396e662a4a8033b9799996b1cf2f5b8 |
|
BLAKE2b-256 | afaf75449470c04bfb7d39e3287ed90f0e52633fac9070cc9c00c9290a53aa92 |