Skip to main content

rate-limiter

A simple, easy-to-use rate limiter package for Python projects.

Features

  • Fixed window limiter
  • Sliding window log limiter
  • Sliding window counter limiter
  • Leaky bucket limiter
  • Token bucket limiter
  • In-memory storage
  • Optional Redis storage
  • Basic metrics collector
  • Docker-based local monitoring setup with Prometheus and Grafana

Installation

Install from the current directory:

pip install .

Install directly from GitHub:

pip install git+https://github.com/Aniket281004/rate-limiter.git

Quick start

from rate_limiter import RateLimitConfig, create_rate_limiter

config = RateLimitConfig(limit=100, window=60)
limiter = create_rate_limiter(config)

result = limiter.allow("user-123")
if result.allowed:
    print("Request allowed")
else:
    print("Rate limit exceeded")

Available algorithms

Fixed window

from rate_limiter import FixedWindowRateLimiter, RateLimitConfig

limiter = FixedWindowRateLimiter(RateLimitConfig(limit=10, window=60))

Sliding window log

from rate_limiter import SlidingWindowLogRateLimiter, RateLimitConfig

limiter = SlidingWindowLogRateLimiter(RateLimitConfig(limit=10, window=60))

Sliding window counter

from rate_limiter import SlidingWindowCounterRateLimiter, RateLimitConfig

limiter = SlidingWindowCounterRateLimiter(RateLimitConfig(limit=10, window=60))

Leaky bucket

from rate_limiter import LeakyBucketRateLimiter, RateLimitConfig

limiter = LeakyBucketRateLimiter(RateLimitConfig(limit=10, window=60))

Token bucket

from rate_limiter import TokenBucketRateLimiter, RateLimitConfig

limiter = TokenBucketRateLimiter(RateLimitConfig(limit=10, window=60))

Redis storage

Install the Redis client:

pip install redis

Example:

from rate_limiter import RateLimitConfig, SlidingWindowLogRateLimiter
from rate_limiter.storage import RedisStorage

storage = RedisStorage(host="localhost", port=6379, db=0)
limiter = SlidingWindowLogRateLimiter(RateLimitConfig(limit=10, window=60), storage=storage)

Metrics

The package includes a simple collector that tracks allowed and denied requests:

from rate_limiter.metrics.collector import MetricsCollector

collector = MetricsCollector()
collector.record_request(allowed=True)
collector.record_request(allowed=False)
print(collector.snapshot())

Docker and monitoring

Run the local monitoring stack:

docker compose up --build -d

This starts:

  • the app on port 8000
  • Prometheus on port 9090
  • Grafana on port 3000

Testing

Run the test suite:

pytest -q

The current test suite covers:

  • fixed window behavior
  • sliding window log behavior
  • sliding window counter behavior
  • leaky bucket behavior
  • token bucket behavior
  • metrics collection

Metadata

Release files for aniket-rate-limiter 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aniket-rate-limiter 0.1.1
File Size Uploaded Provenance Actions
aniket_rate_limiter-0.1.1.tar.gz 7.3 kB Without provenance Details for aniket_rate_limiter-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aniket-rate-limiter 0.1.1
File Interpreter ABI Platform Actions
aniket_rate_limiter-0.1.1-py3-none-any.whl Python 3 none any Details for aniket_rate_limiter-0.1.1-py3-none-any.whl

Total release size: 21.0 kB

Release files / aniket_rate_limiter-0.1.1.tar.gz

Download URL aniket_rate_limiter-0.1.1.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6d2584cd9bb6d01a5b22e76f5dfc0a2ecec48dca92eb84e5cd5c05865ca45ae8
BLAKE2b-256 checksum
How to use checksums
3394922dec54a338783f8b3be316b8d91fde0371f7a6012cf25e23396378b535
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Release files / aniket_rate_limiter-0.1.1-py3-none-any.whl

Download URL aniket_rate_limiter-0.1.1-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a4c6cd9470c21b6d92f26385cead9a459433464fee626347f0c82340bfc891c
BLAKE2b-256 checksum
How to use checksums
c3838578e00f66d76ecc0ea946939d00a4df7ecfabd7ed19761e7fde685cc9d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Security for aniket-rate-limiter 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page