No project description provided
Project description
Simple Token Bucket
A simple token bucket implementation.
Project philosophy
simple-token-bucket
is meant to be a light and very simple to use
token bucket library. Simple is better than
complex.
Installation
simple-token-bucket
is available on PyPI:
python -m pip install simple-token-bucket[redis]
This project requires Python 3.8 or newer to run.
Usage example
from simple_token_bucket import SimpleTokenBucket
from simple_token_bucket.backends.redis import RedisBackend
# Create a new bucket
third_party_api_rate_limit_bucket = SimpleTokenBucket(
name="third_party_api",
bucket_size=3,
interval=10,
backend=RedisBackend.from_url("redis://localhost:6379/0")
)
third_party_api_rate_limit_bucket.try_get_token()
third_party_api_rate_limit_bucket.try_get_token()
third_party_api_rate_limit_bucket.try_get_token()
# will raises a NotEnoughTokens exception.
third_party_api_rate_limit_bucket.try_get_token()
# after 10 seconds everything works again.
import time
time.sleep(10)
third_party_api_rate_limit_bucket.try_get_token()
The latest documentation can be found here
Contributing
Contributions are welcome. See Contributing section in docs.
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
Built Distribution
File details
Details for the file simple_token_bucket-0.1.2.tar.gz
.
File metadata
- Download URL: simple_token_bucket-0.1.2.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fa12a70f9df2479b1be964f7221375f418ab45b613176c87d8dbf47e2c36191 |
|
MD5 | 3c63af2fd75ac2b6c54b2a455c7d5c16 |
|
BLAKE2b-256 | a53bcac5eec1a116c10901fce24cb436c5f69808cb0235c7474bc4ee654c7634 |
File details
Details for the file simple_token_bucket-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: simple_token_bucket-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d96fc44b7d0060a8f9282847753b62fa486e6401634da8c78df1606b94a1fbb7 |
|
MD5 | 8cd0c9b0e82a0bcc9cbfacd5e4097c01 |
|
BLAKE2b-256 | 55c2ca7abfda88a0553895c9f1afb59bd68d962ac0cb86b0c58c12973afda736 |