Skip to main content

Rate Limit

this package help you to limit the call's [frequent] rates of any callable in python.

Usage

basic usage

from src.rlimit import Limiter, Per
from time import sleep


@Limiter(times=2, per=2 * Per.SECOND)
def func_a():
    return True


func_a()  # True
func_a()  # True
func_a()  # OverflowError
sleep(2)
func_a()  # True
func_a()  # True
func_a()  # OverflowError

key example

from src.rlimit import Limiter, Per


@Limiter(
    times=2, per=2 * Per.SECOND,
    key=lambda name, age: str(hash((name, age)))
)
def func_a(name: str, age: int):
    return f'hi2{name}-{age}'


func_a('gzuz', 13)
func_a('gzuz', 14)
func_a('gzuz', 13)
func_a('gzuz', 15)
func_a('gzuz', 14)
func_a('gzuz', 14)  # OverflowError
func_a('gzuz', 13)  # OverflowError

fastapi

from src.rlimit import Limiter, Per
from fastapi import APIRouter, HTTPException, Request

router = APIRouter(...)


@router.get(...)
@Limiter(
    times=2, per=4 * Per.SECOND,
    key=lambda r: r.client.host,
    exception=HTTPException(429)
)
def test_ratelimit(request: Request):
    return 'no limit'

Install

pip install git+https://github.com/omidekz/rlimit

pypi will add


Custom Memory

to implement new memory class, you have to extend BaseMemory abstract class

Metadata

Release files for rlimit 1.5

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

Source distribution (sdist)

Source distribution for rlimit 1.5
File Size Uploaded Provenance Actions
rlimit-1.5.tar.gz 15.1 kB Without provenance Details for rlimit-1.5.tar.gz

Built distribution (wheel)

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

Total release size: 31.1 kB

Release files / rlimit-1.5.tar.gz

Download URL rlimit-1.5.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
41cfb7f2918ce2daabeb87086443d60b68ada1079f303e9777c99c4e5fdea48b
BLAKE2b-256 checksum
How to use checksums
18bf35723971368311025569612d498d4acf5df9c0d0adce5451e9e96baf2ba6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / rlimit-1.5-py3-none-any.whl

Download URL rlimit-1.5-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d1a36b6719de25cd2399c65a45811218d52ef0d1847921d2771bee97100c4aea
BLAKE2b-256 checksum
How to use checksums
f31ad87fa0bc6c94498ac6ee24176d5b48c66fb4e342c0da910e1908effcfc35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Security for rlimit 1.5

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

1.5 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