Skip to main content

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 window
  • X-RateLimit-Remaining: Requests remaining in current window
  • X-RateLimit-Reset: Seconds until window resets
  • Retry-After: Seconds to wait on 429 responses

See Also

  • Backend standards: backend.md Rate Limiting
  • Flask extensions pattern: Similar to Flask-Security-Too, Flask-Limiter

Metadata

Release files for penguin-limiter 0.1.0

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

Source distribution (sdist)

Source distribution for penguin-limiter 0.1.0
File Size Uploaded
penguin_limiter-0.1.0.tar.gz 24.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for penguin-limiter 0.1.0
File Interpreter ABI Platform
penguin_limiter-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 47.8 kB

Release files / penguin_limiter-0.1.0.tar.gz

Download URL penguin_limiter-0.1.0.tar.gz
Size 24.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5b594a76cd41b71fc8d853d627e568cb46a9545f385741ab2ceeb213da31ba17
BLAKE2b-256 checksum
How to use checksums
97faea42e9f0dcecbdfda41fe99ea7851d4e421ac66ca92f3f8ce86a3038f3a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 6, 2026.

Transparency log

Release files / penguin_limiter-0.1.0-py3-none-any.whl

Download URL penguin_limiter-0.1.0-py3-none-any.whl
Size 23.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0bcb0efb90d1b33f8b16fa76cb961a0bb432b1a2ce36a7d01e18b0234cb6f85c
BLAKE2b-256 checksum
How to use checksums
116c4a4aa9a6481dc5b7ca8702b9653d20c29b2ed383deeca94e7badb1527525
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 6, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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