Hyperclass
Subclass the web.
Hyperclass is an experiment in building interactive web applications as Python class hierarchies.
HTML elements are Python base classes. Python subclasses become CSS classes. Styles follow inheritance. Interaction is ordinary HTTP over WSGI, with htmx in the browser.
from hyperclass import css, div, grid, orange, rem
class card(div):
style = css(
display=grid,
gap=1 * rem,
padding=1.25 * rem,
border_radius=0.75 * rem,
)
class warning_card(card):
style = css(
border_color=orange,
background=orange.fade(0.08),
)
Calling:
warning_card("Something happened")
would produce ordinary, inspectable HTML:
<div class="card warning-card">Something happened</div>
The Python inheritance hierarchy and the CSS cascade cooperate instead of imitating one another.
The model
Hyperclass treats classes and instances differently:
- An element's first built-in HTML ancestor determines its tag.
- Each semantic subclass contributes a CSS class.
snake_caseclass names becomekebab-case.- Styles are inherited and emitted in method-resolution order.
- Multiple inheritance composes multiple CSS classes.
- Classes are also usable as selectors and htmx targets.
- Instances contain attributes, state, and child content.
class compact:
style = css(padding=0.5 * rem)
class clickable:
style = css(cursor="pointer")
class result_card(card, compact, clickable):
pass
A result_card would render as:
<div class="card compact clickable result-card"></div>
Components
Components are element subclasses with ordinary Python behavior:
from hyperclass import (
button,
closest,
form,
hidden,
hx,
input,
outer_morph,
output,
)
class counter(card):
def __init__(self, value):
self.value = value
def content(self):
yield output(str(self.value))
yield form(
input(type=hidden, name="value", value=self.value),
button("+1", type="submit"),
hx=hx.post(
"/counter",
target=closest(counter),
swap=outer_morph,
),
)
The class counter simultaneously represents:
- a Python type;
- an HTML
<div>; - the CSS selector
.counter; - a reusable styled component;
- a valid htmx target.
WSGI and htmx
Routes return elements directly:
from hyperclass import App
app = App()
@app.get("/")
def index(request):
return counter(0)
@app.post("/counter")
def increment(request):
return counter(request.form.int("value") + 1)
if __name__ == "__main__":
app.run()
The application is a normal WSGI callable. The development server can use Python's standard library; production deployment can use any WSGI server.
htmx supplies browser-to-server interaction without introducing a client-side component runtime. Hyperclass should favor native HTML and CSS for local behavior and use htmx when the server needs to participate.
Principles
- Python is the authoring language. Control flow, composition, inheritance, and reuse are ordinary Python.
- The browser remains the browser. Hyperclass emits standard HTML and CSS rather than recreating the DOM on the server.
- Classes mean classes. Python inheritance has a visible, predictable relationship to HTML classes and the CSS cascade.
- HTTP is the state boundary. There is no hydration protocol or hidden client component lifecycle.
- Output should be boring. Generated markup remains readable in View Source and DevTools.
- Small is a feature. Prefer the standard library, WSGI, and a pinned htmx asset over a large framework stack.
Status
Hyperclass is currently a design exploration. The examples above describe the intended direction, not a released API.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hyperclass-0.0.1.tar.gz.
File metadata
- Download URL: hyperclass-0.0.1.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05d01cd9006f82b1f62019eb58a03c6555ddf39cd598363922a2db48fc74dfe6
|
|
| MD5 |
8f2f94a310f85269bf421f027c421978
|
|
| BLAKE2b-256 |
dab707b7860891aaccb52ea0c29acee6c19f545081cc32c8c35e776e17435ec1
|
Provenance
The following attestation bundles were made for hyperclass-0.0.1.tar.gz:
Publisher:
release.yml on grantjenks/python-hyperclass
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hyperclass-0.0.1.tar.gz -
Subject digest:
05d01cd9006f82b1f62019eb58a03c6555ddf39cd598363922a2db48fc74dfe6 - Sigstore transparency entry: 2646262138
- Sigstore integration time:
-
Permalink:
grantjenks/python-hyperclass@e8680c0bf79869e07810bacdf46fd7e49ce04cfd -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/grantjenks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e8680c0bf79869e07810bacdf46fd7e49ce04cfd -
Trigger Event:
push
-
Statement type:
File details
Details for the file hyperclass-0.0.1-py3-none-any.whl.
File metadata
- Download URL: hyperclass-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8382b402eacb023589d39c1ac3bf24ea91aab4c3fe01c753f33ed3678d3ec80f
|
|
| MD5 |
b4e2aac91398c5cae89b5436fc3f654f
|
|
| BLAKE2b-256 |
527627abe4a80c6c0adc62e0d57aa3378bfb0471fa62bc02dd0398af7e409907
|
Provenance
The following attestation bundles were made for hyperclass-0.0.1-py3-none-any.whl:
Publisher:
release.yml on grantjenks/python-hyperclass
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hyperclass-0.0.1-py3-none-any.whl -
Subject digest:
8382b402eacb023589d39c1ac3bf24ea91aab4c3fe01c753f33ed3678d3ec80f - Sigstore transparency entry: 2646262278
- Sigstore integration time:
-
Permalink:
grantjenks/python-hyperclass@e8680c0bf79869e07810bacdf46fd7e49ce04cfd -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/grantjenks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e8680c0bf79869e07810bacdf46fd7e49ce04cfd -
Trigger Event:
push
-
Statement type: