OxyRoute
High-performance, production-grade RSGI web framework for Python powered by a native Rust hot path.
Overview
OxyRoute combines the expressiveness and developer experience of Python with the raw speed, safety, and memory efficiency of Rust. Designed from the ground up for Granian RSGI, OxyRoute executes request routing, body parsing, token-bucket rate limiting, JWT authentication, and response encoding directly in compiled Rust (PyO3), executing Python code only for your business logic handlers.
Incoming Request
│
▼
┌──────────────────────────────────────────────────────────┐
│ Granian (RSGI Protocol) │
└───────────────┬──────────────────────────────────────────┘
│ Zero-copy scope & protocol pass
▼
┌──────────────────────────────────────────────────────────┐
│ OxyRoute Rust Core (_oxyroute) │
│ ├─ Radix Routing (matchit, zero-alloc path slices) │
│ ├─ Sharded Token-Bucket Rate Limiter (HTTP 429) │
│ ├─ JWT Verification (RS256/ES256/EdDSA/HS* via oxyjwt) │
│ ├─ Request Body & Multipart (Thread-local buffer pool) │
│ └─ PEP 590 Vectorcall Direct Dispatch │
└───────────────┬──────────────────────────────────────────┘
│ Extracted kwargs & dependencies
▼
┌──────────────────────────────────────────────────────────┐
│ Python Handlers & Dependencies │
│ def get_user(user_id: int, auth: Token, db = Depends()) │
└──────────────────────────────────────────────────────────┘
Key Features
⚡ Rust-Powered Performance
- PEP 590 Vectorcall: Invokes Python handler functions directly via Vectorcall protocol, eliminating
PyDictallocations for kwargs on the hot path. - 64-Byte Cacheline Layout: Internal
RouteEntrymetadata is packed into a single 64-byte struct for optimal CPU L1 cache locality. - Zero-Allocation Path Slicing: URL path parameters are sliced directly from the request URI buffer without heap allocations.
- Single-Pass Router: Unified bitmask radix matching for instant HTTP
405 Method Not Allowedresolution. - Thread-Local Buffer Pooling: Request body readers reuse pooled memory buffers, minimizing GC pressure.
- Pre-Baked Static Response Headers: Eliminates dynamic string formatting for standard response headers.
🛡️ Built-in Security & Resilience
- Native Rate Limiting: In-memory sharded Token Bucket rate limiter with configurable keys (
ipwith proxy support,header:<name>,global) and automatic RFC-compliantRetry-After/X-RateLimit-*headers. - Adaptive Concurrency Limiting: Automatic load shedding (
AdaptiveConcurrencyLimiter) to prevent memory exhaustion (OOM) and tail latency spikes under traffic bursts. - JWT Authentication: Native Rust verification (
require_jwt=True) supporting HS256/384/510, RSA, EC, and EdDSA viaoxyjwt. - Security Middlewares: High-performance CORS, CSRF (double-submit cookie), and browser Security Headers (HSTS, CSP, X-Frame-Options).
🛠️ Modern Developer Experience
- DAG Dependency Injection: Graph-based dependency resolution (
Depends) with topological sorting and cycle detection at route registration time. - OpenAPI 3.1.0 & Interactive Docs: Native
GET /openapi.jsonwith Scalar and Swagger UI mounted at/docs, automatic 401/422 documentation, and Pydantic v2 JSON Schema compatibility. - Auto Pydantic Model Inference: Automatically infers and validates request bodies from type annotations without boilerplate.
- Native RSGI WebSockets: Full-duplex WebSocket support (
@app.websocket) with concurrent send frame serialization and 1001 Going Away graceful shutdown broadcast. - Typed & Tested: PEP 561
py.typedmarker package with complete_oxyroute.pyitype stubs.
Installation
pip install oxyroute
With development dependencies:
pip install "oxyroute[dev]"
Requirements: Python ≥ 3.10 and Granian (
pip install granian). Pre-built wheels are available for Linux (x86_64, aarch64), macOS (Apple Silicon & Intel), and Windows (x64).
Quick Start
Create main.py:
from pydantic import BaseModel
from oxyroute import App, Depends, HTTPException, Request
app = App(title="OxyRoute Production API", docs_ui="scalar")
class Item(BaseModel):
name: str
price: float
def get_db():
return {"status": "connected"}
@app.get("/")
def read_root() -> dict[str, str]:
return {"status": "healthy", "engine": "OxyRoute Rust RSGI"}
# Rate limited to 60 requests per minute by client IP
@app.get("/items/:item_id", rate_limit="60/minute")
def read_item(item_id: int, db=Depends(get_db)) -> dict:
return {"item_id": item_id, "db_status": db["status"]}
# Automatically validates JSON request body via Pydantic
@app.post("/items", status_code=201)
def create_item(item: Item) -> dict:
return {"created": item.name, "price": item.price}
# Native WebSocket endpoint
@app.websocket("/ws/echo")
async def echo_socket(ws) -> None:
await ws.accept()
while True:
msg = await ws.receive_text()
await ws.send_text(f"Echo: {msg}")
Run with Granian RSGI:
granian --interface rsgi --workers 4 --threads 2 main:app
Interactive documentation is automatically available at http://localhost:8000/docs.
Examples & Patterns
1. Token Bucket Rate Limiting
# Rate limit by custom API Key header
@app.get("/api/v1/data", rate_limit="1000/hour", rate_limit_key="header:X-API-Key")
def secure_data() -> dict:
return {"data": "sensitive"}
2. DAG Dependency Injection
from oxyroute import Depends
def config():
return {"env": "prod"}
def auth_service(cfg = Depends(config)):
return {"auth_mode": cfg["env"]}
@app.get("/profile")
def user_profile(auth = Depends(auth_service)):
return {"auth": auth}
3. JWT Route Protection
@app.get("/admin", require_jwt=True)
def admin_panel(request: Request) -> dict:
claims = request.state.jwt_claims
return {"admin_id": claims.get("sub")}
Documentation
- Usage Guide — Complete configuration and operational reference.
- Rate Limiting — Token bucket algorithm, header formats, key strategies.
- RSGI & Granian — Architecture, worker lifecycle, and deployment.
- Dependencies & DAG — Dependency injection, topological ordering, lifecycle.
- OpenAPI & Docs — OpenAPI 3.1.0 specifications, Scalar, and Swagger UI.
- WebSockets — Full-duplex messaging, frame ordering, graceful shutdown.
- Database & SQLx — Native database streaming and query helpers.
- Resilience — Concurrency limiting and load shedding.
- Security — JWT, CORS, CSRF, and Security Headers.
Contributing
Contributions are warmly welcomed! Please read CONTRIBUTING.md and Development Workflow before opening a pull request.
License
OxyRoute is open-source software licensed under the MIT License.
Metadata
Release files for oxyroute 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| oxyroute-0.6.0.tar.gz | 232.0 kB | Without provenance | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| oxyroute-0.6.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| oxyroute-0.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| oxyroute-0.6.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
| oxyroute-0.6.0-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 8.1 MB
Release files / oxyroute-0.6.0.tar.gz
| Download URL | oxyroute-0.6.0.tar.gz |
|---|---|
| Size | 232.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dce14ff10f5a0e869acd4c72d970157676e9964650d859de5199c7c2a280446f
|
|
BLAKE2b-256 checksum How to use checksums |
4409f933e8c861a3ff21fb1cbbfe1bf586df6672065a846769e7231f489995c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / oxyroute-0.6.0-cp310-abi3-win_amd64.whl
| Download URL | oxyroute-0.6.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
6b0e6bb64a9d75f6238bd7e3f4610b69ecfc274fb18f37434cf60d9ddbf9e176
|
|
BLAKE2b-256 checksum How to use checksums |
57fc71618099a71ed3bfc71068355bcd567bb15e85752709c0358f7dbe64c11e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / oxyroute-0.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | oxyroute-0.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
99ae7d17922a14ca934125b4dc8acc43fd49bcb18b7ff87132548c7e20ba265d
|
|
BLAKE2b-256 checksum How to use checksums |
4cbf27061f650828700a0a91ffc05565ec758eb2e039e5727c8a6c9b383c6a45
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / oxyroute-0.6.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | oxyroute-0.6.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
d24d6b52896ca27d356fe1b687d06846d3964c8bf36ef6e8f9cc135730ef2278
|
|
BLAKE2b-256 checksum How to use checksums |
90d7a0e0279b74f37058f428d6b467543a1a51c6ab8db7bff8400e2d1f88db50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / oxyroute-0.6.0-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | oxyroute-0.6.0-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 2.0 MB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
f5703a422983db521b4474928b2d54a317ce04f28a9c347430586aff4e4af7e0
|
|
BLAKE2b-256 checksum How to use checksums |
0af29693da66c2fb16ae3e0019013ddc32b4f5c3c258bcf3d553fa3744f3b6d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for oxyroute 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.