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
Passwords auth scrypt hashes with a pepper, leaked passwords refused, guesses limited per account, resets by a link that works once
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
Object storage uploads signed URLs and upload forms for S3, R2 or MinIO, without an SDK
E-mail mail password resets, codes and receipts over SMTP with TLS, without forged headers
Pagination pagination page numbers, offsets, ranges, cursors, keysets, scrolls and streams, cached page by page
Background work background a task queue, scheduled jobs, locks, leader election, broadcast to every process and an outbox
Operations operations circuit breakers, maintenance mode and feature flags
Observability observability, telemetry problem details, request IDs, timeouts, health checks, OpenTelemetry, logs as JSON
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.7.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.7.0
File Size Uploaded Provenance Actions
fastapi_alcazaba-0.7.0.tar.gz 703.8 kB With provenance Details for fastapi_alcazaba-0.7.0.tar.gz

Built distribution (wheel)

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

Total release size: 1.0 MB

Release files / fastapi_alcazaba-0.7.0.tar.gz

Download URL fastapi_alcazaba-0.7.0.tar.gz
Size 703.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ff33d8c4c7581d36cf57edb7bc497e12db820de86c29ce55ca87ccd0623d5a33
BLAKE2b-256 checksum
How to use checksums
b9c0e5b5702e4cc254f65931a17d1ea60befca7193586d456a56ea422c8c7fee
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.7.0-py3-none-any.whl

Download URL fastapi_alcazaba-0.7.0-py3-none-any.whl
Size 336.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b135620af928fcf1ef9c0af0170b421e4a167184d26494ec4100831ec23736eb
BLAKE2b-256 checksum
How to use checksums
edc5d5366b30b251484f19c7bc8d0536ee844fe91c5479479ece89dbac8532d6
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.7.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.7.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