UI components for Python using Pydantic and Jinja2 templates
Project description
PyJinHx
Type-safe UI components for Python web apps. A component is a Pydantic model plus a Jinja template sitting next to it — nest them with PascalCase tags, and co-located JS/CSS is collected automatically at render.
pip install pyjinhx
Example
A Card that renders a Button — the tag's attributes become validated Pydantic fields:
# components/button.py
from pyjinhx import BaseComponent
class Button(BaseComponent):
id: str
text: str
variant: str = "default"
<!-- components/button.html -->
<button id="{{ id }}" class="btn btn-{{ variant }}">{{ text }}</button>
<!-- components/card.html -->
<div id="{{ id }}" class="card">
<h2>{{ title }}</h2>
<Button id="cta" text="{{ button_text }}" variant="primary"/>
</div>
# components/card.py
from pyjinhx import BaseComponent, Renderer
class Card(BaseComponent):
id: str
title: str
button_text: str = "Sign up"
Renderer.set_default_environment("./components")
html = Card(id="hero", title="Get Started").render()
Drop a button.css or card.js next to the component and it's included once, automatically.
Reactivity (HTMX)
Components declare what state they depend on. Return one component from a mutation route — every other mounted region that reacts to the same keys updates via out-of-band swaps, no manual wiring:
from pyjinhx import ReactiveComponent, MutationKey, mutates, setup
class Keys(MutationKey):
TODOS = "todos"
class Counter(ReactiveComponent, react={Keys.TODOS}):
remaining: int
@classmethod
def load(cls) -> "Counter":
return cls(remaining=db.remaining())
@mutates(Keys.TODOS)
def toggle_all():
db.toggle_all()
setup(app) # FastAPI: lifespan + middleware, done
@app.post("/todos/toggle")
def toggle():
toggle_all()
return Counter.render() # other regions reacting to TODOS update too
Learn more
- Usage tiers — adopt only the layers you need
- Components · PascalCase tags · Assets
- Reactivity guide · full todo example
- Built-in UI kit
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
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 pyjinhx-0.18.0.tar.gz.
File metadata
- Download URL: pyjinhx-0.18.0.tar.gz
- Upload date:
- Size: 302.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c17387d715e9970579b90fc3bd5f528e874cad2fb2a5f96a4f9a24eff085f96d
|
|
| MD5 |
9afc738060861a93d94fb9b1792a6369
|
|
| BLAKE2b-256 |
7337d7282ba807cc696d86f126235dfe7424d1e449cbc50c85a38483a271f188
|
File details
Details for the file pyjinhx-0.18.0-py3-none-any.whl.
File metadata
- Download URL: pyjinhx-0.18.0-py3-none-any.whl
- Upload date:
- Size: 135.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
493f06662cbcf8581c3a20094eafc3338b46989d4fc13689e5494069e9080823
|
|
| MD5 |
2dfc8efa209a7b832fc4391310ac6303
|
|
| BLAKE2b-256 |
bbea412d731b0006a67538651c3719713648316962a8f5ae5948db3c1dd6b17a
|