An opinionated way to work with html in pure python with htmx support.
Project description
Hypermedia
hypermedia is a pure python library for working with html. hypermedias killer feature is that it is html code is composable through slot
concept. Because of that, it works great with HTMX partials and full page reloads.
Hypermedia is made to work with FastAPI and HTMX. but can be used by any web server.
Here are some 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 Html, Body, Div
Html(text="Hello world!")
use .dump()
to dump your code to html.
from hypermedia import Html, Body, Div
Html(text="Hello world!").dump()
# outputs
# '<html>hello world</html>'
Composability with slots
from hypermedia import Html, Body, Div, Menu, Header, Div, Ul, Li
base = Html(
Body(
Menu(slot="menu"),
Header(slot="header", text="my header"),
Div(slot="content"),
),
)
menu = Ul(Li(text="main"))
content = Div(text="Some content")
base.extend("menu", menu)
base.extend("content", content)
base.dump()
# outputs
# '<html><body><menu><ul><li>main</li></ul></menu><header>my header</header><div><div>Some content</div></div></body></html>'
With FastAPI:
coming
Using dependency injection.
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
hypermedia-2.0.0.tar.gz
(11.6 kB
view hashes)
Built Distribution
hypermedia-2.0.0-py3-none-any.whl
(13.8 kB
view hashes)
Close
Hashes for hypermedia-2.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0dfc542374fd1d74f30ae690b49a458542e8aaf39e34b9bdd5fd88cf420ad0b7 |
|
MD5 | ffda7cb7fe6b5fe02af9dba34a4a8ddf |
|
BLAKE2b-256 | 4136edc4b55771c4b2f0fdfdbae55385e42d13de374d64a137f4870bdc37fbbe |