an extendable toolbox for scalable apis
Project description
Premier
A production-ready ASGI API Gateway that transforms any Python web application into a full-featured API gateway with caching, rate limiting, retry logic, timeouts, and performance monitoring.
Features
Premier provides enterprise-grade API gateway functionality with:
- Response Caching - Smart caching with TTL and custom cache keys
- Rate Limiting - Multiple algorithms (fixed/sliding window, token/leaky bucket), works with distributed app
- Retry Logic - Configurable retry strategies with exponential backoff
- Request Timeouts - Per-path timeout protection
- Performance Monitoring - Request timing and analytics
- Path-Based Policies - Different features per route with regex matching
- Backend Forwarding - Route requests to multiple backend services
- YAML Configuration - Declarative configuration with namespace support
- Type Safety - Full type hints and structured configuration
... and more
Why Premier
Premier is designed for simplicity and accessibility - perfect for simple applications that need API gateway functionality without introducing complex tech stacks like Kong, Ambassador, or Istio.
Key advantages:
- Zero Code Changes - Wrap existing ASGI apps without modifications
- Simple Setup - Single dependency, no external services required
- Dual Mode Operation - Plugin for existing apps OR standalone gateway
- Python Native - Built for Python developers, integrates seamlessly
- Lightweight - Minimal overhead, maximum performance
- Hot Reloadable - Update configurations without restarts
Quick Start
Plugin Mode (Recommended)
Wrap your existing ASGI application:
from premier.asgi import ASGIGateway, GatewayConfig
from fastapi import FastAPI
# Your existing app - no changes needed
app = FastAPI()
@app.get("/api/users/{user_id}")
async def get_user(user_id: int):
return await fetch_user_from_database(user_id)
# Load configuration and wrap app
config = GatewayConfig.from_file("gateway.yaml")
gateway = ASGIGateway(config, app=app)
Standalone Mode
Use as a standalone gateway:
from premier.asgi import ASGIGateway, GatewayConfig
config = GatewayConfig.from_file("gateway.yaml")
gateway = ASGIGateway(config, servers=["http://backend:8000"])
uvicorn src:main
YAML Configuration
Configure gateway policies declaratively:
premier:
keyspace: "my-api"
paths:
- pattern: "/api/users/*"
features:
cache:
expire_s: 300
rate_limit:
quota: 100
duration: 60
algorithm: "sliding_window"
timeout:
seconds: 5.0
retry:
max_attempts: 3
wait: 1.0
monitoring:
log_threshold: 0.1
- pattern: "/api/admin/*"
features:
rate_limit:
quota: 10
duration: 60
algorithm: "token_bucket"
timeout:
seconds: 30.0
default_features:
timeout:
seconds: 10.0
monitoring:
log_threshold: 0.5
Installation
pip install premier
For Redis support (optional):
pip install premier[redis]
Framework Integration
Works with any ASGI framework:
# FastAPI
from fastapi import FastAPI
app = FastAPI()
# Starlette
from starlette.applications import Starlette
app = Starlette()
# Django ASGI
from django.core.asgi import get_asgi_application
app = get_asgi_application()
# Wrap with Premier
config = GatewayConfig.from_file("config.yaml")
gateway = ASGIGateway(config, app=app)
Production Deployment
# production.py
from premier.asgi import ASGIGateway, GatewayConfig
from premier.providers.redis import AsyncRedisCache
from redis.asyncio import Redis
# Redis backend for distributed caching
redis_client = Redis.from_url("redis://localhost:6379")
cache_provider = AsyncRedisCache(redis_client)
# Load configuration
config = GatewayConfig.from_file("production.yaml")
# Create production gateway
gateway = ASGIGateway(config, app=your_app, cache_provider=cache_provider)
# Deploy with uvicorn
if __name__ == "__main__":
import uvicorn
uvicorn.run(gateway, host="0.0.0.0", port=8000, workers=4)
Requirements
- Python >= 3.10
- Redis >= 5.0.3 (optional, for distributed deployments)
- PyYAML (for YAML configuration)
- aiohttp (optional, for standalone mode)
License
MIT License
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 premier-0.4.7.tar.gz.
File metadata
- Download URL: premier-0.4.7.tar.gz
- Upload date:
- Size: 134.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bdb6ddd946d56d86046063844fb3c37049074fb3dd7e4a7c3dbf6a368c3c8d2
|
|
| MD5 |
3c97617fa49aa55f821d37361c34ba8b
|
|
| BLAKE2b-256 |
85be292c7563246d1421ad97125c3edeadc14087c06138e99dc9fbc885426489
|
File details
Details for the file premier-0.4.7-py3-none-any.whl.
File metadata
- Download URL: premier-0.4.7-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.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49b3d35b0d8ca730fa482ea574796d9ce66930cf5725eba812ea00b2fd756d82
|
|
| MD5 |
f5408e578c4f070c106889b0e0361430
|
|
| BLAKE2b-256 |
dde7cd7ecdd4074248b5d845580bddf5f7a03981650e867a67229571e74f46f8
|