Skip to content

Quickstart

Installation

Package is on pypi. Use uv, poetry or pip to install

uv add hypermedia
poetry add hypermedia
pip install hypermedia

The Basics

All html tags can be imported directly like:

from hypermedia import Html, Body, Div, A

Tags are nested by adding children in the constructor:

from hypermedia import Html, Body, Div

Html(Body(Div(), Div()))

Add text to your tag:

from hypermedia import Div

Div("Hello world!")

use .dump() to dump your Elements to html.

from hypermedia import Bold, Div

Div("Hello ", Bold("world!")).dump()

outputs

<div>Hello <b>world!</b></div>

Composability with slots

from hypermedia import Html, Body, Div, Menu, Header, Div, Ul, Li

base = Html(
    Body(
        Menu(slot="menu"),
        Header("my header", slot="header"),
        Div(slot="content"),
    ),
)

menu = Ul(Li(text="main"))
content = Div(text="Some content")

base.extend("menu", menu)
base.extend("content", content)

base.dump()

output

<html>
    <body>
        <menu>
            <ul><li>main</li></ul>
        </menu>
        <header>my header</header>
        <div>
            <div>Some content</div>
        </div>
    </body>
</html>'