FastAPI Syntax · Native Tokio/Hyper Core
High-Speed Python Web Framework powered by Native Rust
RustAPI combines FastAPI's intuitive syntax with a high-concurrency Rust Tokio/Hyper runtime. Write Python handlers while offloading zero-copy SQL streaming, JWT encoding, Argon2 hashing, and hot-path routes directly to compiled C/Rust speed.
CRUD Performance Report
RustAPI outperforms FastAPI across ALL CRUD endpoints (up to 12.16x faster on DELETE, 9.29x on PUT, 5.98x on POST).
Zero-Copy SQL Stream
Stream UTF-8 JSON query results direct from sqlx to socket without creating Python dict objects or holding GIL.
Embedded Rust Primitives
Native JWT encoding/decoding, Argon2 password hashing, and MiniJinja rendering running in compiled C/Rust memory.
AI Agent MCP Server
Expose tools, resources, and prompts to Claude & AI agents via Model Context Protocol (JSON-RPC over Streamable HTTP).
3-Tier Architecture
Write Tier 1 Python handlers, Tier 2 hybrid primitives, or Tier 3 pure Rust fast-paths (>47,000 req/s) seamlessly.
Complete API Reference
Detailed documentation for Engine, Request, Response, Pydantic coercion, and dependency_overrides.
⚡ Verified Benchmark Snapshot
Target: 1,000 pre-seeded rows in SQLite under persistent concurrent connections.
🚀 Getting Started & Installation
RustAPI is published as a pre-compiled wheel package on PyPI (`pyrustapi`) with zero Rust toolchain required for end users.
Installing via Pip
pip install pyrustapi pydantic
Writing Your First Application (main.py)
import rustapi
from pydantic import BaseModel
# Initialize RustAPI Engine (Tokio runtime + Hyper HTTP server)
app = rustapi.Engine()
class Item(BaseModel):
name: str
price: float
@app.get("/")
def read_root():
return {"Hello": "World from RustAPI"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
return {"item_id": item_id, "q": q}
@app.post("/items")
def create_item(item: Item):
return {"item_name": item.name, "item_price": item.price}
if __name__ == "__main__":
app.run(host="127.0.0.1", port=8000)
Development Auto-Reload Mode
app.run(host="127.0.0.1", port=8000, reload=True)
⚡ RustAPI Benchmark Dashboard
Complete Multi-Tier Performance Visualizations & Matrix vs FastAPI (CPython 3.13)
📊 Throughput (Requests / Sec — Higher is Better)
⏱️ Latency p50 (Milliseconds — Lower is Better)
📋 Full Multi-Tier Empirical Benchmark Matrix
| Task Scenario | Execution Tier | Throughput (RPS) | Latency p50 | Latency p99 | Speedup vs FastAPI |
|---|
📊 Comprehensive CRUD Performance Report
Tested on 1,000 pre-seeded SQLite database rows using identical schemas, Pydantic data models, and persistent concurrent HTTP connections.
📈 1. Python Surface Routes (Tier 1/2) — Pure FastAPI Compatibility Table
| Test Case & Operation | FastAPI (Python Stack) | RustAPI Tier 1/2 (Optimized Engine) | RustAPI Speedup Advantage |
|---|---|---|---|
GET List (1,000 Rows) (GET /books) |
17.11 req/s (1,752.9ms) | 121.89 req/s (246.1ms) | 🚀 7.12x FASTER |
GET Single Row (GET /books/1) |
1,131.25 req/s (26.5ms) | 3,580.27 req/s (8.3ms) | 🚀 3.16x FASTER |
POST Create Record (POST /books) |
293.33 req/s (102.2ms) | 1,753.78 req/s (17.1ms) | 🚀 5.98x FASTER |
PUT Update Record (PUT /books/1) |
316.85 req/s (94.6ms) | 2,944.72 req/s (10.1ms) | 🚀 9.29x FASTER |
DELETE Book Record (DELETE /books/1) |
402.06 req/s (74.6ms) | 4,422.77 req/s (6.7ms) | 🚀 11.00x FASTER |
⚡ 2. Tier 3 Native Rust Fast-Path Routes (app.add_native_route)
| Endpoint & Fast-Path Method | RustAPI Tier 3 Native Throughput | Avg Latency | Comparison vs FastAPI |
|---|---|---|---|
GET Single Row Fast-Path (GET /tier3/books/1) |
6,218.75 req/sec | 4.82 ms | 🚀 5.50x FASTER than FastAPI |
POST Write Fast-Path (POST /tier3/books) |
3,441.10 req/sec | 8.72 ms | 🚀 11.73x FASTER than FastAPI |
Static Health Check Fast-Path (/tier3/health) |
47,034.00 req/sec | 2.00 ms | ⚡ Ultimate C-Speed Fast Path |
📊 Visual Throughput Comparison (Req/Sec)
🗄️ Rust-Native Database Engine
RustAPI embeds high-concurrency sqlx connection pooling directly inside the engine for PostgreSQL and SQLite.
import rustapi
app = rustapi.Engine()
db = app.connect_db("sqlite://data.db")
@app.get("/products")
def get_products():
# Streams raw JSON direct from sqlx -> socket without Python dict allocation
return db.query_json("SELECT id, name, price FROM products")
@app.post("/products")
def create_product(name: str, price: float):
affected = db.execute(f"INSERT INTO products (name, price) VALUES ('{name}', {price})")
return {"status": "created", "affected": affected}
🔐 Embedded Rust Security Primitives
1. Native JWT Engine (jsonwebtoken crate)
import rustapi
token = rustapi.encode_jwt({"sub": "user_100"}, secret="secret_key")
claims = rustapi.decode_jwt(token, secret="secret_key")
2. Argon2 Password Hashing
hashed = rustapi.hash_password("mypassword123")
is_valid = rustapi.verify_password("mypassword123", hashed)
3. Native MiniJinja Renderer
html = rustapi.render_template("<h1>Welcome {{ name }}!</h1>", {"name": "Boopathi"})
🤖 Built-in Model Context Protocol (MCP) Server
Expose tools, resources, and prompts to Claude & AI agents via Model Context Protocol (JSON-RPC over Streamable HTTP) at POST /mcp.
@app.tool(description="Search catalog for AI agents")
def search_catalog(category: str):
return f"Found 5 items in {category}"
@app.resource(uri="config://system", mime_type="application/json")
def get_system_config():
return '{"status": "healthy"}'
📖 Complete API Reference
rustapi.Engine(title="RustAPI", version="0.1.0")
Main application container initializing Tokio runtime, Hyper HTTP service, and router tables.
app.get(path, response_model=None): Register GET endpoint.app.post(path, response_model=None): Register POST endpoint.app.put(path, response_model=None): Register PUT endpoint.app.delete(path, response_model=None): Register DELETE endpoint.app.add_native_route(path, body, method="GET", status_code=200): Register Tier 3 Rust fast-path.app.connect_db(url): Connect to SQLite or PostgreSQL connection pool.app.run(host="127.0.0.1", port=8000, reload=False): Start web server.