Examples¶
Each example is a small, complete FastAPI app in the repository's
examples/ folder, written the
way the tools are meant to be used in production, and tested with the library on every change.
They keep their state in memory so that they run without any server; in production, Redis or
Valkey lets every process share it. Only the background work needs one.
-
Server-side sessions, CSRF protection and security headers for a cookie-based app.
-
Keys stored as digests with scopes, one-time login codes and revoked tokens.
-
A site without passwords: sign-ups and logins by passkey, and the devices each user is logged in on.
-
An authenticator app after the password, recovery codes, and a recent code to delete the account.
-
Searches and tokens metered per tenant, held to its plan, each charge a record for billing.
-
Who changed or deleted which account, refusals included, signed and chained.
-
An app per strategy: JWTs, logins with GitHub, sessions, bearer tokens, SAML single sign-on and API keys; and three of them on one app.
-
A newsroom whose Casbin policy says who reads, writes, publishes and grants roles, a team's documents whose Cedar policies decide by their attributes, and a shop whose refunds Open Policy Agent decides, asked over the network.
-
Scheduled jobs, a leader among processes and a task queue on Redis streams.
-
The real type of a file from its bytes, size and pixel limits, and safe names.
-
Problem details, request IDs in logs and responses, deadlines and health checks.
-
A retried payment gets the first response instead of charging twice.
-
Maintenance mode, feature flags and circuit breakers, switched at runtime.
-
An app per strategy, from page numbers to scrolls and streams; and a catalogue cached three ways.
-
Requests per client and per user, shared budgets, and at most N expensive calls at a time.
-
Shared entries for public pages, private ones per user, invalidation by tag and
get_or_set. -
Signed webhooks received without replays, and sent to user URLs without SSRF.
Running them¶
From a clone of the repository, each one starts with uvicorn:
git clone https://github.com/nonodev96/fastapi-alcazaba.git
cd fastapi-alcazaba
make deps # .venv, with every extra
source .venv/bin/activate
uvicorn examples.cache.main:app
Then open http://127.0.0.1:8000/docs to try its endpoints from the browser. The keys and secrets they need come from environment variables, with a throwaway value for trying them out: set real ones in production.