Skip to main content

A rate limiter plugin for Falcon

Project description

falcon-ratelimit
========

[![Build Status](https://travis-ci.org/piotrmaslanka/falcon-ratelimit.svg)](https://travis-ci.org/piotrmaslanka/falcon-ratelimit)
[![Maintainability](https://api.codeclimate.com/v1/badges/698296b5954d7cbdd0dc/maintainability)](https://codeclimate.com/github/piotrmaslanka/falcon-ratelimit/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/698296b5954d7cbdd0dc/test_coverage)](https://codeclimate.com/github/piotrmaslanka/falcon-ratelimit/test_coverage)
[![Issue Count](https://codeclimate.com/github/piotrmaslanka/falcon-ratelimit/badges/issue_count.svg)](https://codeclimate.com/github/piotrmaslanka/falcon-ratelimit)
[![PyPI](https://img.shields.io/pypi/pyversions/falcon-ratelimit.svg)](https://pypi.python.org/pypi/falcon-ratelimit)
[![PyPI version](https://badge.fury.io/py/falcon-ratelimit.svg)](https://badge.fury.io/py/falcon-ratelimit)
[![PyPI](https://img.shields.io/pypi/implementation/falcon-ratelimit.svg)](https://pypi.python.org/pypi/falcon-ratelimit)

Rate limiter for Falcon. Use like:

```python
import falcon
from falconratelimit import rate_limit


class NoRedisResource(object):
@falcon.before(rate_limit(per_second=5, window_size=30, resource='resource_name'))
def on_post(self, req, resp):
...

class RedisResource(object):
@falcon.before(rate_limit(redis_url='localhost:6379', per_second=1, window_size=10))
def on_post(self, req, resp):
...
```

This package works by limiting the number of requests using two variables `per_second` and `window_size`. In the first example above, the `NoRedisResource` class is restricted to 5 requests per second over a 30 second window meaning that there is a limit of 150 requests over 30 seconds. The default storage of calling the `rate_limit` decorator is an in memory list to store the number of requests for the given user using the resource `resource_name`.

The second example implements the optional storage to use Redis by passing in a `redis_url` to store user request data. Using Redis allows for the rate limiting to be implemented across multiple instances of a particular application. In the `RedisResource` class example the user is allowed to make 1 request per second over 10 seconds meaning that there is a limit of 10 requests over 10 seconds. Since this example didn't pass in a `resource` it uses `default` as the name for request storage.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

falcon_ratelimit-1.0-py2.py3-none-any.whl (4.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file falcon_ratelimit-1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: falcon_ratelimit-1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.13

File hashes

Hashes for falcon_ratelimit-1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bf2148ddc82623fc2514e9c30e88777e335f33faa6e8bfacc69bd8ba62111db4
MD5 3006adf5a5a2a8d410803ba046d79803
BLAKE2b-256 51c00ae7776eef9a150f9bcd83af47e479a6fa13d6f9f5cc53061bd5a9e22719

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