Skip to main content

FastAPI-compatible web framework with Rust HTTP core - 2-3x faster with Python 3.13 free-threading

Project description

TurboAPI Architecture

TurboAPI

The FastAPI you know. The speed you deserve.

The ProblemThe SolutionQuick StartBenchmarksMigration Guide


The Problem

You love FastAPI. The clean syntax. The automatic validation. The beautiful docs. But then you deploy to production, and the reality hits:

"Why is my simple API only handling 8,000 requests per second?"

You've optimized your database queries. Added caching. Switched to async. Still not fast enough. The bottleneck isn't your code—it's the framework itself.

Python's GIL (Global Interpreter Lock) means only one thread executes Python code at a time. JSON serialization happens in pure Python. HTTP parsing happens in pure Python. Every microsecond adds up.

The Solution

TurboAPI is FastAPI with a Rust-powered engine. Same API. Same syntax. 2-3x faster.

# This is all you change
from turboapi import TurboAPI as FastAPI

Everything else stays exactly the same.

TurboAPI Speedup

Why It's Faster

What FastAPI Does What TurboAPI Does Speedup
HTTP parsing in Python HTTP parsing in Rust (Hyper/Tokio) 3x
JSON with json.dumps() JSON with SIMD-accelerated Rust 2x
GIL-bound threading Python 3.13 free-threading 2x
dict-based routing Radix tree with O(log n) lookup 1.5x

The result? Your existing FastAPI code runs faster without changing a single line of business logic.


Quick Start

Installation

pip install turboapi

Requirements: Python 3.13+ (free-threading recommended for best performance)

Hello World

from turboapi import TurboAPI

app = TurboAPI()

@app.get("/")
def hello():
    return {"message": "Hello World"}

app.run()

That's it. Your first TurboAPI server is running at http://localhost:8000.

For Maximum Performance

Run with Python's free-threading mode:

PYTHON_GIL=0 python app.py

This unlocks the full power of TurboAPI's Rust core by removing the GIL bottleneck.


Benchmarks

Real numbers matter. Here's TurboAPI vs FastAPI on identical hardware:

Throughput Comparison

Throughput (requests/second)

Endpoint TurboAPI FastAPI Speedup
GET / (hello world) 19,596 8,336 2.4x
GET /json (object) 20,592 7,882 2.6x
GET /users/{id} (path params) 18,428 7,344 2.5x
POST /items (model validation) 19,255 6,312 3.1x
GET /status201 (custom status) 15,698 8,608 1.8x

Latency (lower is better)

Latency Comparison

Endpoint TurboAPI (avg/p99) FastAPI (avg/p99)
GET / 5.1ms / 11.6ms 12.0ms / 18.6ms
GET /json 4.9ms / 11.8ms 12.7ms / 17.6ms
POST /items 5.3ms / 13.1ms 16.2ms / 43.9ms

Benchmarked with wrk, 4 threads, 100 connections, 10 seconds. Python 3.13t free-threading mode.

Run Your Own Benchmarks

# Install wrk (macOS)
brew install wrk

# Run the benchmark suite
pip install matplotlib  # for charts
PYTHON_GIL=0 python benchmarks/run_benchmarks.py

# Generate charts
python benchmarks/generate_charts.py

Migration Guide

TurboAPI is designed as a drop-in replacement for FastAPI. Here's how to migrate:

Step 1: Change Your Imports

# Before (FastAPI)
from fastapi import FastAPI, Depends, HTTPException, Query, Path
from fastapi.responses import JSONResponse, HTMLResponse
from fastapi.middleware.cors import CORSMiddleware

# After (TurboAPI)
from turboapi import TurboAPI as FastAPI, Depends, HTTPException, Query, Path
from turboapi.responses import JSONResponse, HTMLResponse
from turboapi.middleware import CORSMiddleware

Step 2: Update Your Models

TurboAPI uses dhi instead of Pydantic (it's API-compatible):

# Before (Pydantic)
from pydantic import BaseModel

# After (dhi)
from dhi import BaseModel

Step 3: Run Your App

# FastAPI way still works
if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

# Or use TurboAPI's built-in server (faster)
if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)

That's it. Your FastAPI app is now a TurboAPI app.


Feature Parity

Everything you use in FastAPI works in TurboAPI:

Feature Status Notes
Route decorators (@get, @post, etc.) Full parity
Path parameters With type coercion
Query parameters With validation
Request body (JSON) SIMD-accelerated
Response models Full support
Dependency injection Depends() with caching
OAuth2 authentication Password & AuthCode flows
HTTP Basic/Bearer auth Full implementation
API Key auth Header/Query/Cookie
CORS middleware Rust-accelerated
GZip middleware Configurable
Background tasks Async-compatible
WebSocket Basic support
APIRouter Prefixes and tags
HTTPException With custom headers
Custom responses JSON, HTML, Redirect, etc.

