Skip to main content

A simple Token Bucket rate limiter for Python.

Project description

Token Bucket Limiter

A simple, thread-safe Token Bucket rate limiter for Python.

Installation

pip install token-bucket-limiter

Usage

Basic Usage

from token_bucket_limiter import TokenBucket

# 10 tokens max, refill 2 tokens every 1 second
limiter = TokenBucket(max_tokens=10, refill_rate=2, interval=1.0)

if limiter.allow_request():
    print("Request allowed!")
else:
    print("Rate limit exceeded.")

Rate Limiter Store (Per-user/IP)

from token_bucket_limiter import RateLimiterStore

store = RateLimiterStore(max_tokens=10, refill_rate=2, interval=1.0)

# Get or create a bucket for a specific user
user_bucket = store.get_bucket("user_123")
if user_bucket.allow_request():
    # Process request
    pass

License

MIT

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_limiter-0.1.0.tar.gz (4.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_limiter-0.1.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file token_bucket_limiter-0.1.0.tar.gz.

File metadata

  • Download URL: token_bucket_limiter-0.1.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for token_bucket_limiter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5151795ccf5a40e10c29375080350d4a0212af232ecab8bf3632f20dc922c4ae
MD5 91b464c356845d28a539e70b7a57c72f
BLAKE2b-256 c36b8bbc2ac58608102c73dea3066c80a1cacdf0a19614d9b7995ae2043b570b

See more details on using hashes here.

File details

Details for the file token_bucket_limiter-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for token_bucket_limiter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8bc742020f65effa76af302fc3e8b4ce5824cd815ab281abcceba1caa6d9daf
MD5 749645049df401115dbff8b55b28c1e3
BLAKE2b-256 703e69687bb8db849691793b637feaf556622912c0e1f56e7fbbbb53229008e2

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