Typed-first Python web framework for blazingly fast, stable APIs.
Project description
BlazeAPI
BlazeAPI — Typed-first Python web framework for blazingly fast, stable APIs. Built on Granian and Pydantic.
Alpha -- BlazeAPI is under active development. APIs may change between releases. Not recommended for production use yet.
Quick Start
uv add blazeapi
from blazeapi import BlazeAPI, Request, JSONResponse
app = BlazeAPI()
@app.get("/")
async def index(request: Request) -> JSONResponse:
return JSONResponse({"message": "hello, world"})
@app.get("/users/{user_id:int}")
async def get_user(request: Request, user_id: int) -> JSONResponse:
return JSONResponse({"id": user_id})
if __name__ == "__main__":
app.run()
Features
- Typed path parameters --
{id:int},{slug:str},{amount:float},{uid:uuid},{filepath:path} - Pydantic serialization -- return Pydantic models directly from
JSONResponse - Sync and async handlers -- sync handlers run in a thread executor automatically
- Strict mode -- validates handler return type annotations at registration time
- Middleware -- standard ASGI middleware wrapping
- Granian server -- built-in
app.run()for development, or use Granian directly in production
Handlers
Handlers receive a Request object and any matched path parameters as keyword arguments:
@app.post("/items")
async def create_item(request: Request) -> JSONResponse:
data = await request.json()
return JSONResponse(data, status_code=201)
Sync handlers work too -- they're offloaded to a thread pool so they don't block the event loop:
@app.get("/sync")
def health(request: Request) -> JSONResponse:
return JSONResponse({"status": "ok"})
Return dicts or lists directly and they'll be serialized as JSON:
@app.get("/simple")
async def simple(request: Request) -> dict:
return {"works": True}
Strict Mode
Catch handler signature mistakes at import time instead of at request time:
app = BlazeAPI(strict=True)
@app.get("/x")
def bad(request: Request) -> dict: # TypeError -- must return Response or subclass
return {}
Middleware
Standard ASGI middleware pattern -- a function that takes an app and returns an app:
def add_cors(inner_app):
async def middleware(scope, receive, send):
async def custom_send(message):
if message["type"] == "http.response.start":
headers = list(message.get("headers", []))
headers.append((b"access-control-allow-origin", b"*"))
message = {**message, "headers": headers}
await send(message)
await inner_app(scope, receive, custom_send)
return middleware
app.add_middleware(add_cors)
Development
Prerequisites
- Python 3.12+
- uv for package management
Setup
git clone https://github.com/ritwiktiwari/blaze.git
cd blaze
make install
Running Tests
make test
# With coverage
make test-cov
# Across all Python versions
make test-matrix
Code Quality
# Run all checks (lint, format, type-check)
make verify
# Auto-fix lint and format issues
make fix
Documentation
make docs-serve
License
This project is licensed under the Apache-2.0 License - see the LICENSE file for details.
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 blazeapi-0.0.1.tar.gz.
File metadata
- Download URL: blazeapi-0.0.1.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6aa5d963251952200b07d92d86cf1b730e349142bbdf59518861dd11f6e46e46
|
|
| MD5 |
578fd1adfbb994fe87763df4ca24c75b
|
|
| BLAKE2b-256 |
d75756cc690076914867e1de8f4269b0ea97bfb0be244101fee721c7225373fe
|
Provenance
The following attestation bundles were made for blazeapi-0.0.1.tar.gz:
Publisher:
release.yml on ritwiktiwari/blazeapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
blazeapi-0.0.1.tar.gz -
Subject digest:
6aa5d963251952200b07d92d86cf1b730e349142bbdf59518861dd11f6e46e46 - Sigstore transparency entry: 907455336
- Sigstore integration time:
-
Permalink:
ritwiktiwari/blazeapi@32d3b0558390a940f164cf8e8b99fa2ce7193c6b -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/ritwiktiwari
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@32d3b0558390a940f164cf8e8b99fa2ce7193c6b -
Trigger Event:
push
-
Statement type:
File details
Details for the file blazeapi-0.0.1-py3-none-any.whl.
File metadata
- Download URL: blazeapi-0.0.1-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2848bde6dfe1dc86805ec9ce5ca059afeb43579911be67f2f7f79cca1c39aa9
|
|
| MD5 |
9a852c315f6ed170a16d6adcefad88a5
|
|
| BLAKE2b-256 |
cfe7db4263b8abefb89d28c0fc2fff6cd5e4b832fb24af4e54dbb15ad09ebf1d
|
Provenance
The following attestation bundles were made for blazeapi-0.0.1-py3-none-any.whl:
Publisher:
release.yml on ritwiktiwari/blazeapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
blazeapi-0.0.1-py3-none-any.whl -
Subject digest:
a2848bde6dfe1dc86805ec9ce5ca059afeb43579911be67f2f7f79cca1c39aa9 - Sigstore transparency entry: 907455344
- Sigstore integration time:
-
Permalink:
ritwiktiwari/blazeapi@32d3b0558390a940f164cf8e8b99fa2ce7193c6b -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/ritwiktiwari
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@32d3b0558390a940f164cf8e8b99fa2ce7193c6b -
Trigger Event:
push
-
Statement type: