Skip to main content

Very fast implementation of the token bucket algorithm.

Project description

Build Status PyPi codecov.io

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.3.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

token_bucket-0.3.0-py2.py3-none-any.whl (9.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file token_bucket-0.3.0.tar.gz.

File metadata

  • Download URL: token_bucket-0.3.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.2

File hashes

Hashes for token_bucket-0.3.0.tar.gz
Algorithm Hash digest
SHA256 979571c99db2ff9e651f2b2146a62b2ebadf7de6c217a8781698282976cb675f
MD5 111c6213775be10e01196b75d862e3ae
BLAKE2b-256 b76d386ed0cfb7f3c2e0311a96b3884a2ba98a7b958344f51c7cce0b1c7bbb0f

See more details on using hashes here.

File details

Details for the file token_bucket-0.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: token_bucket-0.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.2

File hashes

Hashes for token_bucket-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6df24309e3cf5b808ae5ef714a3191ec5b54f48c34ef959e4882eef140703369
MD5 e242207ee93a8ff65b8dbd1a2a4af891
BLAKE2b-256 4bce61ee52521766059d2c2537e85ba5f9773313e74b86df14652a61dd2e990e

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