Skip to main content

No project description provided

Project description

Simple Token Bucket

Documentation PyPI GitHub

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

https://simple-token-bucket.readthedocs.io/en/latest/

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

simple_token_bucket-0.1.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

simple_token_bucket-0.1.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file simple_token_bucket-0.1.1.tar.gz.

File metadata

  • Download URL: simple_token_bucket-0.1.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.24.1

File hashes

Hashes for simple_token_bucket-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e8c423c68c7a9d4a3d726bfd36f8cdee656d3f2f70b886f7a7c35ee458e87843
MD5 2e3410486e222a276d640c34f767e794
BLAKE2b-256 23ea64ea86ec84ba543a274699ddaaae1c90e6086340022f985556ec024aafc0

See more details on using hashes here.

File details

Details for the file simple_token_bucket-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_token_bucket-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 36c9336ae0b975ff0fb1e91376a9abffeadec65388fed8a3f3a23ea89b007095
MD5 ddccf028ae075059a30d8b3b87d82672
BLAKE2b-256 1bea0d3311ea9993b84345ef1f7a90d60a725bbb6f51a230aa04d4177e5512e0

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