Skip to content

justrach/turboAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

TurboAPI ๐Ÿš€

The Python web framework that gives you FastAPI's beloved developer experience with up to 92x the performance.

Built with Rust for revolutionary speed, designed with Python for developer happiness.

โšก Try it in 30 seconds: python examples/multi_route_app.py โ†’ Visit http://127.0.0.1:8000
๐Ÿ”ฅ See the difference: Same FastAPI syntax, 184K+ RPS performance!
๐ŸŽฏ Zero migration effort: Change 1 import line, keep all your existing code
๐Ÿš€ LATEST in v0.4.13: POST body parsing fixed - ML/AI applications now work!

๐Ÿ†• What's New in v0.4.x Release Series

v0.4.13: POST Body Parsing Fix (LATEST) ๐ŸŽ‰

Critical Fix: POST request body parsing now works! This resolves the major blocking issue for real-world ML/AI applications.

โœ… What Was Fixed

  • POST handlers can now receive request body data
  • Single parameter handlers work: handler(request_data: dict)
  • Large payloads supported (42,000+ items tested in 0.28s!)
  • FastAPI compatibility for POST endpoints

๐Ÿ“Š Test Results: 5/5 Passing

  • Single dict parameter: โœ…
  • Single list parameter: โœ…
  • Large JSON payload (42K items): โœ…
  • Satya Model validation: โœ…
  • Multiple parameters: โœ…

๐Ÿš€ What Now Works

# Single parameter receives entire body
@app.post('/predict/backtest')
def handler(request_data: dict):
    # โœ… Receives entire JSON body with 42K+ candles!
    candles = request_data.get('candles', [])
    return {'received': len(candles)}

# Satya Model validation
from satya import Model, Field

class BacktestRequest(Model):
    symbol: str = Field(min_length=1)
    candles: list
    initial_capital: float = Field(gt=0)

@app.post('/backtest')
def backtest(request: BacktestRequest):
    data = request.model_dump()  # Use model_dump() for Satya models
    return {'symbol': data["symbol"]}

v0.4.12: Python 3.14 Support + Routes Property

  • Python 3.14.0 stable support (just released!)
  • Python 3.14t free-threading support
  • Added routes property to TurboAPI for introspection
  • CI/CD updated with 16 wheel builds (4 Python versions ร— 4 platforms)

v0.4.0: Pure Rust Async Runtime

  • 184,370 sync RPS (92x improvement from baseline!) โšก
  • 12,269 async RPS (6x improvement from baseline!)
  • Sub-millisecond latency (0.24ms avg for sync endpoints)
  • Tokio work-stealing scheduler across all CPU cores
  • Python 3.14 free-threading (no GIL overhead)
  • pyo3-async-runtimes bridge for seamless Python/Rust async
  • 7,168 concurrent task capacity (512 ร— 14 cores)
  • BREAKING: app.run() now uses Tokio runtime (use app.run_legacy() for old behavior)

Complete Security Suite (100% FastAPI-compatible)

  • OAuth2 (Password Bearer, Authorization Code)
  • HTTP Auth (Basic, Bearer, Digest)
  • API Keys (Query, Header, Cookie)
  • Security Scopes for fine-grained authorization

Complete Middleware Suite (100% FastAPI-compatible)

  • CORS with regex and expose_headers
  • Trusted Host (Host Header attack prevention)
  • GZip compression
  • HTTPS redirect
  • Session management
  • Rate Limiting (TurboAPI exclusive!)
  • Custom middleware support

๐ŸŽจ 100% FastAPI-Compatible Developer Experience

TurboAPI provides identical syntax to FastAPI - same decorators, same patterns, same simplicity. But with 5-10x better performance.

Instant Migration from FastAPI

# Just change this line:
# from fastapi import FastAPI
from turboapi import TurboAPI

# Everything else stays exactly the same!
app = TurboAPI(
    title="My Amazing API",
    version="1.0.0",
    description="FastAPI syntax with TurboAPI performance"
)

