A lightweight, FastAPI-inspired web framework
Project description
🚀 Tachyon API
A lightweight, high-performance API framework for Python with the elegance of FastAPI and the speed of light.
Tachyon API combines the intuitive decorator-based syntax you love with minimal dependencies and maximal performance. Built with Test-Driven Development from the ground up, it offers a cleaner, faster alternative with full ASGI compatibility.
🚀 Quick Start
from tachyon_api import Tachyon, Struct, Body, Query
app = Tachyon()
class User(Struct):
name: str
email: str
@app.get("/")
def hello():
return {"message": "Tachyon is running at lightspeed!"}
@app.post("/users")
def create_user(user: User = Body()):
return {"created": user.name}
@app.get("/search")
def search(q: str = Query(...), limit: int = Query(10)):
return {"query": q, "limit": limit}
pip install tachyon-api
uvicorn app:app --reload
📖 Docs: http://localhost:8000/docs
⚡ Performance
Benchmarked against FastAPI 0.136.1 (Pydantic v2) · 1 worker · 100 concurrent connections · uvloop + httptools
| Scenario | FastAPI | Tachyon | Speedup |
|---|---|---|---|
| Hello World | 10,159 req/s | 52,321 req/s | 5.15x |
| Path + query params | 6,930 req/s | 37,384 req/s | 5.39x |
| Body validation (Struct) | 8,189 req/s | 36,593 req/s | 4.47x |
| Nested body (complex Struct) | 7,888 req/s | 38,522 req/s | 4.88x |
| Response model serialization | 6,370 req/s | 44,557 req/s | 6.99x |
| Header param + auth | 7,894 req/s | 45,727 req/s | 5.79x |
| Dependency injection | 6,284 req/s | 46,592 req/s | 7.41x |
| Multiple query params | 6,161 req/s | 33,930 req/s | 5.51x |
| Total throughput | 59,875 req/s | 335,626 req/s | 5.61x |
Latency: ~2.1ms (Tachyon) vs ~14ms (FastAPI) on average.
Benchmark code in
benchmark/. Run withbash benchmark/run_benchmark.sh.
Optional: Cython compilation
Install with Cython extensions for additional speedup on the request hot path:
pip install tachyon-api[fast] # installs cython dependency
python setup.py build_ext --inplace # compile extensions (required step)
Note:
pip install tachyon-api[fast]installs thecythonpackage but does not auto-compile the extensions. Runpython setup.py build_ext --inplacemanually after install. Falls back to pure Python automatically when.sois not present — no code changes needed. Numbers above reflect the compiled version (~11% faster Python hot path).
Why is Tachyon faster?
- Radix trie routing — O(k) path matching vs Starlette's O(N×regex) scan; trie compiled to C
- Middleware bypass — HTTP requests skip Starlette's
ServerErrorMiddlewareandExceptionMiddlewareentirely; exceptions handled directly in each closure - Endpoint pre-compilation —
inspect.signature(),isinstancechains, type resolution, andmsgspec.Decodercreation run once at startup, not per request - No-Request fast path — endpoints with no parameters skip
Request()creation and call the ASGI handler directly - msgspec — validation and deserialization in C, 5–10x faster than Pydantic
- Direct serialization —
Structresponses usemsgspec.json.encode()directly (no Python intermediate step) - Pre-built ASGI dicts — response send payloads constructed once in
__init__, not recreated per request - No middleware bloat — Tachyon mounts only what you register; FastAPI adds ~15 middlewares by default
✨ Features
| Category | Features |
|---|---|
| Core | Decorators API, Routers, Middlewares, ASGI compatible |
| Parameters | Path, Query, Body, Header, Cookie, Form, File (all with alias=) |
| Validation | msgspec Struct (ultra-fast), automatic 422 errors, body size limit |
| DI | @injectable (implicit), Depends() (explicit), circular dep detection |
| Security | HTTPBearer, HTTPBasic, OAuth2, API Keys |
| Async | Background Tasks, WebSockets |
| Performance | orjson serialization, @cache decorator, endpoint pre-compilation |
| Docs | OpenAPI 3.0, Scalar UI, Swagger, ReDoc (XSS-safe HTML generation) |
| CLI | Project scaffolding, code generation, linting |
| Testing | TachyonTestClient, dependency_overrides |
📚 Documentation
| Guide | Description |
|---|---|
| Getting Started | Installation and first project |
| Architecture | Clean architecture patterns |
| Dependency Injection | @injectable and Depends() |
| Parameters | Path, Query, Body, Header, Cookie, Form, File |
| Validation | msgspec Struct validation |
| Security | JWT, Basic, OAuth2, API Keys |
| Caching | @cache decorator |
| Lifecycle Events | Startup/Shutdown |
| Background Tasks | Async task processing |
| WebSockets | Real-time communication |
| Testing | TachyonTestClient |
| CLI Tools | Scaffolding and generation |
| Request Lifecycle | How requests are processed |
| Migration from FastAPI | Migration guide |
| Best Practices | Recommended patterns |
🏦 Example: KYC Demo API
A complete example demonstrating all Tachyon features is available in example/:
cd example
pip install -r requirements.txt
uvicorn example.app:app --reload
The KYC Demo implements:
- 🔐 JWT Authentication
- 👤 Customer CRUD
- 📋 KYC Verification with Background Tasks
- 📁 Document Uploads
- 🌐 WebSocket Notifications
- 🧪 12 Tests with Mocks
Demo credentials: demo@example.com / demo123
👉 See example/README.md for full details.
🔌 Core Dependencies
| Package | Purpose |
|---|---|
starlette |
ASGI framework |
msgspec |
Ultra-fast validation/serialization |
orjson |
High-performance JSON |
uvicorn |
ASGI server |
💉 Dependency Injection
from tachyon_api import injectable, Depends
@injectable
class UserService:
def get_user(self, id: str):
return {"id": id}
@app.get("/users/{id}")
def get_user(id: str, service: UserService = Depends()):
return service.get_user(id)
🔐 Security
from tachyon_api.security import HTTPBearer, OAuth2PasswordBearer
bearer = HTTPBearer()
@app.get("/protected")
async def protected(credentials = Depends(bearer)):
return {"token": credentials.credentials}
⚡ Background Tasks
from tachyon_api.background import BackgroundTasks
@app.post("/notify")
def notify(background_tasks: BackgroundTasks):
background_tasks.add_task(send_email, "user@example.com")
return {"status": "queued"}
👉 Full Background Tasks documentation
🌐 WebSockets
@app.websocket("/ws")
async def websocket(ws):
await ws.accept()
data = await ws.receive_text()
await ws.send_text(f"Echo: {data}")
👉 Full WebSockets documentation
🔧 CLI Tools
# Create new project
tachyon new my-api
# Generate module
tachyon generate service users --crud
# Code quality
tachyon lint all
🧪 Testing
from tachyon_api.testing import TachyonTestClient
def test_hello():
client = TachyonTestClient(app)
response = client.get("/")
assert response.status_code == 200
pytest tests/ -v
📊 Why Tachyon?
| Feature | Tachyon | FastAPI |
|---|---|---|
| Throughput | ~336k req/s total | ~60k req/s total |
| Latency | ~2.1ms avg | ~14ms avg |
| Routing | Radix trie O(k) | Regex scan O(N) |
| Serialization | msgspec + orjson | Pydantic v2 |
| Request compilation | Once at startup | Per request |
| Middleware overhead | User-only stack | +2 auto middleware layers |
| Bundle size | Minimal (4 deps) | Larger (~15 deps) |
| Learning curve | Easy (FastAPI-like) | Easy |
| Type safety | Full (msgspec Struct) | Full (Pydantic) |
📝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Run tests (
pytest tests/ -v) - Commit your changes
- Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📜 License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
🔮 What's Next
See CHANGELOG.md for version history.
Upcoming:
- Response streaming
- GraphQL support
- Multi-worker benchmarks
Built with 💜 by developers, for developers
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tachyon_api-1.1.0.tar.gz.
File metadata
- Download URL: tachyon_api-1.1.0.tar.gz
- Upload date:
- Size: 47.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a75ac280a0c6fb4defedb5b190687b0ce7ef0461b7ee61a44018586346dd0c2d
|
|
| MD5 |
150f1ff2541118f125f8548b4066ab3a
|
|
| BLAKE2b-256 |
2deb7861de5bb5640a7532d5b2f3de36dfb24c77c3b99d2e03fc70aa9d3bbbd9
|
File details
Details for the file tachyon_api-1.1.0-py3-none-any.whl.
File metadata
- Download URL: tachyon_api-1.1.0-py3-none-any.whl
- Upload date:
- Size: 62.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48836ca70a8a553d05f1067f641e1da0be717165bfdd76b4e30ae33d651b5c13
|
|
| MD5 |
9477ec2a7634a6dbc1d529dc0aea4112
|
|
| BLAKE2b-256 |
aa3860b1480e4a6733c66cfab1a311a6c4dd79ef78b71292d43ef079d03294d7
|