Skip to main content

omnilimit for Python

Rate limiting that behaves the same across stacks, and proves it. This port follows the same spec and passes the same conformance vectors as the TypeScript one, and both can share a counter in Redis or Postgres.

  • Trusted client IPs. It reads X-Forwarded-For from the right. Rotating the header does not evade the limit.
  • An explicit failure mode. You must decide, per limiter, what happens when the store is down.
  • No dependencies. Extras only install a client: omnilimit[redis], omnilimit[postgres], omnilimit[fastapi].
pip install omnilimit

Usage

from redis import Redis

from omnilimit import Limiter
from omnilimit.stores.redis import RedisStore

client = Redis.from_url(url, socket_timeout=0.25, socket_connect_timeout=0.25)
limiter = Limiter(
    store=RedisStore(client),
    scope="login",
    limit=5,
    window_ms=60_000,
    burst=2,
    on_store_error="closed",  # required: "open" lets requests through, "closed" answers 503
)

decision = limiter.check(user_id)
if not decision.allowed:
    ...  # answer decision.status with decision.headers, which include Retry-After

5 per minute with burst 5 can admit 9 requests in one minute: this is a rate, not a counter that resets. Lower burst if you need fewer.

Sync or async

Code Limiter Stores
Flask, Django, def dependencies Limiter MemoryStore, RedisStore, PostgresStore
async def AsyncLimiter MemoryStore, AsyncRedisStore, AsyncPostgresStore

Limiter runs each store call in its own daemon thread, because Python cannot abandon a blocking call. store_timeout_ms bounds the request, and max_store_threads bounds the calls in flight. Set socket timeouts on your client as well, so a hung call ends.

redis-py caps its pool and raises past that cap, which omnilimit reports as a store failure. If you expect bursts of concurrent checks, use BlockingConnectionPool.

FastAPI

from fastapi import Depends, FastAPI

from omnilimit import MemoryStore, Limiter
from omnilimit.fastapi import ip_key, rate_limit

limiter = Limiter(
    store=MemoryStore(), scope="api", limit=100, window_ms=60_000, on_store_error="open"
)
app = FastAPI(dependencies=[
    Depends(rate_limit(limiter, key=ip_key(preset="cloud-run"), on_missing_key="shared")),
])

Denials raise HTTPException, so your own handlers format them. Headers on allowed requests are not added when a route returns its own Response object, as a file download usually does.

Client IP only

omnilimit.ip uses only the standard library and also works next to slowapi:

from omnilimit.ip import resolve_client_ip

ip = resolve_client_ip(request.headers, request.client.host, preset="cloud-run-lb")

It returns None rather than guessing. Check that the preset matches your deployment: see client IP.

Postgres

omnilimit.stores.postgres.MIGRATION_SQL creates the table and functions: apply it with your migration tool. Stores take a psycopg 3 pool or a connection with autocommit=True. Each hit is a write, so it is not meant for high traffic, and cleanup() is yours to schedule.

Metadata

Release files for omnilimit 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 omnilimit 0.1.1
File Size Uploaded Provenance Actions
omnilimit-0.1.1.tar.gz 118.2 kB With provenance Details for omnilimit-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 138.4 kB

Release files / omnilimit-0.1.1.tar.gz

Download URL omnilimit-0.1.1.tar.gz
Size 118.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7d85b134359c34f1919b1fffd37dbfc08f6275e0acc81caa9ce56da3f9fd7be5
BLAKE2b-256 checksum
How to use checksums
0d14cf34de2e3dd3a21bf84c3d0829cddcf3ba351cd60ccde5fa37ae438d342d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 6, 2026.

Transparency log

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

Download URL omnilimit-0.1.1-py3-none-any.whl
Size 20.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e86f70a45673e90644cf43753c8cb1a7a098ffb213dab9134bbf9d3c8c41a14a
BLAKE2b-256 checksum
How to use checksums
51e94886f9de8bfada390110b86a2af5519f65e2a07dc0bb3208b9f6c90381bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 6, 2026.

Transparency log

Security for omnilimit 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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for omnilimit-0.1.1.tar.gz

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 Nov 6, 2026.

Transparency log

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.

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