@app.get("/")
def read_root():
    return {"message": "Hello TurboAPI!", "performance": "๐Ÿš€"}

@app.get("/users/{user_id}")
def get_user(user_id: int):
    return {"user_id": user_id, "username": f"user_{user_id}"}

@app.post("/users")
def create_user(name: str, email: str):
    return {"name": name, "email": email, "status": "created"}

# Same run command as FastAPI
app.run(host="127.0.0.1", port=8000)

That's it! Same decorators, same syntax, 5-10x faster performance.

๐Ÿš€ Revolutionary Performance

Why TurboAPI is 5-10x Faster

  • ๐Ÿฆ€ Rust-Powered HTTP Core: Zero Python overhead for request handling
  • โšก Zero Middleware Overhead: Rust-native middleware pipeline
  • ๐Ÿงต Free-Threading Ready: True parallelism for Python 3.13+
  • ๐Ÿ’พ Zero-Copy Optimizations: Direct memory access, no Python copying
  • ๐Ÿ”„ Intelligent Caching: Response caching with TTL optimization

Benchmark Results - v0.4.0 Pure Rust Async Runtime (wrk load testing)

Run the benchmarks yourself:

# TurboAPI standalone benchmark
python examples/multi_route_app.py  # Terminal 1
python benchmark_v040.py            # Terminal 2

# TurboAPI vs FastAPI comparison (automated)
python benchmark_turboapi_vs_fastapi.py

TurboAPI Standalone Performance:

๐Ÿš€ Light Load (50 connections):
  Sync Root:           73,444 req/s  (0.70ms latency)  - 36.7x faster than baseline
  Sync User Lookup:   184,370 req/s  (0.24ms latency)  - 92.2x faster than baseline โšก
  Sync Search:         27,901 req/s  (1.75ms latency)  - 14.0x faster than baseline
  Async Data:          12,269 req/s  (3.93ms latency)  - 6.2x faster than baseline
  Async User:           8,854 req/s  (5.43ms latency)  - 4.5x faster than baseline

๐Ÿš€ Medium Load (200 connections):
  Sync Root:           71,806 req/s  (2.79ms latency)  - 35.9x faster than baseline
  Async Data:          12,168 req/s  (16.38ms latency) - 6.1x faster than baseline
  Sync Search:         68,716 req/s  (2.94ms latency)  - 34.4x faster than baseline

๐Ÿš€ Heavy Load (500 connections):
  Sync Root:           71,570 req/s  (6.93ms latency)  - 35.8x faster than baseline
  Async Data:          12,000 req/s  (41.59ms latency) - 6.1x faster than baseline

โšก Peak Performance:
  โ€ข Sync Endpoints:  184,370 RPS (92x faster!) - Sub-millisecond latency
  โ€ข Async Endpoints:  12,269 RPS (6x faster!)  - With asyncio.sleep() overhead
  โ€ข Pure Rust Async Runtime with Tokio work-stealing scheduler
  โ€ข Python 3.14 free-threading (no GIL overhead)
  โ€ข True multi-core utilization across all 14 CPU cores

TurboAPI vs FastAPI Head-to-Head:

๐Ÿ”ฅ Identical Endpoints Comparison (50 connections, 10s duration):
  Root Endpoint:
    TurboAPI:  70,690 req/s  (0.74ms latency)
    FastAPI:    8,036 req/s  (5.94ms latency)
    Speedup:    8.8x faster โšก

  Path Parameters (/users/{user_id}):
    TurboAPI:  71,083 req/s  (0.72ms latency)
    FastAPI:    7,395 req/s  (6.49ms latency)
    Speedup:    9.6x faster โšก

  Query Parameters (/search?q=...):
    TurboAPI:  71,513 req/s  (0.72ms latency)
    FastAPI:    6,928 req/s  (6.94ms latency)
    Speedup:    10.3x faster โšก

  Async Endpoint (with asyncio.sleep):
    TurboAPI:  15,616 req/s  (3.08ms latency)
    FastAPI:   10,147 req/s  (4.83ms latency)
    Speedup:    1.5x faster โšก

