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.
Metadata
Release files for simple-token-bucket 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 |
|---|---|---|---|---|
| simple_token_bucket-0.2.0.tar.gz | 5.5 kB | Without provenance | Details for simple_token_bucket-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simple_token_bucket-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for simple_token_bucket-0.2.0-py3-none-any.whl |
Total release size: 10.0 kB
Release files / simple_token_bucket-0.2.0.tar.gz
| Download URL | simple_token_bucket-0.2.0.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
83710d5fce3c2678334fd43ba45ccf3eb339c9c7fdf9d1fd0a057df41439cf60
|
|
BLAKE2b-256 checksum How to use checksums |
0ff7f81fa26a4197af5513df44f0f63d5646fadc96d2270efe52d9d46e0472c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.27.0
|
Release files / simple_token_bucket-0.2.0-py3-none-any.whl
| Download URL | simple_token_bucket-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9558bde377a07b6733f09d1c326d5fcef9976ad718a08874d2cc2a00d259fedc
|
|
BLAKE2b-256 checksum How to use checksums |
232e152325179ae5f24a182c6ef1a9adeccd9943e5b18cd1322bf91e6f9c9217
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.27.0
|
Security for simple-token-bucket 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.