Route lifecycle management for APIs — maintenance mode, env gating, deprecation, and more
Project description
Route lifecycle management for Python web frameworks — maintenance mode, environment gating, deprecation, admin panels, and more. No restarts required.
Install
uv add "api-shield[all]"
# or: pip install "api-shield[all]"
Quickstart
from fastapi import FastAPI
from shield.core.config import make_engine
from shield.fastapi import (
ShieldMiddleware, ShieldAdmin, apply_shield_to_openapi,
maintenance, env_only, disabled, force_active, deprecated,
)
engine = make_engine()
app = FastAPI()
app.add_middleware(ShieldMiddleware, engine=engine)
@app.get("/payments")
@maintenance(reason="DB migration — back at 04:00 UTC")
async def get_payments():
return {"payments": []}
@app.get("/health")
@force_active
async def health():
return {"status": "ok"}
apply_shield_to_openapi(app, engine)
app.mount("/shield", ShieldAdmin(engine=engine, auth=("admin", "secret")))
GET /payments → 503 {"error": {"code": "MAINTENANCE_MODE", ...}}
GET /health → 200 always
Manage routes from the CLI — no code changes, no restarts:
shield config set-url http://localhost:8000/shield
shield login admin
shield status
shield enable GET:/payments
shield global enable --reason "Deploying v2" --exempt /health
Decorators
| Decorator | Effect | Status |
|---|---|---|
@maintenance(reason, start, end) |
Temporarily unavailable | 503 |
@disabled(reason) |
Permanently off | 503 |
@env_only("dev", "staging") |
Restricted to named environments | 404 elsewhere |
@deprecated(sunset, use_instead) |
Still works, injects deprecation headers | 200 |
@force_active |
Bypasses all shield checks | Always 200 |
Backends
| Backend | Persistence | Multi-instance |
|---|---|---|
MemoryBackend |
No | No |
FileBackend |
Yes | No |
RedisBackend |
Yes | Yes |
Documentation
Full documentation at attakay78.github.io/api-shield
| Tutorial | Get started in 5 minutes |
| Decorators reference | All decorator options |
| ShieldEngine reference | Programmatic control |
| Backends | Memory, File, Redis, custom |
| Admin dashboard | Mounting ShieldAdmin |
| CLI reference | All CLI commands |
| Production guide | Monitoring & deployment automation |
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 api_shield-0.2.0.tar.gz.
File metadata
- Download URL: api_shield-0.2.0.tar.gz
- Upload date:
- Size: 215.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5023a5397275b4cf960a4a728690aa2e36c423e0003540419c3b18288d4f7266
|
|
| MD5 |
6dff02920df73d5d25aba90a34b05cbb
|
|
| BLAKE2b-256 |
8dd8aa9f05fbe0a0b2a2e3bb1fe34591843e758d82b5d0d82935c942f9366330
|
File details
Details for the file api_shield-0.2.0-py3-none-any.whl.
File metadata
- Download URL: api_shield-0.2.0-py3-none-any.whl
- Upload date:
- Size: 102.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
762a660e9d66dcc3a708c6ca33ab61a7c98776adb406ba6fb08a913a9087a685
|
|
| MD5 |
ebc817471bc3a94ac9a50a0d4c879520
|
|
| BLAKE2b-256 |
4fe09f70f8543a09baa8d556c59b760e89c324c515128eb93577cdf85c400efa
|