๐Ÿ“Š Average: 7.6x faster than FastAPI
๐Ÿ† Best: 10.3x faster on query parameters

๐ŸŽฏ Zero Learning Curve

If you know FastAPI, you already know TurboAPI:

๐Ÿ”ฅ LIVE DEMO - Try It Now!

Experience TurboAPI's FastAPI-compatible syntax with real-time performance metrics:

# Run the interactive showcase
python live_performance_showcase.py

# Visit these endpoints to see TurboAPI in action:
# ๐Ÿ  http://127.0.0.1:8080/ - Welcome & feature overview  
# ๐Ÿ“Š http://127.0.0.1:8080/performance - Live performance metrics
# ๐Ÿ” http://127.0.0.1:8080/search?q=turboapi&limit=20 - FastAPI-style query params
# ๐Ÿ‘ค http://127.0.0.1:8080/users/123?include_details=true - Path + query params
# ๐Ÿ’ช http://127.0.0.1:8080/stress-test?concurrent_ops=5000 - Stress test
# ๐Ÿ http://127.0.0.1:8080/benchmark/cpu?iterations=10000 - CPU benchmark

What you'll see:

  • โœ… Identical FastAPI syntax - same decorators, same patterns
  • โšก Sub-millisecond response times - even under heavy load
  • ๐Ÿ“Š Real-time performance metrics - watch TurboAPI's speed
  • ๐Ÿš€ 5-10x faster processing - compared to FastAPI benchmarks

Migration Test - Replace FastAPI in 30 Seconds

Want to test migration? Try this FastAPI-to-TurboAPI conversion:

# Your existing FastAPI code
# from fastapi import FastAPI  โ† Comment this out
from turboapi import TurboAPI as FastAPI  # โ† Add this line

# Everything else stays identical - same decorators, same syntax!
app = FastAPI(title="My API", version="1.0.0")

@app.get("/items/{item_id}")  # Same decorator
def read_item(item_id: int, q: str = None):  # Same parameters
    return {"item_id": item_id, "q": q}  # Same response

app.run()  # 5-10x faster performance!

๐ŸŽฏ Must-Try Demos

1. ๐Ÿ”ฅ Live Performance Showcase

python live_performance_showcase.py

Interactive server with real-time metrics showing FastAPI syntax with TurboAPI speed.

2. ๐ŸฅŠ Performance Comparison

python turbo_vs_fastapi_demo.py

Side-by-side comparison showing identical syntax with performance benchmarks.

3. ๐Ÿ“Š Comprehensive Benchmarks

python comprehensive_benchmark.py

Full benchmark suite with decorator syntax demonstrating 5-10x performance gains.

๐ŸŽ‰ Why Developers Love TurboAPI

"It's Just FastAPI, But Faster!"

# Before (FastAPI)
from fastapi import FastAPI
app = FastAPI()

@app.get("/api/heavy-task") 
def cpu_intensive():
    return sum(i*i for i in range(10000))  # Takes 3ms, handles 1,800 RPS

# After (TurboAPI) - SAME CODE!
from turboapi import TurboAPI as FastAPI  # โ† Only change needed!
app = FastAPI()

@app.get("/api/heavy-task")
def cpu_intensive():
    return sum(i*i for i in range(10000))  # Takes 0.9ms, handles 5,700+ RPS! ๐Ÿš€

Real-World Impact

  • ๐Ÿข Enterprise APIs: Serve 5-10x more users with same infrastructure
  • ๐Ÿ’ฐ Cost Savings: 80% reduction in server costs
  • โšก User Experience: Sub-millisecond response times
  • ๐Ÿ›ก๏ธ Reliability: Rust memory safety + Python productivity
  • ๐Ÿ“ˆ Scalability: True parallelism ready for Python 3.13+

Migration Stories (Simulated Results)

๐Ÿ“Š E-commerce API Migration:
   Before: 2,000 RPS โ†’ After: 12,000+ RPS
   Migration time: 45 minutes
   
