Skip to main content

Route lifecycle management for APIs — maintenance mode, env gating, deprecation, and more

Project description

API Shield

Route lifecycle management for Python web frameworks — maintenance mode, environment gating, deprecation, admin panels, and more. No restarts required.

PyPI Python versions License


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

MIT

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

api_shield-0.2.0.tar.gz (215.9 kB view details)

Uploaded Source

Built Distribution

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

api_shield-0.2.0-py3-none-any.whl (102.1 kB view details)

Uploaded Python 3

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

Hashes for api_shield-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5023a5397275b4cf960a4a728690aa2e36c423e0003540419c3b18288d4f7266
MD5 6dff02920df73d5d25aba90a34b05cbb
BLAKE2b-256 8dd8aa9f05fbe0a0b2a2e3bb1fe34591843e758d82b5d0d82935c942f9366330

See more details on using hashes here.

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

Hashes for api_shield-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 762a660e9d66dcc3a708c6ca33ab61a7c98776adb406ba6fb08a913a9087a685
MD5 ebc817471bc3a94ac9a50a0d4c879520
BLAKE2b-256 4fe09f70f8543a09baa8d556c59b760e89c324c515128eb93577cdf85c400efa

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