A Python microservices framework for FastAPI with service discovery and API gateway routing
Project description
Tapper - Python Microservices Framework
Tapper is a lightweight, elegant Python framework that simplifies service discovery and API gateway routing for FastAPI-based microservices.
With a single @Service decorator placed on your service's main.py, Tapper automatically registers your service and provides a powerful API gateway that discovers all services and intelligently routes requests to the correct backend.
Features
- Zero-boilerplate registration with
@tapper.Service - Automatic service discovery and registration
- Built-in dynamic API gateway with path-based routing
- Transparent proxying of requests (path params, query strings, headers, body)
- Health checks and service status monitoring
- Load balancing (round-robin by default)
- Seamless integration with existing FastAPI apps
- Minimal configuration — focus on your business logic
Installation
pip install tapper
Quick Start
1. Annotate Your Service (in main.py of each microservice)
from fastapi import FastAPI
from tapper import Service
app = FastAPI()
@Service(name="user-service", version="1.0.0", description="User management service")
@app.get("/users/{user_id}")
async def get_user(user_id: int):
return {"user_id": user_id, "name": "Jane Doe"}
@app.post("/users/")
async def create_user(user: dict):
return {"message": "User created", "user": user}
That's all! The @Service decorator registers your service automatically.
2. Run the API Gateway
Create a separate gateway application (e.g., gateway.py):
from fastapi import FastAPI
from tapper import TapperGateway
app = FastAPI(title="Tapper API Gateway")
# Initialize the gateway (you can pass registry_url or use env vars)
gateway = TapperGateway()
# Mount the gateway at the root
app.mount("/", gateway)
# Optional: expose gateway health
@app.get("/health")
async def health():
return {"status": "healthy", "services": gateway.get_service_status()}
Run it:
uvicorn gateway:app --port 8000
Now your gateway at http://localhost:8000 will automatically discover and route to all @Service-decorated FastAPI apps.
How It Works
- Each microservice uses the
@Servicedecorator on itsFastAPIinstance. - Tapper registers the service (name, version, endpoints) with a central registry.
- The TapperGateway periodically discovers available services.
- Incoming requests are matched against registered service routes.
- Requests are proxied transparently to the correct service instance.
Configuration Options
Service Decorator
@Service(
name="payment-service",
version="2.1.0",
description="Handles all payment operations",
prefix="/payments", # optional: prefix all routes
health_endpoint="/health", # optional: custom health check path
tags=["payments", "finance"] # optional: OpenAPI tags
)
Gateway Configuration
gateway = TapperGateway(
registry_url="http://registry:8001", # or via TAPER_REGISTRY_URL env var
discovery_interval=30, # seconds
timeout=5, # request timeout in seconds
load_balancer="round-robin", # or "random", "least-connections", custom
# auth_provider=YourAuthProvider(), # optional
)
Advanced Usage
Custom Load Balancer
from tapper import LoadBalancer
class CustomBalancer(LoadBalancer):
def select_instance(self, instances):
# Your custom logic
return instances[0]
gateway = TapperGateway(load_balancer=CustomBalancer())
Supported Registries
- In-memory (development)
- Redis
- Consul
- etcd
- Custom backend (extend
tapper.registry.RegistryBackend)
Contributing
Contributions are welcome!
- Fork the repo
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE for more information.
Acknowledgments
- Built on the amazing FastAPI
- Inspired by service discovery patterns from Kubernetes, Consul, and Spring Cloud
Happy microservicing with Tapper! 🚀
Feel free to customize badges, add a real logo, or adjust the configuration details as you implement the actual framework!
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 tyler_ag_tapper-0.1.0.tar.gz.
File metadata
- Download URL: tyler_ag_tapper-0.1.0.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8eab2e871aa75ed3386c19452dce91363224d7b1048ab843315c46ae63d52db8
|
|
| MD5 |
1170061e70a05b075d8174e3c3eb2ea6
|
|
| BLAKE2b-256 |
d863a570d01e19b0d74194849e199883976a62111993dba5b2a2d54f0cafc792
|
File details
Details for the file tyler_ag_tapper-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tyler_ag_tapper-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ef9477fd6f5e590030e76e1a4c7915f272bea3562acb0318d2584e305e74189
|
|
| MD5 |
b0b94c3dc80314b7e8191e2fec2b9d28
|
|
| BLAKE2b-256 |
43eb6e0e71a9dbcfc4a669fd5a9d7c25e2082b600b995a208194f3237c4e8ffd
|