Skip to main content

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

Project description

fastapi-easylimit

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-easylimit

Usage

from fastapi import FastAPI
from fastapi_easylimit.middleware import RateLimiterMiddleware
from fastapi_easylimit.backends import AsyncRedisBackend, InMemoryBackend
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.0.tar.gz (4.3 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.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_easylimiter-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 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.0.tar.gz
Algorithm Hash digest
SHA256 8db6473fac28693f2b5d3c6284f9ffff3f66f6043b3723dff2947ebcfa073aa2
MD5 aaf884a4ba7cdddda1a3e7e7d591bb7c
BLAKE2b-256 0d6fb7f380db3f27d0457a852af18011b7a50693daeffa535efd35d740d4a066

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_easylimiter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4001737649dd1bab2426fa3591dfa50ced12e81f3b4303542ec814a71ef30d8d
MD5 4e4ad9f332049d70a739297d12b6ba65
BLAKE2b-256 cf47a8add6944a1e2aaa96de1d5be1d9e9fa6d4a5e950751825faef49922fffa

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