This document provides a high-level introduction to TurboAPI, a FastAPI-compatible Python web framework that achieves 1.3-3.1x performance improvements (and up to 7x in specific benchmarks) by replacing the Python HTTP stack with a high-performance Zig core. It explains the system's purpose, the hybrid architecture, and how performance optimization is achieved without modifying user code.
For detailed information about specific subsystems, see: Key Features and Benefits and Installation and Quick Start.
TurboAPI is a Python web framework that maintains high API compatibility with FastAPI while replacing performance-critical components—HTTP parsing, routing, and JSON validation—with native Zig implementations. Applications written for FastAPI can often migrate by changing the main application import:
The system consists of three primary layers:
| Layer | Technology | Purpose |
|---|---|---|
| Python Framework | Python 3.13+ | Application logic, decorators, and dependency injection. |
| Integration Bridge | Python C-API (Zig) | Zero-copy marshaling and async handler dispatch. |
| Zig Core | turbonet | Multi-threaded HTTP server, Radix tree routing, and std.json parsing. |
Sources: README.md14-84 python/turboapi/__init__.py1-57
TurboAPI moves the "heavy lifting" out of the Python interpreter. While FastAPI processes every request through multiple Python layers (Uvicorn → ASGI → Starlette), TurboAPI handles the entire lifecycle up to the business logic in Zig.
The following diagram maps the request flow to concrete code entities in both Zig and Python spaces:
Sources: README.md127-164 python/turboapi/native_integration.py1-45
turbonet): Manages an 8-thread pool, performs Radix tree route matching, and executes JSON schema validation via the dhi library before the Python GIL is even acquired README.md39-46json.loads() README.md40-42APIRouter, Depends, and security schemes like OAuth2PasswordBearer python/turboapi/__init__.py59-72TurboAPI targets the overhead of the Python Global Interpreter Lock (GIL) and slow JSON processing. By using Python 3.13+ free-threading support, it enables true parallelism.
Based on wrk testing on Apple Silicon with Python 3.14t:
| Endpoint | TurboAPI | FastAPI | Speedup |
|---|---|---|---|
GET / | 71,290 | 10,038 | 7.1x |
GET /items/{id} | 65,266 | 8,666 | 7.5x |
POST /items (JSON) | 59,595 | 8,200 | 7.2x |
Sources: README.md90-112 tests/test_performance_regression.py6-11
PyUnicode_AsUTF8() to get a direct pointer to Python string data, writing it straight to the socket without intermediate allocations README.md166-171dhi models (a Zig-native Pydantic replacement), validation happens in the Zig core. If a request body is invalid, a 422 error is returned without ever waking up the Python interpreter README.md113-115simple_sync, model_sync, body_async). Simple routes bypass complex Python wrappers to reduce latency socials/twitter.md41-53The following table bridges the conceptual systems to their primary code locations:
| System | Code Entity | File Path |
|---|---|---|
| Core Application | TurboAPI class | python/turboapi/native_integration.py44 |
| Data Models | dhi.BaseModel | python/turboapi/native_integration.py62 |
| Routing | APIRouter / Router | python/turboapi/routing.py56 |
| Server-Sent Events | EventSourceResponse | python/turboapi/sse.py62 |
| Extension Build | build_turbonet.py | zig/build_turbonet.py1-50 |
Sources: python/turboapi/__init__.py43-81 python/turboapi/sse.py62-101