Real-World Examples

API with Authentication

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

app = TurboAPI(title="My API", version="1.0.0")
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")

@app.get("/users/me")
def get_current_user(token: str = Depends(oauth2_scheme)):
    if token != "secret-token":
        raise HTTPException(status_code=401, detail="Invalid token")
    return {"user": "authenticated", "token": token}

Request Validation

from dhi import BaseModel, Field
from typing import Optional

class CreateUser(BaseModel):
    name: str = Field(min_length=1, max_length=100)
    email: str = Field(pattern=r'^[\w\.-]+@[\w\.-]+\.\w+$')
    age: Optional[int] = Field(default=None, ge=0, le=150)

@app.post("/users")
def create_user(user: CreateUser):
    return {"created": True, "user": user.model_dump()}

CORS and Middleware

from turboapi.middleware import CORSMiddleware, GZipMiddleware

app.add_middleware(
    CORSMiddleware,
    allow_origins=["https://yourapp.com"],
    allow_methods=["*"],
    allow_headers=["*"],
)

app.add_middleware(GZipMiddleware, minimum_size=1000)

API Router

from turboapi import APIRouter

router = APIRouter(prefix="/api/v1", tags=["users"])

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

@router.get("/users/{user_id}")
def get_user(user_id: int):
    return {"user_id": user_id}

app.include_router(router)

How It Works

TurboAPI's secret is a hybrid architecture:

┌──────────────────────────────────────────────────────┐
│              Your Python Application                  │
│         (exactly like FastAPI code)                   │
├──────────────────────────────────────────────────────┤
│       TurboAPI (FastAPI-compatible layer)            │
│    Routing • Validation • Dependency Injection        │
├──────────────────────────────────────────────────────┤
│          PyO3 Bridge (zero-copy)                     │
│     Rust ↔ Python with minimal overhead               │
├──────────────────────────────────────────────────────┤
│          TurboNet (Rust HTTP Core)                   │
│  • Hyper + Tokio async runtime                       │
│  • SIMD-accelerated JSON (simd-json)                 │
│  • Radix tree routing                                │
│  • Zero-copy response buffers                        │
└──────────────────────────────────────────────────────┘

Python handles the logic you care about. Routes, validation rules, business logic—all in Python.

Rust handles the heavy lifting. HTTP parsing, JSON serialization, connection management—the parts that need to be fast.

The result: FastAPI's developer experience with systems-level performance.


Building from Source

Want to contribute or build from source?

git clone https://github.com/justrach/turboAPI.git
cd turboAPI

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

# Build the Rust extension
pip install maturin
maturin develop --release

# Install Python package
pip install -e ./python

# Run tests
PYTHON_GIL=0 python -m pytest tests/ -v

Roadmap

Completed ✅

  • Rust HTTP core (Hyper/Tokio)
  • SIMD JSON serialization & parsing
  • Python 3.13 free-threading support
  • FastAPI feature parity (OAuth2, Depends, Middleware)
  • Radix tree routing with path parameters
  • Handler classification for optimized fast paths

In Progress 🚧

  • Async handler optimization (pure Tokio)
  • WebSocket performance improvements
  • HTTP/2 with server push

Planned 📋

  • OpenAPI/Swagger auto-generation
  • GraphQL support
  • Database connection pooling
  • Prometheus metrics
  • Distributed tracing

Community


License

MIT License. Use it, modify it, ship it.


Stop waiting for Python to be fast. Make it fast.

pip install turboapi

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

