Skip to main content

Simple FastAPI rate limiter

Project description

simplelimiter

A simple FastAPI rate limiter

Requirements

Redis

How to use

Install the package

pip install simplelimiter

Example

import redis

from fastapi import FastAPI, APIRouter, Request
from fastapi.params import Depends
from simplelimiter import Limiter


app = FastAPI()
router = APIRouter()

# We initialize the Limiter on the app startup event
@app.on_event("startup")
async def startup():
    r = redis.from_url("redis://localhost", encoding="utf-8", decode_responses=True)
    Limiter.init(redis_instance=r, debug=True)

    return app


# We pass the Limiter as a dependencie
@router.get("/", dependencies=[Depends(Limiter("5/minute"))])
def base_route(request: Request):
    return {"response": "ok"}


app.include_router(router)

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

simplelimiter-0.1.4.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

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

simplelimiter-0.1.4-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simplelimiter-0.1.4.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.5 Windows/10

File hashes

Hashes for simplelimiter-0.1.4.tar.gz
Algorithm Hash digest
SHA256 12844fc3eebb5b1cded48ce4a30beb891c6ab049eac0d2b3af82ed6a4e401266
MD5 4e7d056e98f6c4c96f280195376563e8
BLAKE2b-256 8bcd41ac320c632e3352a9b3f51413a090f6e2f7adbcb84189999c0147b92080

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simplelimiter-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.5 Windows/10

File hashes

Hashes for simplelimiter-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ca09bfd044fd70173b0d7e930e393c3d260330110cae24a771226e50cce6f562
MD5 02389b916bf5dbdeda6a3be7a377a962
BLAKE2b-256 c40a025e882d1442a80d3dbce030681f219f189fa13b2fcdaaf0b76e094ce399

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