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

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

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.8.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

slowapi-0.1.8-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: slowapi-0.1.8.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.11.2 Linux/6.1.0-7-amd64

File hashes

Hashes for slowapi-0.1.8.tar.gz
Algorithm Hash digest
SHA256 8cc268f5a7e3624efa3f7bd2859b895f9f2376c4ed4e0378dd2f7f3343ca608e
MD5 3f20af04e974e92a982d7fe179982106
BLAKE2b-256 f5973e85a6097fb4986691b52dbef7ca7576f49740fc880160602f91a1062c69

See more details on using hashes here.

File details

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

File metadata

  • Download URL: slowapi-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.11.2 Linux/6.1.0-7-amd64

File hashes

Hashes for slowapi-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 629fc415575bbffcd9d8621cc3ce326a78402c5f9b7b50b127979118d485c72e
MD5 fc0a8989dbe3263418d15a7914cdf1f2
BLAKE2b-256 2dde6865ffa325c8c1f68569cba7ff41a1949feecff19ca874bbaf8e330950df

See more details on using hashes here.

Supported by

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