Rate limiting for callable functions
Project description
Function-Limiter provides rate limiting features to callable function.
Installation
pip install Flask-Limiter
Quick Start
Add the rate limiter to your function as decorator. The following example uses the default in memory implementation for storage.
The decorators made available as instance methods of the Limiter instance are Limiter.
from function_limiter.limiter import Limiter
from function_limiter.limiter import RateLimitExceeded
import time
limiter = Limiter()
@limiter.limit('3/second', 'key')
def function():
print('hello world!')
from function_limiter.limiter import Limiter
from function_limiter.limiter import RateLimitExceeded
import time
storage_uri = 'redis://ip:port/'
limiter = Limiter(
storage_uri=storage_uri
)
There are a few ways of using this decorator depending on your preference and use-case.
Single decorator
The limit string can be a single limit or a delimiter separated string
@limiter.limit('3/second;10 per minute', 'key')
def function():
print('hello world!')
Multiple decorators
The limit string can be a single limit or a delimiter separated string or a combination of both.
@limiter.limit('3/second', 'key')
@limiter.limit('10 per minute', 'key')
def function():
print('hello world!')
Custom keying function
By default rate limits are applied based on the key function that the Limiter instance was initialized with. You can implement your own function to retrieve the key to rate limit by when decorating individual routes. Take a look at Rate Limit Key Functions for some examples.
def limitation():
return '5/second'
def key():
return 'custom key'
@limiter.limit(limitation, key=key)
def function():
print('hello world!')
Changelog
v0.0.9
- Release Date: 2021-01-28
Rate limit policy changed to successful call.
- Bug Fixed:
Multiple limit doesn’t work.
v0.0.8
- Release Date: 2021-01-17
- Bug Fixed:
Null key bugs Fixed.
v0.0.7
- Release Date: 2021-01-17
Bug Fixed.
v0.0.6
- Release Date: 2021-01-16
Added redis as in memory storage.
v0.0.5
- Release Date: 2021-01-16
Added garbage collector.
v0.0.4
- Release Date: 2021-01-16
Added Validator to limiter.
v0.0.3
- Release Date: 2021-01-14
Added callable function for limitation and key function.
v0.0.2
- Release Date: 2021-01-14
Bug fixed.
v0.0.1
- Release Date: 2021-01-13
Basic Function Limiter.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for Function_Limiter-0.0.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b7115b00be1b22e99ab7719b063b87fb8a0fcf4071980d3dcce2670a6d3c276 |
|
MD5 | 2956fa66dbf76fdfbd627f68cfec17d8 |
|
BLAKE2b-256 | 463eea5d9e7a96bb4f31b36219a6236712bb3b16fd58ca036bca725f8ae385da |