Skip to main content

A lightweight, FastAPI-inspired web framework

Project description

🚀 Tachyon API

Version Python License Status

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.

from tachyon_api import Tachyon
from tachyon_api.models import Struct

app = Tachyon()

class User(Struct):
    name: str
    age: int

@app.get("/")
def hello_world():
    return {"message": "Tachyon is running at lightspeed!"}

@app.post("/users")
def create_user(user: User):
    return {"created": user.name}

✨ Features

  • 🔍 Intuitive API - Elegant decorator-based routing inspired by FastAPI
  • 🧩 Implicit & Explicit Dependency Injection - Both supported for maximum flexibility
  • 📚 Automatic OpenAPI Documentation - With Scalar UI, Swagger UI, and ReDoc support
  • 🛠️ Router System - Organize your API endpoints with powerful route grouping
  • 🧪 Built with TDD - Comprehensive test suite ensures stability and correctness
  • 🔄 Middleware Support - Both class-based and decorator-based approaches
  • 🚀 High-Performance JSON - Powered by msgspec and orjson for lightning-fast processing
  • 🪶 Minimal Dependencies - Lean core with only what you really need

📦 Installation

Tachyon API is currently in beta. The package will be available on PyPI and Poetry repositories soon!

From source (Currently the only method)

git clone https://github.com/jmpanozzoz/tachyon_api.git
cd tachyon-api
pip install -r requirements.txt

Note: The pip install tachyon-api and poetry add tachyon-api commands will be available once the package is published to PyPI.

🔍 Key Differences from FastAPI

While inspired by FastAPI's elegant API design, Tachyon API takes a different approach in several key areas:

Feature Tachyon API FastAPI
Core Dependencies Minimalist: Starlette + msgspec + orjson Pydantic + multiple dependencies
Validation Engine msgspec (faster, lighter) Pydantic (more features, heavier)
Dependency Injection Both implicit and explicit Primarily explicit
Middleware Approach Dual API (class + decorator) Class-based
Development Approach Test-Driven from the start Feature-driven
Documentation UI Scalar UI (default), Swagger, ReDoc Swagger UI (default), ReDoc
Size Lightweight, focused Comprehensive, full-featured

🧪 Test-Driven Development

Tachyon API is built with TDD principles at its core:

  • Every feature starts with a test
  • Comprehensive test coverage
  • Self-contained test architecture
  • Clear test documentation

This ensures stability, maintainability, and prevents regressions as the framework evolves.

🔌 Core Dependencies

Tachyon API maintains a minimal, carefully selected set of dependencies:

  • Starlette: ASGI framework providing solid foundations
  • msgspec: Ultra-fast serialization and validation
  • orjson: High-performance JSON parser
  • uvicorn: ASGI server for development and production

These were chosen for their performance, lightweight nature, and focused functionality.

💉 Dependency Injection System

Tachyon API offers a flexible dependency injection system:

Implicit Injection

@injectable
class UserService:
    def __init__(self, repository: UserRepository):  # Auto-injected!
        self.repository = repository

@app.get("/users/{user_id}")
def get_user(user_id: int, service: UserService):  # Auto-injected!
    return service.get_user(user_id)

Explicit Injection

@app.get("/users/{user_id}")
def get_user(user_id: int, service: UserService = Depends()):
    return service.get_user(user_id)

🔄 Middleware Support

Tachyon API supports middlewares in two elegant ways:

Class-based Approach

from tachyon_api.middlewares import CORSMiddleware, LoggerMiddleware

# Add built-in CORS middleware
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
    allow_credentials=False,
)

# Add built-in Logger middleware
app.add_middleware(
    LoggerMiddleware,
    include_headers=True,
    redact_headers=["authorization"],
)

Decorator-based Approach

@app.middleware()
async def timing_middleware(scope, receive, send, app):
    start_time = time.time()
    await app(scope, receive, send)
    print(f"Request took {time.time() - start_time:.4f}s")

Built-in Middlewares

  • CORSMiddleware: Handles preflight requests and injects CORS headers into responses. Highly configurable with allow_origins, allow_methods, allow_headers, allow_credentials, expose_headers, and max_age.
  • LoggerMiddleware: Logs request start/end, duration, status code, and optionally headers and a non-intrusive body preview.

Both middlewares are standard ASGI middlewares and can be used with app.add_middleware(...).

📚 Example Application

For a complete example showcasing all features, see the example directory. It demonstrates:

  • Clean architecture with models, services, and repositories
  • Router organization
  • Middleware implementation
  • Dependency injection patterns
  • OpenAPI documentation

Built-in CORS and Logger middlewares are integrated in the example for convenience. You can toggle settings in example/app.py.

Run the example with:

cd example
python app.py

Then visit:

📝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📜 License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

🔮 Roadmap

  • Exception System: Standardized exception handling and error responses
  • Environment Management: Built-in environment variable handling and uvicorn integration
  • CLI Tool: Project scaffolding and service generation
    • Directory structure generation
    • Service and repository templates
    • API endpoint generation
  • Code Quality Tools: Ruff integration for linting and formatting
  • Performance Optimization: Cython compilation for service layer via CLI
  • Authentication Middleware: Built-in auth patterns and middleware
  • Performance Benchmarks: Comparisons against other frameworks
  • More Example Applications: Demonstrating different use cases
  • Plugin System: Extensibility through plugins
  • Deployment Guides: Documentation for various deployment scenarios
  • And much more!

Built with 💜 by developers, for developers

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

tachyon_api-0.5.5.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

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

tachyon_api-0.5.5-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file tachyon_api-0.5.5.tar.gz.

File metadata

  • Download URL: tachyon_api-0.5.5.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tachyon_api-0.5.5.tar.gz
Algorithm Hash digest
SHA256 262837a7ec26ed6b7d3a0526037eebb6045dbb9e29354783cd253af2943345a4
MD5 e2e800b9ba12aa3c3e230f9574f6378a
BLAKE2b-256 c5e3b637dd5c4a8e41e84657c765bc928d548e4ccd198fb603981636baca1cfd

See more details on using hashes here.

File details

Details for the file tachyon_api-0.5.5-py3-none-any.whl.

File metadata

  • Download URL: tachyon_api-0.5.5-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tachyon_api-0.5.5-py3-none-any.whl
Algorithm Hash digest
SHA256 993e2e4c0c574a24f7b984e989cc1817408bc69e1524b3ccd89df20b23869ffc
MD5 464971332fc646cba761654f5f20a203
BLAKE2b-256 c268605a4b07b5ca1afa21f7058e0dbab6b02657594d3b31950a293340b28326

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