turboapi-0.4.16.tar.gz (1.0 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

turboapi-0.4.16-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64

turboapi-0.4.16-cp314-cp314-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.14Windows x86-64

turboapi-0.4.16-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

turboapi-0.4.16-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

turboapi-0.4.16-cp314-cp314-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

turboapi-0.4.16-cp314-cp314-macosx_10_12_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

turboapi-0.4.16-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ ARM64

turboapi-0.4.16-cp313-cp313-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.13Windows x86-64

turboapi-0.4.16-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

turboapi-0.4.16-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

turboapi-0.4.16-cp313-cp313-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

turboapi-0.4.16-cp313-cp313-macosx_10_12_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

File details

Details for the file turboapi-0.4.16.tar.gz.

File metadata

  • Download URL: turboapi-0.4.16.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for turboapi-0.4.16.tar.gz
Algorithm Hash digest
SHA256 0d90916b3479091e13c6802ee2dc6649b15b48f80118496078b8ea2f9b2a83a9
MD5 848dc3f08a92350f81d0cd8c0606ace5
BLAKE2b-256 e75420a99cba086a65013974084d9b94e2db7184d1fba7972080d8a231e2e0d9

See more details on using hashes here.

File details

Details for the file turboapi-0.4.16-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for turboapi-0.4.16-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 53cccfc8bc5a887c9b02d433c94c80f31f797f9437ca80458853ae7e0394c97f
MD5 335ea8a14baf7dc262870fee7560b613
BLAKE2b-256 5040c99269323da8cdbabbc9ecdca4d1ebf27443974d3872260726bf8f8f1e56

See more details on using hashes here.

File details

Details for the file turboapi-0.4.16-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: turboapi-0.4.16-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for turboapi-0.4.16-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 9ec60c69de745c6eccbc5fd9540d4a6007d6d99ad0d46558f8b90dd1620b9cd8
MD5 2cc576805e58897a1c9b9e973c9ecd73
BLAKE2b-256 a3b4e8b3a9082e675fb300aeec9cfda00524f50490f0c6506866e4ad0d98f5b6

See more details on using hashes here.

File details

Details for the file turboapi-0.4.16-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for turboapi-0.4.16-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 45ee3d0c29a0c2baa4900bf098f740e6cdb86bcd09bf412e918b677c6a080c0e
MD5 1b3b4003586dffbe59dcab375b0b2160
BLAKE2b-256 4158c1171ae335588a885cc542e47febea3f4ec9651f0129ca639e63f40f2bca

See more details on using hashes here.

File details

Details for the file turboapi-0.4.16-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for turboapi-0.4.16-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 de610e236ba83c3e5ed0af5f61b4846df1792219d3798b3a6e72040e8e1ae4d6
MD5 0cf8c99d153b4a9e0ea6568db8ffeed6
BLAKE2b-256 d5146b0a59c3c54a5e90e2ddb661417c276021db01ae3ecb73e6bfbcbc532ad2

See more details on using hashes here.

File details

Details for the file turboapi-0.4.16-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for turboapi-0.4.16-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e4f2d392b8b4ded2352c987b0ac183b101d7c8ebb74b51ca1fcce6c4f9624631
MD5 23fbc0e01bfbf6fea5f302a77f12b40a
BLAKE2b-256 23210f4deab4113b2c240a7d030771807a82f424d03b38ae49bb492c045ff384

See more details on using hashes here.

File details

Details for the file turboapi-0.4.16-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for turboapi-0.4.16-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3271d56cfcd7a7b0bd877bbe218014f040acca240bfe7ec87f1448dc242a4a97
MD5 788dcb6009d642d7aa61584b8e2a6c0b
BLAKE2b-256 90a1d33a9543587785cb2b6431261d77eb8f52deef32bf0b1351d80a3a04a666

See more details on using hashes here.

File details

Details for the file turboapi-0.4.16-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for turboapi-0.4.16-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f6cdb54673ffce3adabced0824f03826048b840fe9eb48b149826c6a7db4cb16
MD5 b405bcf26da22d8e8b72337616959fc2
BLAKE2b-256 b1effa8debc314afa14d8aa6f091012f0ac5a343b191404820b57e074604278b

See more details on using hashes here.

File details

Details for the file turboapi-0.4.16-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: turboapi-0.4.16-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for turboapi-0.4.16-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c7c1d67ddc212dbe959736389b9816ad60dceed90c43ba286b82943d8b072daa
MD5 e8691b497b84d35b09ea646957f90707
BLAKE2b-256 33636a63e3e9b74c13511833aabdb8790f7e30b151b4619f04a9ba7733e55901

See more details on using hashes here.

File details

Details for the file turboapi-0.4.16-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for turboapi-0.4.16-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cc055cca05cb7df94b9827d200c640f004e694195fff8258db59e0dfb60ce78a
MD5 b39040858215c2de84f1ebd5aff646f0
BLAKE2b-256 ad5739cb501b9328bc2c51c49c87d4495729f8cc8c16546cfff2ac15f521bb18

See more details on using hashes here.

File details

Details for the file turboapi-0.4.16-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for turboapi-0.4.16-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9167e8a146cf82a6d46610cd2e06eca38870cf2a9ec9e0eb93f2ddd789c92304
MD5 5332f0b68af47f7b1605bfd790aa8111
BLAKE2b-256 d20f3b7743b18f9caef14d865bdee9b1f476239a349b3718c60168c3dce8d907

See more details on using hashes here.

File details

Details for the file turboapi-0.4.16-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for turboapi-0.4.16-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4f87ce8fa8b5bfa497ff9e04701d8cb0255ddc0c9bc610a0dc1189d3c7f642c7
MD5 662b105b00f20e251dfb9a5b28d1dae5
BLAKE2b-256 c103a960c8f99db0939aabb7ee556eb6f130daffe62291285651cc9a26bb2b57

See more details on using hashes here.

File details

Details for the file turboapi-0.4.16-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for turboapi-0.4.16-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b39edda6ae6c4f305f775c22a0b90828e5f624249742dfd33dffa204c0ebebcb
MD5 f4eb92998433a85d45d4db169b8f96dc
BLAKE2b-256 f181dcdd43deb312a637be3f0defee66b74238de1ee1f885f041593fa8cbbcc5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page