๐Ÿ“Š Banking API Migration:  
   Before: P95 latency 5ms โ†’ After: P95 latency 1.2ms
   Compliance: โœ… Same Python code, Rust safety
   
๐Ÿ“Š Gaming API Migration:
   Before: 500 concurrent users โ†’ After: 3,000+ concurrent users  
   Real-time performance: โœ… Sub-millisecond responses

โšก Quick Start

Installation

Option 1: Install from PyPI (Recommended)

# Install Python 3.13 free-threading for optimal performance
# macOS/Linux users can use pyenv or uv

# Create free-threading environment
python3.13t -m venv turbo-env
source turbo-env/bin/activate  # On Windows: turbo-env\Scripts\activate

# Install TurboAPI (includes prebuilt wheels for macOS and Linux)
pip install turboapi

# Verify installation
python -c "from turboapi import TurboAPI; print('โœ… TurboAPI v0.4.13 ready!')"

Option 2: Build from Source

# Clone repository
git clone https://github.com/justrach/turboAPI.git
cd turboAPI

# Create Python 3.13 free-threading environment
python3.13t -m venv turbo-freethreaded
source turbo-freethreaded/bin/activate

# Install Python package
pip install -e python/

# Build Rust core for maximum performance
pip install maturin
maturin develop --manifest-path Cargo.toml

# Verify installation
python -c "from turboapi import TurboAPI; print('โœ… TurboAPI ready!')"```

**Note**: Free-threading wheels (cp313t) available for macOS and Linux. Windows uses standard Python 3.13.

#### **Advanced Features (Same as FastAPI)**
```python
from turboapi import TurboAPI
import time

app = TurboAPI()

# Path parameters
@app.get("/users/{user_id}")
def get_user(user_id: int):
    return {"user_id": user_id, "name": f"User {user_id}"}

# Query parameters  
@app.get("/search")
def search_items(q: str, limit: int = 10):
    return {"query": q, "limit": limit, "results": [f"item_{i}" for i in range(limit)]}

# POST with body
@app.post("/users")
def create_user(name: str, email: str):
    return {"name": name, "email": email, "created_at": time.time()}

# All HTTP methods work
@app.put("/users/{user_id}")
def update_user(user_id: int, name: str = None):
    return {"user_id": user_id, "updated_name": name}

@app.delete("/users/{user_id}")
def delete_user(user_id: int):
    return {"user_id": user_id, "deleted": True}

app.run()

๐Ÿ“š Complete Multi-Route Application

For a comprehensive example with sync/async endpoints, all HTTP methods, and advanced routing patterns, see:

examples/multi_route_app.py - Full-featured application demonstrating:

  • โœ… Sync & Async Routes - 32K+ sync RPS, 24K+ async RPS
  • โœ… Path Parameters - /users/{user_id}, /products/{category}/{id}
  • โœ… Query Parameters - /search?q=query&limit=10
  • โœ… All HTTP Methods - GET, POST, PUT, PATCH, DELETE
  • โœ… Request Bodies - JSON body parsing and validation
  • โœ… Error Handling - Custom error responses
  • โœ… Complex Routing - Nested paths and multiple parameters

Run the example:

python examples/multi_route_app.py
# Visit http://127.0.0.1:8000

Available routes in the example:

GET  /                           # Welcome message
GET  /health                     # Health check
GET  /users/{user_id}            # Get user by ID
GET  /search?q=...               # Search with query params
GET  /async/data                 # Async endpoint (24K+ RPS)
POST /users                      # Create user
PUT  /users/{user_id}            # Update user
DELETE /users/{user_id}          # Delete user
GET  /api/v1/products/{cat}/{id} # Nested parameters
GET  /stats                      # Server statistics

Performance:

  • Sync endpoints: 32,804 RPS (1.48ms latency)
  • Async endpoints: 24,240 RPS (1.98ms latency)
  • Pure Rust Async Runtime with Tokio work-stealing scheduler

๐Ÿ”’ Security & Authentication (NEW!)

TurboAPI now includes 100% FastAPI-compatible security features:

OAuth2 Authentication

