Skip to main content

Very fast implementation of the token bucket algorithm.

Project description

tests PyPI python-versions codecov

A Token Bucket Implementation for Python Web Apps

The token-bucket package provides an implementation of the token bucket algorithm suitable for use in web applications for shaping or policing request rates. This implementation does not require the use of an independent timer thread to manage the bucket state.

Compared to other rate-limiting algorithms that use a simple counter, the token bucket algorithm provides the following advantages:

  • The thundering herd problem is avoided since bucket capacity is replenished gradually, rather than being immediately refilled at the beginning of each epoch as is common with simple fixed window counters.

  • Burst duration can be explicitly controlled.

Moving window algorithms are resistant to bursting, but at the cost of additional processing and memory overhead vs. the token bucket algorithm which uses a simple, fast counter per key. The latter approach does allow for bursting, but only for a controlled duration.

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

token_bucket-0.4.0rc1.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

token_bucket-0.4.0rc1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file token_bucket-0.4.0rc1.tar.gz.

File metadata

  • Download URL: token_bucket-0.4.0rc1.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for token_bucket-0.4.0rc1.tar.gz
Algorithm Hash digest
SHA256 df6ab604642fff4b64080cc15f557e6d6c0b89f6f77f5b0908ed414348df48c3
MD5 0dca4dc1a351969ffb79a6620fe3036f
BLAKE2b-256 49f868b8b37eb35be975350fcd17ba2a68bf69cbed1a7954dfb6175a277e76a2

See more details on using hashes here.

File details

Details for the file token_bucket-0.4.0rc1-py3-none-any.whl.

File metadata

File hashes

Hashes for token_bucket-0.4.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 971adf00f8d72b1d34d97a506b7e41cb7d3208cfa1d0c5018fe9ecb0c814869b
MD5 0af24176c14b44d3d9876a141a65ed48
BLAKE2b-256 6ebe18731e270160991c03a8879d0fc517c53daa3efa64957e7bcab3f40585b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page