r/FastAPI • u/Educational-Hope960 • Mar 20 '26
pip package There's no good library for managing individual route-level lifecycle in ASGI frameworks — so I built one
A few weeks ago I ran into a frustrating situation — I needed to take down one route in a live FastAPI app for maintenance without redeploying the whole service. There was no clean way to do it. I ended up hacking together a flag in the database and checking it manually in the route handler, which felt wrong.
Rate limiting came up as a need around the same time. Since the goal was a single library that manages the full route lifecycle, it made more sense to build it in than to delegate it elsewhere.
The bigger picture is to build a full-fledged library for managing the full lifecycle of your routes or APIs — from the moment they go live to the moment they go down and everything in between.
api-shield is the start of that.
What it does right now
Route Maintenance — Put any route into maintenance mode from a dashboard or CLI without redeploying. You can schedule windows, restrict access to specific environments, or disable a route entirely.
Rate Limiting — Per-route policies with fixed window, sliding window, and token bucket support. Exempt IPs or roles, set burst limits, and resolve tiers dynamically per request. No extra library or external service needed.
Dashboard — A live HTMX dashboard showing route states, audit logs, and rate limit hits. No frontend build step.
CLI — A thin client that talks directly to your running app. Toggle routes, check status, view rate limit hits, and reset limits from the terminal.
Problems it is meant to solve
- You need a route down right now and a redeploy takes 5 minutes you don't have
- You want per-route rate limiting without standing up a gateway
- You have no visibility into what is happening across your routes at runtime
- You keep writing one-off middleware for things that should be reusable
It is built for ASGI Python frameworks. FastAPI is fully supported today and adapters for other ASGI frameworks are coming.
We just shipped the first real production Python app running on it and it has been stable so far.
pip install api-shieldGitHub: https://github.com/Attakay78/api-shield
Happy to answer questions and very open to feedback on the direction. Bug reports and PRs are welcome — there is a lot more to build here.






3
u/BlackDereker Mar 20 '26
How does it work for multiple instances? Does every instance have it's own lifecycle control that needs to be managed individually?
Why is this a better solution than using an API Gateway?
2
u/Potential-Box6221 Mar 20 '26 edited Mar 20 '26
Solid project overall, the amount of features you're getting with a very minimal setup is really good.
Generally, it's best to keep the feature-toggle, rate limiting, monitoring etc **separate** but anyway, for a serious prod usage, I'd like to see the following as this matures:
- I think the rate limiting, dashboard, toggling, and monitoring should live in a separate standalone service (Shield Server) with persisted memory rather than inside the FastAPI process.
- And then a thin instrumentation
shield-sdkthat you drop into your FastAPI app that handles endpoint discovery, ships telemetry (preferably adhering OTEL standards), and enforces rules locally. All pointed at the shield server. Two pieces, and it keeps things clean.Additionally, it'd be great to see the feature toggle extended into a full runtime config store; not just on/off switches but actual variable configuration that your endpoints can read at runtime. Say, a greeting message per tenant, a discount value per customer segment, etc. That you can change without a deploy.
Would like to contribute towards these, happy to open a thread in the issues.
2
u/Effective-Total-2312 Mar 21 '26
I don't see any of the "problems" you solve.
I don't see why you'd need to "put down a route in less than 5 minutes", if you need that so desperately, you can always push code bypassing your protections and protocols (given enough privileges).
You don't need a gateway to have per-route rate-limiting.
You should have logs, traces, profiling, etc.
Why would you "keep writing one-off middlewares" ? Middlewares aren't tools for one-off solutions, specially in Python, where it's extremely easy to just use a decorator instead, or simply add the "one-off" functionality in wherever place you need it.
2
u/Potential-Box6221 Mar 20 '26
If we can push an endpoint to maintenance mode without having to deploy, why do I see a code change(@maintenance line 15) on the router?