from turboapi import TurboAPI
from turboapi.security import OAuth2PasswordBearer, Depends

app = TurboAPI()
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")

@app.post("/token")
def login(username: str, password: str):
    # Validate credentials
    return {"access_token": username, "token_type": "bearer"}

@app.get("/users/me")
async def get_current_user(token: str = Depends(oauth2_scheme)):
    # Decode and validate token
    return {"token": token, "user": "current_user"}

HTTP Basic Authentication

from turboapi.security import HTTPBasic, HTTPBasicCredentials
import secrets

security = HTTPBasic()

@app.get("/admin")
def admin_panel(credentials: HTTPBasicCredentials = Depends(security)):
    correct_username = secrets.compare_digest(credentials.username, "admin")
    correct_password = secrets.compare_digest(credentials.password, "secret")
    if not (correct_username and correct_password):
        raise HTTPException(status_code=401, detail="Invalid credentials")
    return {"message": "Welcome admin!"}

API Key Authentication

from turboapi.security import APIKeyHeader

api_key_header = APIKeyHeader(name="X-API-Key")

@app.get("/secure-data")
def get_secure_data(api_key: str = Depends(api_key_header)):
    if api_key != "secret-key-123":
        raise HTTPException(status_code=403, detail="Invalid API key")
    return {"data": "sensitive information"}

๐Ÿ›ก๏ธ Middleware (NEW!)

Add powerful middleware with FastAPI-compatible syntax:

CORS Middleware

from turboapi.middleware import CORSMiddleware

