Skip to main content

OxyRoute

High-performance, production-grade RSGI web framework for Python powered by a native Rust hot path.

CI Status PyPI version Python 3.10+ Rust PyO3 Granian RSGI License: MIT


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 PyDict allocations for kwargs on the hot path.
  • 64-Byte Cacheline Layout: Internal RouteEntry metadata 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 Allowed resolution.
  • 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 (ip with proxy support, header:<name>, global) and automatic RFC-compliant Retry-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 via oxyjwt.
  • 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.json with 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.typed marker package with complete _oxyroute.pyi type 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.7.0

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

Source distribution (sdist)

Source distribution for oxyroute 0.7.0
File Size Uploaded Provenance
oxyroute-0.7.0.tar.gz 258.1 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for oxyroute 0.7.0
File
oxyroute-0.7.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
oxyroute-0.7.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.7.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
oxyroute-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 8.3 MB

Release files / oxyroute-0.7.0.tar.gz

Download URL oxyroute-0.7.0.tar.gz
Size 258.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a802c38ee827c9b1af2e35295fe89b8528d2197b078c0de2125443381a1093c0
BLAKE2b-256 checksum
How to use checksums
e87e06646517338cc9c92b57791c397640eaf57a22228abd3205af9c56c01803
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.7.0-cp310-abi3-win_amd64.whl

Download URL oxyroute-0.7.0-cp310-abi3-win_amd64.whl
Size 1.9 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
aaf94d1843aa11149e925d9ad960a55ebcfb32c00ebdd6574463e41e392bab8e
BLAKE2b-256 checksum
How to use checksums
8e1e101c1a99aa32c1c49cb702ffa5392f1c201c06432b5b1d7dfb60e9e8aaea
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.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL oxyroute-0.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.2 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
e88f0003028597d9ebc46cd14f72cc6d0691faa527c0c2f68e0c01bd0cb1fbff
BLAKE2b-256 checksum
How to use checksums
195bdfa82dc077c1913ccbf7bf41fa6dc0a5e4a0b1042e8909ba8ef9b49ba332
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.7.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL oxyroute-0.7.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
27e3507310d3e7d947dd1d2389af89d457d60dab438b7bfcccbb9df86b4c544f
BLAKE2b-256 checksum
How to use checksums
1f35d6bc0d6c69bf50e69b63f6554b9b8fecd887992a0b9eb5bee2624576ff8e
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.7.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL oxyroute-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 2.1 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
a69d81e9feb83c59b93a9460d0aad3e1d839455b707cc551bfb8d281b1ed6aba
BLAKE2b-256 checksum
How to use checksums
d113e1af921d80ce84049053b94cc15e19179a887f487f89e1634d03bc9f1596
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.7.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.

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