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.1.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.1-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for hypermedia-6.0.1.tar.gz
Algorithm Hash digest
SHA256 354619c12d85f346eda34f436ad8150e52a6e29fe75fb75495d1b6aa829c300c
MD5 a245cdf58668b8ed4ac81c3a5571dc4b
BLAKE2b-256 31b1f8d7999e53544b701698000e7d36fc1a1bcfad56c7819e28fe782b7fd05b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hypermedia-6.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2bfb47a26b094338e8f5662a1f2db7335b1aefad21c5a4d02bdd085c96bf45e4
MD5 c6bb91a7411d4af4643920af593c2012
BLAKE2b-256 c13de174d740334511bbf099a6b1d9a76a8e7a97c1d4607fc9b09a90d6c69ec7

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