Skip to main content

Hyper

CI PyPI License: MIT

Write type-safe HTML in .hyper files. Import components directly from Python.

uv add hyperhtml

Requires Python 3.10 or newer.

Create a component

Create app/pages/Greeting.hyper:

<h1>Hello, World!</h1>

Import and call it:

from app.pages import Greeting

print(Greeting())
<h1>Hello, World!</h1>

The filename sets the component name.

Pass data

Add typed props above ---:

name: str
---
<h1>Hello, {name}!</h1>
print(Greeting(name="Ada"))
<h1>Hello, Ada!</h1>

Props are keyword-only. Values are escaped by default.

Calling a component binds its props. Rendering starts when it becomes a string or when you call .render():

greeting = Greeting(name="Ada")
html = greeting.render()

Use Python

Use Python expressions and control flow directly:

names: list[str]
---
for name in names:
    <h1>Hello, {name}!</h1>
print(Greeting(names=["Ada", "Lin"]))
<h1>Hello, Ada!</h1><h1>Hello, Lin!</h1>

Indentation defines Python blocks. Add an aligned end only when it makes a boundary clearer.

Compose components

Create app/components/Card.hyper:

title: str
---
<article><h2>{title}</h2></article>

Use it from app/pages/Dashboard.hyper:

from app.components import Card
---
<{Card} title="Orders" />
from app.pages import Dashboard

print(Dashboard())
<article><h2>Orders</h2></article>

Pass content

Place {...} where caller content belongs:

title: str
---
<article>
    <h2>{title}</h2>
    <div>{...}</div>
</article>

Pass content between component tags:

from app.components import Card
---
<{Card} title="Orders">
    <p>3 open orders</p>
</{Card}>
<article><h2>Orders</h2><div><p>3 open orders</p></div></article>

Pass named content

Use a named slot when content belongs in a specific place:

title: str
---
<article>
    <h2>{title}</h2>
    <div>{...}</div>
    <footer>{...actions}</footer>
</article>

Mark the element that fills it:

from app.components import Card
---
<{Card} title="Orders">
    <p>3 open orders</p>
    <button {...actions}>View orders</button>
</{Card}>
<article><h2>Orders</h2><div><p>3 open orders</p></div><footer><button>View orders</button></footer></article>

Define several components

Use def ... -> Component to group related components in one file:

# app/components/forms.hyper
def Button(*, label: str) -> Component:
    <button>{label}</button>

def Input(*, name: str) -> Component:
    <input name={name} />

A declarations-only file imports like a Python module:

from app.components.forms import Button, Input

print(Button(label="Save"))
<button>Save</button>

.hyper files receive required runtime and typing imports automatically. In Python files, import the runtime from hyper:

from hyper import Component

Use FastAPI

Set the response type to HTML, then render a component:

from fastapi import FastAPI
from fastapi.responses import HTMLResponse

from app.pages import Dashboard

app = FastAPI(default_response_class=HTMLResponse)


@app.get("/dashboard")
def dashboard():
    return Dashboard().render()

Stream a response

Pass stream=True to send each generated chunk:

from fastapi.responses import StreamingResponse


@app.get("/dashboard/stream")
def stream_dashboard():
    return StreamingResponse(
        Dashboard().render(stream=True),
        media_type="text/html",
    )

See Integrations for Django, Jinja, Flask, Litestar, and Sanic.

IDE support

  • JetBrains: syntax highlighting, Python language injection, and compiler diagnostics
  • TextMate and VS Code: syntax highlighting

Documentation

License

MIT

Metadata

Release files for hyperhtml 0.2.0

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

Source distribution (sdist)

Source distribution for hyperhtml 0.2.0
File Size Uploaded
hyperhtml-0.2.0.tar.gz 154.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for hyperhtml 0.2.0
File
hyperhtml-0.2.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
hyperhtml-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details
hyperhtml-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details
hyperhtml-0.2.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
hyperhtml-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 2.8 MB

Release files / hyperhtml-0.2.0.tar.gz

Download URL hyperhtml-0.2.0.tar.gz
Size 154.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d2ca5ed879e61ee6e3fb8caf030c96810f64073f89aebd0c016b6c3de445706a
BLAKE2b-256 checksum
How to use checksums
620c26e5a0ce803a0404886e61dad778dbf9d273f4f7c89bea1c993197c360f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / hyperhtml-0.2.0-cp310-abi3-win_amd64.whl

Download URL hyperhtml-0.2.0-cp310-abi3-win_amd64.whl
Size 462.2 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
7bf8179192bc886a37c090da1ee6a9d3e2ac2c2d46057d40835433b9df16556e
BLAKE2b-256 checksum
How to use checksums
0d170d5b6099a02d4879b55aa9938e947f187256caf662ccae9ac1c40e0a37f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / hyperhtml-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL hyperhtml-0.2.0-cp310-abi3-manylinux_2_28_x86_64.whl
Size 585.6 kB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
3070ec12adc22a1c79e740272de3019e6bdfd4e1455ed9d60c3395e41557def4
BLAKE2b-256 checksum
How to use checksums
ddc052fd18fc1a579c48faaeb24ed9f9c52255307527376c104b1fb9c54e000d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / hyperhtml-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL hyperhtml-0.2.0-cp310-abi3-manylinux_2_28_aarch64.whl
Size 532.7 kB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
c32276d15aa13d804f4196ee67de5ed0da24464ff64484782a4f3c3f38df32bf
BLAKE2b-256 checksum
How to use checksums
e4e6ac92792b93b25ed0955cac3e444544945ff3973ebc55d4a9ecc969e36c04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / hyperhtml-0.2.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL hyperhtml-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
Size 510.6 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
aaeba4f30e3b117c1013ebf713a3e0636515ed6a060d8ec8ec0ff7dd130530d9
BLAKE2b-256 checksum
How to use checksums
f4208806361d991f3d019ac019fd2d3a2f6b17c471aec13d2008ec8e67c1d4cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / hyperhtml-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL hyperhtml-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 532.6 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
05d979ce54d43d9cba25661e323653b71e6891ad710c9ae41eceeed8049d6c7c
BLAKE2b-256 checksum
How to use checksums
5ae2d9a24042f8c57874b99011dd9949901a55283db053ad0b064b119f11901d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

0.2.1

6 release files

This release

0.2.0 This release

6 release files

0.1.2

6 release files

0.1.1

6 release files

0.1.0

5 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