A wrapper engine to enforce request-based, token-based, and concurrency-based limits on kani engines.
Project description
kani-ratelimits
This is a simple, small package to to enforce request-per-minute (RPM), token-per-minute (TPM), and/or max-concurrency ratelimits before making requests to an underlying engine.
Installation
pip install kani-ratelimits
Usage
from kani.ext.ratelimits import RatelimitedEngine
# limit requests to 10 req/min and 30k tokens/min
inner_engine = ... # your engine here, e.g. `OpenAIEngine(..., model="gpt-4")`
engine = RatelimitedEngine(inner_engine, rpm_limit=10, tpm_limit=30_000)
The RatelimitedEngine takes the following parameters:
engine: The engine to wrap.max_concurrency(int): The maximum number of concurrent requests to serve at once (default unlimited).rpm_limit(float): The maximum number of requests to serve per rpm_period (default unlimited).rpm_period(float): The duration, in seconds, of the time period in which to limit the rate. Note that up to rpm_limit requests are allowed within this time period in a burst (default 60s).tpm_limit(float): The maximum number of tokens to send in requests per tpm_period (default unlimited).tpm_period(float): The duration, in seconds, of the time period in which to limit the rate. Note that up to tpm_limit tokens are allowed within this time period in a burst (default 60s).
The ratelimiter will ensure that all conditions are met before forwarding the request to the wrapped engine.
Project details
Release history Release notifications | RSS feed
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 kani_ratelimits-1.1.0.tar.gz.
File metadata
- Download URL: kani_ratelimits-1.1.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e90e14e54eb55698ca941391cfe7eea0a03089083f7e53fb58e2bb832da4615c
|
|
| MD5 |
f7804720709f287e9ce4f3f9e10b18e2
|
|
| BLAKE2b-256 |
2a729b0e4294508dda11a4ba9b3c72b270afb240cdd5a54e7b88b373c68bcf42
|
Provenance
The following attestation bundles were made for kani_ratelimits-1.1.0.tar.gz:
Publisher:
pythonpublish.yml on zhudotexe/kani-ratelimits
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kani_ratelimits-1.1.0.tar.gz -
Subject digest:
e90e14e54eb55698ca941391cfe7eea0a03089083f7e53fb58e2bb832da4615c - Sigstore transparency entry: 656672110
- Sigstore integration time:
-
Permalink:
zhudotexe/kani-ratelimits@7ac66ca50c044602a3d3936c176e654deb0ab14b -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/zhudotexe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pythonpublish.yml@7ac66ca50c044602a3d3936c176e654deb0ab14b -
Trigger Event:
release
-
Statement type:
File details
Details for the file kani_ratelimits-1.1.0-py3-none-any.whl.
File metadata
- Download URL: kani_ratelimits-1.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f42124a84ebc1e0d9ba451bd3432ee1554bc21f11d9f522b200a96ceef857187
|
|
| MD5 |
b4f168959de71d14513e6bd0aa9d1f03
|
|
| BLAKE2b-256 |
52ab33f50ff5da8c4be55443f956e4475577d95dce2cb1d5487f0a14d5671c64
|
Provenance
The following attestation bundles were made for kani_ratelimits-1.1.0-py3-none-any.whl:
Publisher:
pythonpublish.yml on zhudotexe/kani-ratelimits
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kani_ratelimits-1.1.0-py3-none-any.whl -
Subject digest:
f42124a84ebc1e0d9ba451bd3432ee1554bc21f11d9f522b200a96ceef857187 - Sigstore transparency entry: 656672115
- Sigstore integration time:
-
Permalink:
zhudotexe/kani-ratelimits@7ac66ca50c044602a3d3936c176e654deb0ab14b -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/zhudotexe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pythonpublish.yml@7ac66ca50c044602a3d3936c176e654deb0ab14b -
Trigger Event:
release
-
Statement type: