Examples¶
The examples/ directory in the repo has working demos covering different parts of the library. You can run any of them with uv run.
Static page¶
Generates an HTML file to stdout. No server involved, just elements, styles, keyframe animations, and event handlers. Pipe to a file and open with your browser to view.
Counter¶
An HTMX-powered counter with increment, decrement, and reset buttons. Good starting point for understanding how HTMX partial responses work with ztml.
Todo app¶
Full CRUD todo list with add, toggle, and delete. Demonstrates form handling, path parameters, and Fragment for returning multiple elements.
Custom components¶
Shows the __ztml_render__ protocol with Card, Badge, NavLink, and Page components. Renders to a static HTML file.
Auth demo¶
Sessions, before hooks, and form data parsing. Has a login page, a protected dashboard, and logout. Shows how require_auth works as a before hook.
WebSocket chat¶
A chat room using raw WebSockets. Multiple clients can connect and broadcast messages. The client-side code uses RawJs and On event handlers.
SSE clock¶
A live-updating clock using NamedEventStream with two sources running at different intervals. Shows HTMX SSE extension integration.
Jupyter notebook¶
examples/notebook_demo.ipynb demonstrates interactive development in Jupyter, including _repr_html_() rendering and building styled components inline.