Skip to main content

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

Autocomplete demo

Metadata

Release files for domtree 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for domtree 0.0.5
File Size Uploaded
domtree-0.0.5.tar.gz 240.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for domtree 0.0.5
File Interpreter ABI Platform
domtree-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 262.4 kB

Release files / domtree-0.0.5.tar.gz

Download URL domtree-0.0.5.tar.gz
Size 240.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b33fe5a800d8a261594584b59aead58f984ea0b1f9b61eeed787a78bb01952c1
BLAKE2b-256 checksum
How to use checksums
edff8b5bcf64793ad3a8f1bd6fa7a8199f5c374db72a48e7a68fdc4101274366
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release files / domtree-0.0.5-py3-none-any.whl

Download URL domtree-0.0.5-py3-none-any.whl
Size 21.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3eeb82846eb42cdc21ce0fa3a84195fec8cadd91ebff4a47885982676a2d10de
BLAKE2b-256 checksum
How to use checksums
afaf75449470c04bfb7d39e3287ed90f0e52633fac9070cc9c00c9290a53aa92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page