Air: The Modern Python Web Framework for FastAPI and Pydantic

Summary
Air is a new Python web framework developed by the authors of "Two Scoops of Django." It leverages FastAPI, Starlette, and Pydantic to provide a fast and intuitive development experience. Designed for building both APIs and web pages, Air offers features like Air Tags for HTML generation, Jinja2 integration, and HTMX support, aiming to breathe fresh air into Python web development.
Repository Info
Introduction
Air is a new Python web framework created by the authors of "Two Scoops of Django." It aims to simplify web development by building upon popular and robust libraries like FastAPI, Starlette, and Pydantic. Air allows developers to efficiently build both RESTful APIs and dynamic web pages within a single application, offering a fresh approach to Python web development.
Installation
To get started with Air, you can install it using pip or conda:
pip install -U air
# or
conda install air -c conda-forge
For uv users, follow these steps:
uv venv
source .venv/bin/activate
uv init
uv add air
You can also install optional features (extras) to extend Air's capabilities:
# Standard extras (FastAPI’s recommended)
uv add "air[standard]"
# Pretty HTML Rendering (lxml, rich)
uv add "air[pretty]"
# SQLModel / SQLAlchemy support
uv add "air[sqlmodel]"
# OAuth clients via Authlib
uv add "air[auth]"
# All extras
uv add "air[all]"
You can combine extras in one command, for example: uv add "air[pretty,sql]".
Examples
A Simple Example
Create a main.py with:
import air
app = air.Air()
@app.get("/")
async def index():
return air.Html(air.H1("Hello, world!", style="color: blue;"))
Run the app with:
fastapi dev
If you have fastapi installed globally, you may see an error. In that case, run the app with:
uv run fastapi dev
This example uses Air Tags, which are Python classes that render as HTML. Air Tags are typed and documented, designed to work well with any code completion tool.
Combining FastAPI and Air
Air is just a layer over FastAPI, making it trivial to combine sophisticated HTML pages and a REST API into one app.
import air
from fastapi import FastAPI
app = air.Air()
api = FastAPI()
@app.get("/")
def landing_page():
return air.Html(
air.Head(air.Title("Awesome SaaS")),
air.Body(
air.H1("Awesome SaaS"),
air.P(air.A("API Docs", target="_blank", href="/api/docs")),
),
)
@api.get("/")
def api_root():
return {"message": "Awesome SaaS is powered by FastAPI"}
# Combining the Air and FastAPI apps into one
app.mount("/api", api)
Combining FastAPI and Air using Jinja2
If you prefer using Jinja2 instead of Air Tags, Air has you covered.
import air
from air.requests import Request
from fastapi import FastAPI
app = air.Air()
api = FastAPI()
# Air's JinjaRenderer is a shortcut for using Jinja templates
jinja = air.JinjaRenderer(directory="templates")
@app.get("/")
def index(request: Request):
return jinja(request, name="home.html")
@api.get("/")
def api_root():
return {"message": "Awesome SaaS is powered by FastAPI"}
# Combining the Air and and FastAPI apps into one
app.mount("/api", api)
Don't forget the Jinja template! Create a templates/home.html file with:
<!doctype html>
<html>
<head>
<title>Awesome SaaS</title>
</head>
<body>
<h1>Awesome SaaS</h1>
<p>
<a target="_blank" href="/api/docs">API Docs</a>
</p>
</body>
</html>
Using Jinja with Air is designed to be easier than with FastAPI directly.
Why use Air?
Air offers several compelling reasons for developers to choose it:
- Powered by FastAPI: Designed to work with FastAPI so you can serve your API and web pages from one app.
- Fast to code: Tons of intuitive shortcuts and optimizations designed to expedite coding HTML with FastAPI.
- Air Tags: Easy to write and performant HTML content generation using Python classes to render HTML.
- Jinja Friendly: No need to write
response_class=HtmlResponseandtemplates.TemplateResponsefor every HTML view. - Mix Jinja and Air Tags: Jinja and Air Tags both are first class citizens. Use either or both in the same view!
- HTMX friendly: We love HTMX and provide utilities to use it with Air.
- HTML form validation powered by Pydantic: Air Forms provide two ways to use Pydantic with HTML forms (dependency injection or from within views).
- Easy to learn yet well documented: Hopefully Air is so intuitive and well-typed you'll barely need to use the documentation. In case you do need to look something up we're taking our experience writing technical books and using it to make documentation worth boasting about.
Links
For more information, refer to the official documentation and source code:
- Documentation: https://airdocs.fastapicloud.dev/
- Source Code: https://github.com/feldroy/air