Skip to main content

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. Hypermedia's killer feature is that it is composable through a slot concept. Because of that, it works great with </> htmx where you need to respond with both partials and full page html.

Hypermedia is made to work with FastAPI and </> htmx, but can be used by anything to create HTML.


Python Version from PEP 621 TOML


Documentation Stable | Source Code | Task Tracker

Features

  • Build HTML with python classes
  • Composable templates through a slot system
  • Seamless integration with </> htmx
  • Fully typed and Autocompletion for html/htmx attributes and styles
  • Opinionated simple decorator for FastAPI
  • Unlike other template engines like Jinja2 we have full typing since we never leave python land.

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 code to html.

from hypermedia import Bold, Div

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

output

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

Composability with slots

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

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

menu = Ul(Li("home"))
content = Div("Some content")

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

base.dump()

output

<html>
    <body>
        <menu>
            <ul><li>home</li></ul>
        </menu>
        <div>
            <div>Some content</div>
        </div>
    </body>
</html>

Documentation

Head over to our documentation

If you are using this for HTMX, then please read the HTMX section of the documentation

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

hypermedia-6.0.0.tar.gz (133.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hypermedia-6.0.0-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

Details for the file hypermedia-6.0.0.tar.gz.

File metadata

  • Download URL: hypermedia-6.0.0.tar.gz
  • Upload date:
  • Size: 133.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.8

File hashes

Hashes for hypermedia-6.0.0.tar.gz
Algorithm Hash digest
SHA256 2301cfa33f2c952da80ed4d61c85b84a959fa16c0e1f959c0765f83515b7f473
MD5 0e1256bbe4a58008f0c538a0ebad1cc5
BLAKE2b-256 3c390a531e4bca5897900376987f7b04671b05a08665d2ba39d2cb65a05e6785

See more details on using hashes here.

File details

Details for the file hypermedia-6.0.0-py3-none-any.whl.

File metadata

  • Download URL: hypermedia-6.0.0-py3-none-any.whl
  • Upload date:
  • Size: 28.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.8

File hashes

Hashes for hypermedia-6.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 67038cd8072f3e0471a170ecaed96c176026333576a1aea92a938d6a80b1e132
MD5 77def1b9d190e26ab95a0486b9b7512e
BLAKE2b-256 5d3ade72c6165be7a29b2f9fe54798d1fe770b94346009dbee6c7c7550a0669f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page