Limitr for Python
Usage and margin control for AI products: limits, credits, and billing decided inside your app. Limitr is an open-source engine that runs in-process and decides every call for each customer: what they can do, what it costs you, and what to bill. Plans, credits, limits, costs, and contract terms live in one policy, so changing pricing is a policy change, not a migration.
pip install limitr
Quick start
from limitr import Limitr
policy = Limitr("""
policy: {
credits: {
request: { label: 'Request' }
ai_token: { label: 'AI token', price: { amount: 0.00002 } }
}
plans: {
free: {
default: true
entitlements: {
api: { limit: { credit: 'request', mode: 'hard', value: 1000, resets: true } }
chat: { limit: { credit: 'ai_token', mode: 'hard', value: 100_000, resets: true } }
}
}
}
}
""")
policy.ensure_customer('ada')
if policy.allow('ada', 'api', 1): # decide and count
...
d = policy.check('ada', 'api', 5000, detail=True)
if not d['allowed']:
print(d['reason'], d['remaining'], d['resets']) # Ex. 'limit' 999 1796083200000
Policies can also be YAML, JSON, or TOML (Limitr(text, 'yaml')) or a dict.
LLM calls: reserve, then settle
A call's size is only known when it's done, and calls run at the same time. Hold room first, then record what the call really used:
hold = policy.reserve('ada', 'chat', 4096) # or leave the value out to hold the predicted size
if not hold:
return 'out of tokens'
res = client.messages.create(model=model, max_tokens=4096, messages=messages)
policy.settle('ada', 'chat', hold, res.usage.input_tokens + res.usage.output_tokens,
{'model': model, 'input': res.usage.input_tokens, 'output': res.usage.output_tokens})
Events and state
policy.add_handler('billing', lambda name, event: print(name, event)) # objects arrive as dicts
saved = policy.customers() # all customer state: store it anywhere
restored = Limitr(policy_source)
restored.load_customers(saved)
Event handlers run during the call that sent the event, so don't call the policy from one; queue the work instead.
Notes
- Every method is one engine call, run one at a time (a lock guards the document), so a single
allowis safe across threads. Usereserveandsettlewhen concurrent calls must not overspend together. - Method names match the TypeScript SDK in snake_case (
ensureCustomerisensure_customer), and options are keyword arguments (allow(customer, entitlement, value, detail=True)). - This release is the engine. Limitr Cloud (live policy changes, ledgers, invoices, Limitr Analyst) comes next.
Docs: limitr.dev. Policy semantics: the policy reference. Source: github.com/dev-formata-io/limitr. Apache 2.0.
Metadata
Release files for limitr 0.8.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| limitr-0.8.6.tar.gz | 121.6 kB | With provenance | Details for limitr-0.8.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| limitr-0.8.6-py3-none-any.whl | Python 3 | none | any | Details for limitr-0.8.6-py3-none-any.whl |
Total release size: 247.3 kB
Release files / limitr-0.8.6.tar.gz
| Download URL | limitr-0.8.6.tar.gz |
|---|---|
| Size | 121.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5571a620598dd0953860abfc2d888a45d93ed6165abaeac9582d4f04ee243542
|
|
BLAKE2b-256 checksum How to use checksums |
806ccee5eb4ddf551036eb98111c3ea625f137d3ab00314a8bf56cbc7bc829a3
|
| 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 16, 2026.
Transparency logRelease files / limitr-0.8.6-py3-none-any.whl
| Download URL | limitr-0.8.6-py3-none-any.whl |
|---|---|
| Size | 125.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7c13fd7dc1b7195e00388eb5294e2db863254cf6adcbe0f46f35bbaccbd6f742
|
|
BLAKE2b-256 checksum How to use checksums |
65e51e158e9611892937a82242dda42f8931ec646a6a422bcc2284d7aad26239
|
| 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 16, 2026.
Transparency logSecurity for limitr 0.8.6
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.
Attestation for limitr-0.8.6.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 16, 2026.
Transparency logA 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.