penguin-limiter
Rate limiting middleware for Penguin Tech Python applications.
Features
- Flask extension with decorator-based route limiting
- Token bucket rate limiting algorithm
- In-process memory storage with LRU eviction
- Redis-backed storage for distributed systems
- Configurable rate limits (per second, minute, hour, day)
- Thread-safe implementation
- Standard HTTP rate limit headers
Installation
pip install penguin-limiter
# With Redis support:
pip install 'penguin-limiter[redis]'
Quick Start
from flask import Flask
from penguin_limiter import FlaskRateLimiter, MemoryStorage, RateLimitConfig
app = Flask(__name__)
# Create rate limiter with 100 requests per hour
limiter = FlaskRateLimiter(
config=RateLimitConfig.from_string("100/hour"),
storage=MemoryStorage(),
)
limiter.init_app(app)
@app.route("/api/endpoint")
@limiter.limit()
def my_endpoint():
return {"message": "success"}
Configuration
Using RateLimitConfig
# Parse from string
config = RateLimitConfig.from_string("100/hour")
# Or create directly
from penguin_limiter import RateLimitConfig
config = RateLimitConfig(rate=100, unit="hour")
Supported units: second, minute, hour, day
Storage Options
Memory Storage (Default)
from penguin_limiter import MemoryStorage
storage = MemoryStorage(max_entries=10000)
Redis Storage
from penguin_limiter import RedisStorage
storage = RedisStorage(url="redis://localhost:6379/0")
API Reference
FlaskRateLimiter
limiter = FlaskRateLimiter(
config=RateLimitConfig.from_string("100/hour"),
storage=MemoryStorage(),
key_func=lambda: request.remote_addr # Optional custom key function
)
Decorating Routes
# Use default limit
@app.route("/api/users")
@limiter.limit()
def get_users():
return []
# Override limit for specific route
@app.route("/api/expensive")
@limiter.limit(RateLimitConfig.from_string("10/hour"))
def expensive_operation():
return {}
Rate Limit Headers
Standard X-RateLimit headers are added to all responses:
X-RateLimit-Limit: Maximum requests in windowX-RateLimit-Remaining: Requests remaining in current windowX-RateLimit-Reset: Seconds until window resetsRetry-After: Seconds to wait on 429 responses
See Also
- Backend standards:
backend.mdRate Limiting - Flask extensions pattern: Similar to Flask-Security-Too, Flask-Limiter
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file penguin_limiter-0.1.0.tar.gz.
File metadata
- Download URL: penguin_limiter-0.1.0.tar.gz
- Upload date:
- Size: 24.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b594a76cd41b71fc8d853d627e568cb46a9545f385741ab2ceeb213da31ba17
|
|
| MD5 |
178de079dc3ce4db815c830b28a7df45
|
|
| BLAKE2b-256 |
97faea42e9f0dcecbdfda41fe99ea7851d4e421ac66ca92f3f8ce86a3038f3a9
|
Provenance
The following attestation bundles were made for penguin_limiter-0.1.0.tar.gz:
Publisher:
publish.yml on penguintechinc/penguin-libs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
penguin_limiter-0.1.0.tar.gz -
Subject digest:
5b594a76cd41b71fc8d853d627e568cb46a9545f385741ab2ceeb213da31ba17 - Sigstore transparency entry: 2362118288
- Sigstore integration time:
-
Permalink:
penguintechinc/penguin-libs@e470cb66cc14bd31fda36dd898c1c9bf9dacaeba -
Branch / Tag:
refs/heads/release/python-limiter/v0.1.x - Owner: https://github.com/penguintechinc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e470cb66cc14bd31fda36dd898c1c9bf9dacaeba -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file penguin_limiter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: penguin_limiter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 23.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bcb0efb90d1b33f8b16fa76cb961a0bb432b1a2ce36a7d01e18b0234cb6f85c
|
|
| MD5 |
2a7c65d37e00d64d5aae3a1c7a646c94
|
|
| BLAKE2b-256 |
116c4a4aa9a6481dc5b7ca8702b9653d20c29b2ed383deeca94e7badb1527525
|
Provenance
The following attestation bundles were made for penguin_limiter-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on penguintechinc/penguin-libs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
penguin_limiter-0.1.0-py3-none-any.whl -
Subject digest:
0bcb0efb90d1b33f8b16fa76cb961a0bb432b1a2ce36a7d01e18b0234cb6f85c - Sigstore transparency entry: 2362118290
- Sigstore integration time:
-
Permalink:
penguintechinc/penguin-libs@e470cb66cc14bd31fda36dd898c1c9bf9dacaeba -
Branch / Tag:
refs/heads/release/python-limiter/v0.1.x - Owner: https://github.com/penguintechinc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e470cb66cc14bd31fda36dd898c1c9bf9dacaeba -
Trigger Event:
workflow_dispatch
-
Statement type: