Enhance Your Calm - Advanced Rate Limiting & DDoS Protection for FastAPI
Project description
███████╗ █████╗ ███████╗████████╗ █████╗ ██████╗ ██╗ ██╗ ██╗██████╗ ██████╗
██╔════╝██╔══██╗██╔════╝╚══██╔══╝██╔══██╗██╔══██╗██║ ██║ ██║╚════██╗██╔═████╗
█████╗ ███████║███████╗ ██║ ███████║██████╔╝██║ ███████║ █████╔╝██║██╔██║
██╔══╝ ██╔══██║╚════██║ ██║ ██╔══██║██╔═══╝ ██║ ╚════██║██╔═══╝ ████╔╝██║
██║ ██║ ██║███████║ ██║ ██║ ██║██║ ██║ ██║███████╗╚██████╔╝
╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝
Production rate limiting for FastAPI using HTTP 420 "Enhance Your Calm".
This is a quick overview — security theory, architecture, and full walkthroughs are in the learn modules.
What It Does
- Three implementation methods: middleware (global), decorator (per route), dependency injection
- Sliding Window, Token Bucket, and Fixed Window rate limiting algorithms
- Redis support with automatic in-memory fallback when Redis is unavailable
- Scoped rate limiters for applying different limits to endpoint groups
- Fingerprint levels (RELAXED, NORMAL, STRICT) for client identification granularity
- Multiple stacking rules where the most restrictive limit applies
Quick Start
uv add fastapi-420
from fastapi import FastAPI
from fastapi_420 import RateLimiter, RateLimiterSettings
app = FastAPI()
limiter = RateLimiter(RateLimiterSettings(default_limit="100/minute"))
app.add_middleware(limiter.middleware)
For Redis support: uv add fastapi-420[redis]
[!TIP] This project uses
justas a command runner. Typejustto see all available commands.Install:
curl -sSf https://just.systems/install.sh | bash -s -- --to ~/.local/bin
Learn
This project includes step-by-step learning materials covering security theory, architecture, and implementation.
| Module | Topic |
|---|---|
| 00 - Overview | Prerequisites and quick start |
| 01 - Concepts | Security theory and real-world breaches |
| 02 - Architecture | System design and data flow |
| 03 - Implementation | Code walkthrough |
| 04 - Challenges | Extension ideas and exercises |
License
AGPL 3.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_420-1.0.1.tar.gz.
File metadata
- Download URL: fastapi_420-1.0.1.tar.gz
- Upload date:
- Size: 161.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39def7702248018edff86f2b82cf7006277f85346ff8f01448518089642dbbac
|
|
| MD5 |
9c845f87855dbbf69d18365f28433ded
|
|
| BLAKE2b-256 |
10b49fee3869209afb0a5c394cc0f1dbb32888c887ed632d500e4587d39c6e9e
|
Provenance
The following attestation bundles were made for fastapi_420-1.0.1.tar.gz:
Publisher:
publish-api-rate-limiter.yml on CarterPerez-dev/Cybersecurity-Projects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_420-1.0.1.tar.gz -
Subject digest:
39def7702248018edff86f2b82cf7006277f85346ff8f01448518089642dbbac - Sigstore transparency entry: 940499810
- Sigstore integration time:
-
Permalink:
CarterPerez-dev/Cybersecurity-Projects@9ae5be609bea4854ab180a37660ebcad27784d2e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/CarterPerez-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-api-rate-limiter.yml@9ae5be609bea4854ab180a37660ebcad27784d2e -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastapi_420-1.0.1-py3-none-any.whl.
File metadata
- Download URL: fastapi_420-1.0.1-py3-none-any.whl
- Upload date:
- Size: 50.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d0e36cfc531214d7d7588fcae2851bdfcb35005d310cd6bf6fd2750fac059bb
|
|
| MD5 |
2fd75f08b73d2e54566ebd1eb4c58a4d
|
|
| BLAKE2b-256 |
f673a40a8fb154fb5968739ac04baeb29bd1924cfba0c5ce698902e48681e402
|
Provenance
The following attestation bundles were made for fastapi_420-1.0.1-py3-none-any.whl:
Publisher:
publish-api-rate-limiter.yml on CarterPerez-dev/Cybersecurity-Projects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_420-1.0.1-py3-none-any.whl -
Subject digest:
1d0e36cfc531214d7d7588fcae2851bdfcb35005d310cd6bf6fd2750fac059bb - Sigstore transparency entry: 940499819
- Sigstore integration time:
-
Permalink:
CarterPerez-dev/Cybersecurity-Projects@9ae5be609bea4854ab180a37660ebcad27784d2e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/CarterPerez-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-api-rate-limiter.yml@9ae5be609bea4854ab180a37660ebcad27784d2e -
Trigger Event:
push
-
Statement type: