Skip to main content

About

HotMix allows you to conveniently add htmx to your FastAPI app.

Getting Started

Install the packages

pip install uvicorn fastapi jinja2 hotmix

Create a tempate folder and add a template.

main.py
templates/
	index.html

Content of index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Simple Page</title>
  </head>
  <body>
    <h1>HotMix Hello World</h1>
    <p>Parameter from the API: {{ param }}</p>
    <p>You are accessing the path: {{ request.url.path }}</p>
  </body>
</html>

Content of main.py

from fastapi import FastAPI, Request
import hotmix as hm

app = FastAPI()
hm.init("templates")

@app.get("/")
@hm.htmx("index")
async def main(request: Request):
    return {"param": 37}

How it works

Initialize hotmix while setting the templates folder path

import hotmix as hm

hm.init("templates")

For each of the routes which should return some htmx content, add a decorator specifying the name of the template file, without the .html extension.

@app.get("/")
@hm.htmx("index")
async def main(request: Request):
    return {"param": 37}

Instead of returning the dictionary as JSON data, it will pass the dictionary to the jinja2 template engine, which will return the .html with the desired parameters.

HotMix can handle two kinds of parameters:

  • Explicit paramters: returned in the request answer dictionary. They are accessed by giving their names: {{ param }}.
  • Request parameters, accessed through the request keyword. For example {{ request.url.path }}.

Release files for hotmix 0.0.4

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

Source distribution (sdist)

Source distribution for hotmix 0.0.4
File Size Uploaded
hotmix-0.0.4.tar.gz 2.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hotmix 0.0.4
File Interpreter ABI Platform
hotmix-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 5.0 kB

Release files / hotmix-0.0.4.tar.gz

Download URL hotmix-0.0.4.tar.gz
Size 2.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3683a5fb090c7858b4ba5f95913228317c1a0ce3038151fb19f6c6e24031f574
BLAKE2b-256 checksum
How to use checksums
f0bdeff0f0007906e736fce043a695f517606485802727d0382f93b12ca949b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / hotmix-0.0.4-py3-none-any.whl

Download URL hotmix-0.0.4-py3-none-any.whl
Size 2.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce92d24d671a68495efabfe14bb4f10465cd0c5debcfd89a5dc52376dfc838cb
BLAKE2b-256 checksum
How to use checksums
1deb55911d955014f0f7cd86476d82d9c0983aa05902e100a788416a90672572
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 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