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.

Note: this is alpha quality code still, the API may change, and things may fall apart while you try it.

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 (will come 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

  • There is no support for default limits yet (in other words, the only default limit supported is "unlimited")

  • 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.2.tar.gz (12.1 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.2-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: slowapi-0.1.2.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.6 Linux/5.8.0-1-amd64

File hashes

Hashes for slowapi-0.1.2.tar.gz
Algorithm Hash digest
SHA256 5b6c8abeb844933ef0066c7cee2fd3b00f6a61bbba1140df2ad2ac70d7a1a185
MD5 8affb03fbf0f9bb13d8bf40f596f0dcc
BLAKE2b-256 19f0505b4b02462e0b653a5a7ef1e8d4ec745d0a7f1dec33c3d8f416085457ca

See more details on using hashes here.

File details

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

File metadata

  • Download URL: slowapi-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.6 Linux/5.8.0-1-amd64

File hashes

Hashes for slowapi-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 80c208164b756c587841fd698d72ba2eed5056d89b7dac39db36c7842e1c538c
MD5 01edf5c1a7c6afa0a50693ec49598bb9
BLAKE2b-256 b1dacffe9d68d971fd833ff92c827b670da340f835edccf84fd97b223c4c2121

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