FastHX #21
metaperl
started this conversation in
Framework Discussion: Specific
FastHX
#21
Replies: 1 comment
-
https://www.reddit.com/r/Python/comments/19eeeh4/new_package_fasthx_fastapi_and_htmx_the_right_way/ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Source code: https://github.com/volfpeter/fasthx
Documentation and examples: https://volfpeter.github.io/fasthx
FastHX
FastAPI and HTMX, the right way.
Key features:
markyp-html
ordominate
.Installation
The package is available on PyPI and can be installed with:
$ pip install fasthx
Examples
For complete, but simple examples that showcase the basic use of
FastHX
, please see the examples folder.If you're looking for a more complex (
Jinja2
) example with features like active search, lazy-loading, server-sent events, custom server-side HTMX triggers, dialogs, and TailwindCSS and DaisyUI integration, check out this FastAPI-HTMX-Tailwind example.Jinja2 templating
To start serving HTML and HTMX requests, all you need to do is create an instance of
fasthx.Jinja
and use itshx()
orpage()
methods as decorators on your routes.hx()
only triggers HTML rendering for HTMX requests, whilepage()
unconditionally renders HTML, saving you some boilerplate code. See the example code below:Custom templating
If you're not into Jinja templating, the
hx()
andpage()
decorators give you all the flexibility you need: you can integrate any HTML rendering or templating engine intofasthx
simply by implementing theHTMLRenderer
protocol. Similarly to the Jinja case,hx()
only triggers HTML rendering for HTMX requests, whilepage()
unconditionally renders HTML. See the example code below:Dependencies
The only dependency of this package is
fastapi
.Development
Use
ruff
for linting and formatting,mypy
for static code analysis, andpytest
for testing.The documentation is built with
mkdocs-material
andmkdocstrings
.Contributing
All contributions are welcome.
Contributors
License - MIT
The package is open-sourced under the conditions of the MIT license.
Beta Was this translation helpful? Give feedback.
All reactions