Skip to main content

A rate limiting extension for Starlette and Fastapi

Project description

SlowApi

A rate limiting library for Starlette and FastAPI adapted from flask-limiter.

This package is used in various production setups, handling millions of requests per month, and seems to behave as expected. There might be some API changes when changing the code to be fully async, but we will notify users via appropriate semver version changes.

The documentation is on read the docs.

Quick start

Installation

slowapi is available from pypi so you can install it as usual:

$ pip install slowapi

Features

Most feature are coming from FlaskLimiter and the underlying limits.

Supported now:

  • Single and multiple limit decorator on endpoint functions to apply limits
  • redis, memcached and memory backends to track your limits (memory as a fallback)
  • support for sync and async HTTP endpoints
  • Support for shared limits across a set of routes
  • The library aims to support all currently supported versions of python

Limitations and known issues

  • The request argument must be explicitly passed to your endpoint, or slowapi won't be able to hook into it. In other words, write:
    @limiter.limit("5/minute")
    async def myendpoint(request: Request)
        pass

and not:

    @limiter.limit("5/minute")
    async def myendpoint()
        pass
  • websocket endpoints are not supported yet.

Developing and contributing

PRs are more than welcome! Please include tests for your changes :)

The package uses poetry to manage dependencies. To setup your dev env:

$ poetry install

To run the tests:

$ pytest

Publishing a new release

  • bump version in `pyproject.toml
  • poetry publish --build to build and publish the package to pypi

Credits

Credits go to flask-limiter of which SlowApi is a (still partial) adaptation to Starlette and FastAPI. It's also important to mention that the actual rate limiting work is done by limits, slowapi is just a wrapper around it.

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

slowapi-0.1.10.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

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

slowapi-0.1.10-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file slowapi-0.1.10.tar.gz.

File metadata

  • Download URL: slowapi-0.1.10.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.2 Linux/6.17.13+deb14-amd64

File hashes

Hashes for slowapi-0.1.10.tar.gz
Algorithm Hash digest
SHA256 d320d5bc04d9f171a77fb16700faf3036d85b00f420f22924c8a225f95bd14f9
MD5 72ac01c9db9b3caa15765b220330f2e1
BLAKE2b-256 b95224527cf25a8b508926aff53350b0136561dfe86c7125f61526653666e1b2

See more details on using hashes here.

File details

Details for the file slowapi-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: slowapi-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.2 Linux/6.17.13+deb14-amd64

File hashes

Hashes for slowapi-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 3acb61561dc9d687e3d3669362ff6a439de9ba44e2fed3a9c165da26b4b83e28
MD5 360b0ba689f48a84246b2830c699d658
BLAKE2b-256 c48b1d359f38706b4097d9a943bf8bd22599f537de4cbaff1e622d3e3936e164

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