app.add_middleware(
    CORSMiddleware,
    allow_origins=["http://localhost:3000", "https://example.com"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
    expose_headers=["X-Custom-Header"],
    max_age=600,
)

GZip Compression

from turboapi.middleware import GZipMiddleware

app.add_middleware(GZipMiddleware, minimum_size=1000, compresslevel=9)

Rate Limiting (TurboAPI Exclusive!)

from turboapi.middleware import RateLimitMiddleware

app.add_middleware(
    RateLimitMiddleware,
    requests_per_minute=100,
    burst=20
)

Trusted Host Protection

from turboapi.middleware import TrustedHostMiddleware

app.add_middleware(
    TrustedHostMiddleware,
    allowed_hosts=["example.com", "*.example.com"]
)

Custom Middleware

import time

@app.middleware("http")
async def add_process_time_header(request, call_next):
    start_time = time.time()
    response = await call_next(request)
    process_time = time.time() - start_time
    response.headers["X-Process-Time"] = str(process_time)
    return response

Architecture

TurboAPI consists of three main components:

  1. TurboNet (Rust): High-performance HTTP server built with Hyper
  2. FFI Bridge (PyO3): Zero-copy interface between Rust and Python
  3. TurboAPI (Python): Developer-friendly framework layer
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Python App    โ”‚    โ”‚   TurboAPI       โ”‚    โ”‚   TurboNet      โ”‚
โ”‚                 โ”‚โ—„โ”€โ”€โ–บโ”‚   Framework      โ”‚โ—„โ”€โ”€โ–บโ”‚   (Rust HTTP)   โ”‚
โ”‚  Your Handlers  โ”‚    โ”‚   (Python)       โ”‚    โ”‚   Engine        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

## ๐Ÿš€ Performance

TurboAPI delivers **7.5x FastAPI middleware performance** with comprehensive Phase 5 optimizations:

### ๐Ÿ“Š **HTTP Performance (Phases 3-5)**
- **Throughput**: 4,019-7,320 RPS vs FastAPI's 1,116-2,917 RPS
- **Latency**: Sub-millisecond P95 response times (0.91-1.29ms vs 2.79-3.00ms)
- **Improvement**: **2.5-3.6x faster** across all load levels
- **Parallelism**: True multi-threading with 4 server threads
- **Memory**: Efficient Rust-based HTTP handling

### ๐Ÿ”ง **Middleware Performance (Phase 5)**
- **Average Latency**: 0.11ms vs FastAPI's 0.71ms (**6.3x faster**)
- **P95 Latency**: 0.17ms vs FastAPI's 0.78ms (**4.7x faster**)
- **Concurrent Throughput**: 22,179 req/s vs FastAPI's 2,537 req/s (**8.7x faster**)
- **Overall Middleware**: **7.5x FastAPI performance**
- **Zero Overhead**: Rust-powered middleware pipeline

### ๐ŸŒ **WebSocket Performance (Phase 4)**
- **Latency**: 0.10ms avg vs FastAPI's 0.18ms (**1.8x faster**)
- **Real-time**: Sub-millisecond response times
- **Concurrency**: Multi-client support with broadcasting
- **Memory**: Zero-copy message handling

### ๐Ÿ’พ **Zero-Copy Optimizations (Phase 4)**
- **Buffer Pooling**: Intelligent memory management (4KB/64KB/1MB pools)
- **String Interning**: Memory optimization for common paths
- **SIMD Operations**: Fast data processing and comparison
- **Memory Efficiency**: Reference counting instead of copying

### ๐Ÿ›ก๏ธ **Production Middleware (Phase 5)**
- **CORS**: Cross-origin request handling with preflight optimization
- **Rate Limiting**: Sliding window algorithm with burst protection
- **Authentication**: Multi-token support with configurable validation
- **Caching**: TTL-based response caching with intelligent invalidation
- **Compression**: GZip optimization with configurable thresholds
- **Logging**: Request/response monitoring with performance metrics

**Phase 5 Achievement**: **7.5x FastAPI middleware performance** with enterprise-grade features
**Architecture**: Most advanced Python web framework with production-ready middleware

## Development Status

TurboAPI has completed **Phase 5** with comprehensive advanced middleware support:

**โœ… Phase 0 - Foundation (COMPLETE)**
- [x] Project structure and Rust crate setup
- [x] Basic PyO3 bindings and Python package
- [x] HTTP/1.1 server implementation (1.14x FastAPI)

**โœ… Phase 1 - Routing (COMPLETE)**  
- [x] Radix trie routing system
- [x] Path parameter extraction
- [x] Method-based routing

**โœ… Phase 2 - Validation (COMPLETE)**
- [x] Satya integration for 2-7x Pydantic performance
- [x] Type-safe request/response handling
- [x] Advanced validation features (1.26x FastAPI)

**โœ… Phase 3 - Free-Threading (COMPLETE)**
- [x] Python 3.13 free-threading integration
- [x] PyO3 0.26.0 with `gil_used = false`
- [x] Multi-threaded Tokio runtime
- [x] True parallelism with 4 server threads
- [x] **2.84x FastAPI performance achieved!**

**โœ… Phase 4 - Advanced Protocols (COMPLETE)**
- [x] HTTP/2 support with server push and multiplexing
- [x] WebSocket integration with real-time communication
- [x] Zero-copy optimizations with buffer pooling
- [x] SIMD operations and string interning
- [x] **3.01x FastAPI performance achieved!**

**โœ… Phase 5 - Advanced Middleware (COMPLETE)**
- [x] Production-grade middleware pipeline system
- [x] CORS, Rate Limiting, Authentication, Logging, Compression, Caching
- [x] Priority-based middleware processing
- [x] Built-in performance monitoring and metrics
- [x] Zero-copy integration with Phase 4 optimizations
- [x] **7.5x FastAPI middleware performance**

## ๐ŸŽฏ FastAPI-like Developer Experience

### **Multi-Route Example Application**

TurboAPI provides the exact same developer experience as FastAPI:

```bash
# Test the complete FastAPI-like functionality
cd examples/multi_route_app
python demo_routes.py

Results:

๐ŸŽ‰ ROUTE DEMONSTRATION COMPLETE!
โœ… All route functions working correctly
โœ… FastAPI-like developer experience demonstrated
โœ… Production patterns validated
โฑ๏ธ Total demonstration time: 0.01s

๐ŸŽฏ Key Features Demonstrated:
   โ€ข Path parameters (/users/{id}, /products/{id})
   โ€ข Query parameters with filtering and pagination
   โ€ข Request/response models with validation
   โ€ข Authentication flows with JWT-like tokens
   โ€ข CRUD operations with proper HTTP status codes
   โ€ข Search and filtering capabilities
   โ€ข Error handling with meaningful messages

Production Features Validated

  • 15+ API endpoints with full CRUD operations
  • Authentication system with JWT-like tokens
  • Advanced filtering and search capabilities
  • Proper error handling with HTTP status codes
  • Pagination and sorting for large datasets
  • Production-ready patterns throughout

๐Ÿ”ฎ What's Next?

Phase 6: Full Integration ๐Ÿšง

Currently in development - The final phase to achieve 5-10x FastAPI overall performance:

  • โœ… Automatic Route Registration: @app.get() decorators working perfectly
  • ๐Ÿšง HTTP Server Integration: Connect middleware pipeline to server
  • ๐Ÿ”„ Multi-Protocol Support: HTTP/1.1, HTTP/2, WebSocket middleware
  • ๐ŸŽฏ Performance Validation: Achieve 5-10x FastAPI overall performance
  • ๐Ÿข Production Readiness: Complete enterprise-ready framework

Phase 6.1 Complete: Route Registration System โœ…

from turboapi import TurboAPI, APIRouter

app = TurboAPI(title="My API", version="1.0.0")

@app.get("/users/{user_id}")
async def get_user(user_id: int):
    return {"user_id": user_id, "name": "John Doe"}

@app.post("/users")
async def create_user(name: str, email: str):
    return {"message": "User created", "name": name}

# Router support
users_router = APIRouter(prefix="/api/users", tags=["users"])

@users_router.get("/")
async def list_users():
    return {"users": []}

app.include_router(users_router)

Results:

๐ŸŽฏ Phase 6 Features Demonstrated:
   โœ… FastAPI-compatible decorators (@app.get, @app.post)
   โœ… Automatic route registration
   โœ… Path parameter extraction (/items/{item_id})
   โœ… Query parameter handling
   โœ… Router inclusion with prefixes
   โœ… Event handlers (startup/shutdown)
   โœ… Request/response handling

Production Readiness

Phase 5 establishes TurboAPI as:

  • Most Advanced: Middleware system of any Python framework
  • Highest Performance: 7.5x FastAPI middleware performance
  • FastAPI Compatible: Identical developer experience proven
  • Enterprise Ready: Production-grade features and reliability
  • Future Proof: Free-threading architecture for Python 3.14+

Requirements

  • Python 3.13+ (free-threading build for no-GIL support)
  • Rust 1.70+ (for building the extension)
  • maturin (for Python-Rust integration)
  • PyO3 0.26.0+ (for free-threading compatibility)

Building from Source

# Clone the repository
git clone https://github.com/justrach/turboapiv2.git
cd turboapiv2

# Create a Python 3.13 free-threading environment
python3.13t -m venv turbo-env
source turbo-env/bin/activate

# Install dependencies
pip install maturin

# Build and install TurboAPI
maturin develop --release

๐Ÿ“Š Running Benchmarks

TurboAPI includes comprehensive benchmarking tools to verify performance claims.

โšก Benchmark Methodology

Architecture: TurboAPI uses event-driven async I/O (Tokio), not thread-per-request:

  • Single process with Tokio work-stealing scheduler
  • All CPU cores utilized (14 cores on M3 Max = ~1400% CPU usage)
  • 7,168 concurrent task capacity (512 tasks/core ร— 14 cores)
  • Async tasks (~2KB each), not OS threads (~8MB each)

Test Hardware:

  • CPU: Apple M3 Max (10 performance + 4 efficiency cores)
  • Python: 3.13t/3.14t free-threading (GIL-free)
  • Architecture: Event-driven (like nginx/Node.js), not process-per-request

Why We Don't Need Multiple Processes:

  • Tokio automatically distributes work across all cores
  • No GIL bottleneck (Python 3.13t free-threading)
  • Rust HTTP layer has zero Python overhead
  • Single process is more efficient (no IPC overhead)

See BENCHMARK_FAQ.md for detailed methodology questions.

Quick Benchmark with wrk

# Install wrk (if not already installed)
brew install wrk  # macOS
# sudo apt install wrk  # Linux

# Run the comparison benchmark
python tests/wrk_comparison.py

# Generates:
# - Console output with detailed results
# - benchmark_comparison.png (visualization)

Expected Results:

  • TurboAPI: 40,000+ req/s consistently
  • FastAPI: 3,000-8,000 req/s
  • Speedup: 5-13x depending on workload

Available Benchmark Scripts

1. wrk Comparison (Recommended)

python tests/wrk_comparison.py
  • Uses industry-standard wrk load tester
  • Tests 3 load levels (light/medium/heavy)
  • Tests 3 endpoints (/, /benchmark/simple, /benchmark/json)
  • Generates PNG visualization
  • Most accurate performance measurements

2. Adaptive Rate Testing

python tests/benchmark_comparison.py
  • Finds maximum sustainable rate
  • Progressive rate testing
  • Python-based request testing

3. Quick Verification

python tests/quick_test.py
  • Fast sanity check
  • Verifies rate limiting is disabled
  • Tests basic functionality

Benchmark Configuration

Ports:

  • TurboAPI: http://127.0.0.1:8080
  • FastAPI: http://127.0.0.1:8081

Rate Limiting: Disabled by default for benchmarking

from turboapi import TurboAPI
app = TurboAPI()
app.configure_rate_limiting(enabled=False)  # For benchmarking

**Multi-threading**: Automatically uses all CPU cores
```python
import os
workers = os.cpu_count()  # e.g., 14 cores on M3 Max

Interpreting Results

Key Metrics:

  • RPS (Requests/second): Higher is better
  • Latency: Lower is better (p50, p95, p99)
  • Speedup: TurboAPI RPS / FastAPI RPS

Expected Performance:

Light Load (50 conn):     40,000+ RPS, ~1-2ms latency
Medium Load (200 conn):   40,000+ RPS, ~4-5ms latency  
Heavy Load (500 conn):    40,000+ RPS, ~11-12ms latency

Why TurboAPI is Faster:

  1. Rust HTTP core - No Python overhead
  2. Zero-copy operations - Direct memory access
  3. Free-threading - True parallelism (no GIL)
  4. Optimized middleware - Rust-native pipeline

Testing & Quality Assurance

TurboAPI includes comprehensive testing and continuous benchmarking:

Comprehensive Test Suite

# Run full test suite
python test_turboapi_comprehensive.py

# Run specific middleware tests
python test_simple_middleware.py

# Run performance benchmarks
python benchmarks/middleware_vs_fastapi_benchmark.py
python benchmarks/final_middleware_showcase.py

Continuous Integration

Our GitHub Actions workflow automatically:

  • โœ… Builds and tests on every commit
  • โœ… Runs performance benchmarks vs FastAPI
  • โœ… Detects performance regressions with historical comparison
  • โœ… Updates performance dashboard with latest results
  • โœ… Comments on PRs with benchmark results

Performance Regression Detection

# Check for performance regressions
python .github/scripts/check_performance_regression.py

# Compare with historical benchmarks
python .github/scripts/compare_benchmarks.py

The CI system maintains performance baselines and alerts on:

  • 15%+ latency increases
  • 10%+ throughput decreases
  • 5%+ success rate drops
  • Major architectural regressions

Contributing

TurboAPI is in active development! We welcome contributions:

  1. Check out the execution plan
  2. Pick a task from the current phase
  3. Submit a PR with tests and documentation

License

MIT License - see LICENSE for details.

Acknowledgments

  • FastAPI for API design inspiration
  • Rust HTTP ecosystem (Hyper, Tokio, PyO3)
  • Python 3.14 no-GIL development team

Ready to go fast? ๐Ÿš€ Try TurboAPI today!

About

TurboAPI: Lightning-Fast ASGI Framework with FastAPI-Compatible Syntax

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages