CyberLearn
← Back to advanced
Advanced

API Rate Limiter

Distributed rate limiting middleware

Log in to track progress
1wPythonRedis

What you'll learn

  • Token bucket algorithm
  • Distributed systems
  • Redis backend
███████╗ █████╗ ███████╗████████╗ █████╗ ██████╗ ██╗     ██╗  ██╗██████╗  ██████╗
██╔════╝██╔══██╗██╔════╝╚══██╔══╝██╔══██╗██╔══██╗██║     ██║  ██║╚════██╗██╔═████╗
█████╗  ███████║███████╗   ██║   ███████║██████╔╝██║     ███████║ █████╔╝██║██╔██║
██╔══╝  ██╔══██║╚════██║   ██║   ██╔══██║██╔═══╝ ██║     ╚════██║██╔═══╝ ████╔╝██║
██║     ██║  ██║███████║   ██║   ██║  ██║██║     ██║          ██║███████╗╚██████╔╝
╚═╝     ╚═╝  ╚═╝╚══════╝   ╚═╝   ╚═╝  ╚═╝╚═╝     ╚═╝          ╚═╝╚══════╝ ╚═════╝

Cybersecurity Projects Python License: AGPLv3 PyPI FastAPI

Enterprise rate limiting for FastAPI using HTTP 420 "Enhance Your Calm".

<p align="center"> <a href="https://youtu.be/mIeVcpwWP2Q"> <img src="https://img.shields.io/badge/Watch_on-YouTube-FF0000?logo=youtube&logoColor=white" alt="Watch on YouTube"> </a> </p> <p align="center"> <a href="https://youtu.be/mIeVcpwWP2Q"> <img src="https://img.youtube.com/vi/mIeVcpwWP2Q/maxresdefault.jpg" alt="Video Thumbnail" width="800"> </a> </p>

Learning Docs are here: 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="69/minute"))
app.add_middleware(limiter.middleware)

For Redis support: uv add fastapi-420[redis]

[!TIP] This project uses just as a command runner. Type just to 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.

ModuleTopic
00 - OverviewPrerequisites and quick start
01 - ConceptsSecurity theory and real-world breaches
02 - ArchitectureSystem design and data flow
03 - ImplementationCode walkthrough
04 - ChallengesExtension ideas and exercises

License

AGPL 3.0