Skip to main content

Библиотека для декларативного формирования HTML-структуры на Python.

Текущая версия использует асинхронный рендер. Основной публичный API для получения HTML теперь await render().

Актуальная версия проекта: 0.2.1.

Установка

pip install domica-html

Установка конкретной версии напрямую из GitHub:

pip install git+https://github.com/opolonix/domica-html.git@v0.2.1

Для локальной разработки:

pip install -e .[dev]

Пример

import asyncio

from domica_html import html, div

async def main():
    doc = html()

    with doc:
        div("hello world")

    print(await doc.render())

asyncio.run(main())

output:

<html>
    <div>
        hello world
    </div>
</html>

Реализация собственного компонента

import asyncio

from domica_html import html, div, inc, node_container, script, line
from contextvars import ContextVar
from collections import defaultdict
from typing import Type

external_tags: ContextVar[dict[Type, list["external_container"]]] = ContextVar("external_tags", default=defaultdict(list))

class external_container(node_container):
    def __init__(self, *, anchor=False):
        super().__init__(anchor=anchor)
        if not anchor:
            tags = external_tags.get()
            tags[self.__class__].append(self)

    async def render(self):
        tags = external_tags.get()

        for child in tags[self.__class__]:
            if child is self: continue
            self.add_child(child)

        return await super().render()

class global_script(external_container): ...

async def main():
    doc = html()

    with doc:
        with div():
            div("Hello world with some script", onclick="hello_on_click")
            with global_script():
                line("const hello_on_click = () => {")
                line(inc.char, "alert('hello!');")
                line("}")

        with script():
            global_script(anchor=True)

    print(await doc.render())

asyncio.run(main())

output:

<html>
    <div>
        <div onclick="hello_on_click">  
            Hello world with some script
        </div>
    </div>
    <script>
        const hello_on_click = () => {  
            alert('hello!');
        }
    </script>
</html>

Релизы

  • 0.2.1: текущий релиз асинхронного рендера через await render()
  • 0.2.0: первый релиз с асинхронным рендером через await render()
  • 0.1.5: финальная стабильная синхронная версия ветки 0.1.x

Release files for domica-html 0.2.1

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

Source distribution (sdist)

Source distribution for domica-html 0.2.1
File Size Uploaded
domica_html-0.2.1.tar.gz 10.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for domica-html 0.2.1
File Interpreter ABI Platform
domica_html-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 20.5 kB

Release files / domica_html-0.2.1.tar.gz

Download URL domica_html-0.2.1.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5b7065f7d7fed1e6dc0b51c905ebf305194913bbfc813102e7e0e6b67ef193b8
BLAKE2b-256 checksum
How to use checksums
77bb3e1992d0a787b4e5ccb83b587c68f1d7fcf35073b0e42e883f607371a500
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 23, 2026.

Transparency log

Release files / domica_html-0.2.1-py3-none-any.whl

Download URL domica_html-0.2.1-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
58676250a3a72ddd600ef3a849594ae002e913287839477508d48fd11700f6f9
BLAKE2b-256 checksum
How to use checksums
e1dc7cf4c197e9635ed5729f798ce12d3bcd610408883e16c0c1217ea0dac086
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 23, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.4

2 release files

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