Skip to main content

Alcazaba's logo: a fortress wall whose horseshoe-arch gate opens on a bolt

Alcazaba

Secure, maintained tools for FastAPI
Response cache, rate limits, sessions, CSRF, webhooks, a task queue and more, in one package.

Documentation | Examples | PyPI | Changelog | Security policy


Alcazaba (fastapi-alcazaba) gathers the pieces most FastAPI apps end up writing themselves, built with security in mind and tested against real servers. They share one backend (memory, Redis, Valkey, memcached or DynamoDB), one format of errors and one set of metrics.

Tool In fastapi_alcazaba. What it does
Response cache response_cache @cache for endpoints and functions, invalidated by tag, signed or encrypted
Rate and concurrency limits rate_limit a sliding window, and at most N requests at a time, shared by every process
Idempotency keys idempotency a retried POST gets the first response instead of running twice
Authentication auth FastAPIAuth with strategies: JWTs, bearer tokens, sessions, OAuth2, OpenID Connect and SAML logins, Unkey's API keys, your own
Tokens, codes and API keys auth a JWT blocklist, one-time codes and API keys, nothing stored in clear
Passkeys auth logins without a password (WebAuthn), which a phishing page can't relay
Second factor auth authenticator apps' codes (TOTP) after the password, recovery codes, step-up for sensitive actions
Authorization authz FastAPIAuthz: a Casbin, Cedar or Open Policy Agent policy decides who may do what, per route or for every request
Browser apps security server-side sessions (each user's, listed and ended), CSRF protection, security headers and body size
Webhooks and outbound calls webhooks, outbound Standard Webhooks signatures; deadlines, breakers and SSRF protection for httpx
Uploads uploads the real type from the bytes, size, image dimensions, safe names
Pagination pagination page numbers, offsets, ranges, cursors, keysets, scrolls and streams, cached page by page
Background work background a task queue, scheduled jobs, locks and leader election
Operations operations circuit breakers, maintenance mode and feature flags
Observability observability, telemetry problem details, request IDs, timeouts, health checks, OpenTelemetry
Accounting accounting what each user, API key or tenant uses per period, held to its plan's quotas, a record per charge for billing
Audit trail audit who did what to which resource; no secrets, signed and chained

Install

pip install fastapi-alcazaba            # in-memory backend only
pip install "fastapi-alcazaba[redis]"   # or [valkey], [glide], [memcache], [dynamodb], [all]

Python 3.11+, FastAPI 0.115+ and Pydantic v2. The other extras (OpenTelemetry, encryption, Casbin, JWT, OAuth2, SAML...) are in the guide.

A taste

from collections.abc import AsyncIterator
from contextlib import asynccontextmanager

from fastapi import Depends, FastAPI
from pydantic import BaseModel

from fastapi_alcazaba import FastAPICache
from fastapi_alcazaba.backends.inmemory import InMemoryBackend
from fastapi_alcazaba.rate_limit import FastAPIRateLimiter
from fastapi_alcazaba.response_cache import cache


@asynccontextmanager
async def lifespan(_: FastAPI) -> AsyncIterator[None]:
    FastAPICache.init(InMemoryBackend(), prefix="shop")  # RedisBackend for several processes
    yield


app = FastAPI(lifespan=lifespan)


class Product(BaseModel):
    name: str
    price: float


@app.get(
    "/products/{product_id}",
    dependencies=[Depends(FastAPIRateLimiter(times=10, seconds=1))],  # per client
)
@cache(expire=60, vary_headers=())  # the same response for everybody: one shared entry
async def product(product_id: int) -> Product:
    return Product(name="Olive oil", price=9.5)

The guide starts with an app built in three steps, and each tool has a page of its own and an example app that runs as it is.

Security

The security tools (revocations, idempotency, webhooks, sessions, the task queue) fail closed when the backend does, and none of them puts secrets in logs, keys or errors. The security model says what each tool protects against and what it needs from you; report vulnerabilities as SECURITY.md says.

Development

make deps               # .venv with every extra
make lint               # ruff, mypy and pylint
make test               # the unit tests, with coverage
make services-up        # Redis, Valkey, memcached and DynamoDB in Docker, for:
make test-integration

CONTRIBUTING.md has the rest.

License

Apache License 2.0: see LICENSE and NOTICE.

Metadata

Release files for fastapi-alcazaba 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-alcazaba 0.6.0
File Size Uploaded Provenance Actions
fastapi_alcazaba-0.6.0.tar.gz 669.3 kB With provenance Details for fastapi_alcazaba-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-alcazaba 0.6.0
File Interpreter ABI Platform Actions
fastapi_alcazaba-0.6.0-py3-none-any.whl Python 3 none any Details for fastapi_alcazaba-0.6.0-py3-none-any.whl

Total release size: 980.6 kB

Release files / fastapi_alcazaba-0.6.0.tar.gz

Download URL fastapi_alcazaba-0.6.0.tar.gz
Size 669.3 kB
Tags Source
SHA-256 checksum
How to use checksums
20de64452689948f8210538b21ac9bf5d1841d498311a049ffae4920592a503c
BLAKE2b-256 checksum
How to use checksums
f146005e2895e24a03a3d57cd818a2d6e37cf29c8a6e2629afb1e300e7588236
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

Release files / fastapi_alcazaba-0.6.0-py3-none-any.whl

Download URL fastapi_alcazaba-0.6.0-py3-none-any.whl
Size 311.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
89991f061124ce052610ca7aa900bb94d48b36fb46a6c458cd2392bc397c74bc
BLAKE2b-256 checksum
How to use checksums
866e0bea3bf86ea972109384584305e0aeff899c424bd94db34fe2d2cb20dee9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

Security for fastapi-alcazaba 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fastapi_alcazaba-0.6.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page