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.0.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.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: token_bucket-0.4.0.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.0.tar.gz
Algorithm Hash digest
SHA256 80f94bbe85be8f5adccd51330c26d07e6efdf6e154657cf107f7e65ce510d886
MD5 7351c6ae38f037eb2d321fc5982c049a
BLAKE2b-256 8d17bf09fd3373ff3098151978ca2abde0b125589459a4724885731f7f877c0c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: token_bucket-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for token_bucket-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 16a90125a696b9e22e3e2f20ea9060a5abf07572bf91500142e3b3747d30e568
MD5 71cdcb69734255d1b0240d86baa2e0b1
BLAKE2b-256 c6850a9e1f712f1be611f6ca9db2849925c483bcda41674412013e27e3fcd0a0

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