python redis backed limiter
sliding log or fixed window limiter
This module mainly offer two limiter
- FixedWindowLimiter
simply using redis incr, which about 10 times the speed of the sliding version but the limit is not smooth, may overflow a threshold size near the gap between two intervals - SlidingWindowLimiter
using redis ordered set, slow but offers more smooth limit and more extendability
installation
pip install python-throttle
dummy example usage:
reminder: use name_space to avoid possible conflict on the same key
import time
from limiter import FixedWindowLimiter
TEST_REDIS_CONFIG = {'host': 'localhost','port': 6379,'db': 10}
ip = "who are you?"
throttle = FixedWindowLimiter(threshold=2, interval=3, redis_config=TEST_REDIS_CONFIG, name_space="default")
print("first time, blocked?: {}".format(throttle.exceeded(ip)))
print("second time, blocked?: {}".format(throttle.exceeded(ip)))
print("now I block you, blocked?: {}".format(throttle.exceeded(ip)))
time.sleep(3)
print("refill energy, blocked?: {}".format(throttle.exceeded(ip)))
ouput:
first time blocked?: False
second time blocked?: False
now I block you blocked?: True
refill energy blocked?: False
dummy beach mark
It is from my unittest and not accurate,
rate_counter_pressure_test: SlidingRedisCounter
rate_counter_pressure_test: SlidingRedisCounter time count: 1.0075314449495636
rate_counter_pressure_test: FixedWindowRedisCounter
rate_counter_pressure_test: FixedWindowRedisCounter time count: 0.13711917598266155
Metadata
Release files for python-throttle 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python-throttle-0.2.0.tar.gz | 4.9 kB | Without provenance | Details for python-throttle-0.2.0.tar.gz |
Release files / python-throttle-0.2.0.tar.gz
| Download URL | python-throttle-0.2.0.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9fe5016cf0b5db6884b02e9f6923cb6d4864c477af8b751daa3bd686debbff4e
|
|
BLAKE2b-256 checksum How to use checksums |
1372f6a7ef6cc6c1450c132ff25796ab6240f223b3fb797866cbf8c26f721aa2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3
|
Security for python-throttle 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.