Skip to main content

High-performance async rate limiter for FastAPI with Redis or native in-memory backend

Project description

fastapi-easylimiter

Simple async rate-limiting middleware for FastAPI with Redis or in-memory caching.

Simple design

  • Async rate limiting
  • Redis or in-memory cache

Installation

pip install fastapi-easylimiter

Usage

from fastapi import FastAPI
from fastapi_easylimiter import AsyncRedisBackend, InMemoryBackend, RateLimiterMiddleware
import redis.asyncio as redis_async

app = FastAPI()

REDIS_URL = "redis://localhost:6379/0"

# Redis client
redis_client = redis_async.from_url(REDIS_URL, decode_responses=True)
backend = AsyncRedisBackend(redis_client)

# Or for local development:
# backend = InMemoryBackend()

rules = {
    "/api/users": {"limit": 1, "period": 2},
    "/api/": {"limit": 60, "period": 60}, # GLOBAL ONES GO LAST
}

app.add_middleware(
    RateLimiterMiddleware,
    rules=rules,
    backend=backend,
    backoff_threshold=3,
    max_backoff=60
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_easylimiter-0.1.4.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_easylimiter-0.1.4-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_easylimiter-0.1.4.tar.gz.

File metadata

  • Download URL: fastapi_easylimiter-0.1.4.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for fastapi_easylimiter-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2a739fced12d20aedf0fe56955d64aebdc664476e450fc30bf222ef4a289019a
MD5 3719e1009924997f02e1006a78862567
BLAKE2b-256 39bcdff46254154726bd027466eb71f8fea5cfa7f735dbf26f094a75d4c4eaf8

See more details on using hashes here.

File details

Details for the file fastapi_easylimiter-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_easylimiter-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3318f18e3413a68ca5ab53b922f33461a16d8f8cfb942d8602ce8cbd05bcd7be
MD5 a59fc3c62af75e26d79e1237d93a0fb1
BLAKE2b-256 16ca2006ae184efdcfc58e9d74c529ad0eb6a651cb1aeaa72bc7538e482ba164

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page