Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

limitry

The Limitry Python SDK puts a limit around costly work in a with block: guard checks before the block runs, and reserve reserves what the work will probably cost, then charges what it actually cost. Every API operation is a typed method too, sync or async.

A $2 AI budget for one of your users: three calls are charged, and the next is refused before the AI runs.

▶ Watch the 44-second demo

Limitry is the limits, credits and budgets layer for the software you build: give each of your users, teams, tenants, API keys or agents an allowance, and before any costly request one call tells your code whether it may happen.

Install

pip install limitry

Needs Python 3.10 or later. Set LIMITRY_API_KEY to a key from Settings → Developers in the app. Use a test key (lim_test_…) while you build. To pass the key yourself, use Limitry(api_key=key).

Charge what it actually cost

Say each of your users has a $2 AI budget a month, counted in cents. You only know what a reply cost once it's done. reserve holds what it will probably cost (5 cents here), runs the block, then charges what it actually cost. If the block raises, reserve gives the hold back:

from limitry import Limitry

limitry = Limitry()  # reads LIMITRY_API_KEY

with limitry.reserve(
    subject={"kind": "user", "id": "user_123"}, action="ai-call", cost=5
) as reservation:
    response = call_model(prompt)
    reservation.cost = price_cents(response.usage)  # your prices, in cents

Each hold counts until it's charged, so two replies at once can't overspend.

Guard work that always costs the same

When every request costs the same, guard is simpler. It checks the limit, then runs the block only if it's allowed. Here it counts one request to your API against a limit of 60 a minute for each key:

from limitry import LimitReachedError, Limitry

limitry = Limitry()  # reads LIMITRY_API_KEY

try:
    with limitry.guard(subject={"kind": "apikey", "id": "key_42"}, action="api-request"):
        response = handle_request(request)
except LimitReachedError as error:
    print(f"Try again in {error.retry_after_seconds} seconds")

A refusal raises LimitReachedError. If Limitry can't answer within timeout (1.5 seconds by default), each limit's fail mode decides: open lets the work run, and closed raises UnavailableError. Both errors are a LimitryError.

Everything else

Every API operation is a typed method, named like its CLI command: limitry limits create is limitry.limits.create(). For asyncio, use AsyncLimitry.

from limitry import Limitry

limitry = Limitry()

# "200 cents per user per month for ai-call"
limitry.limits.create(
    subject={"kind": "user"},
    action="ai-call",
    amount=200,
    unit="cents",
    window="month",
)

A failure raises an APIError subclass for its status, such as NotFoundError, with the error's code, message, status_code and request_id.

Contributing

This repository is generated from Limitry's source on each release, so pull requests are ported there and credited (see CONTRIBUTING.md).

License

Licensed under the Apache License 2.0.

Metadata

Release files for limitry 1.0.0rc18

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

Source distribution (sdist)

Source distribution for limitry 1.0.0rc18
File Size Uploaded Provenance Actions
limitry-1.0.0rc18.tar.gz 53.4 kB With provenance Details for limitry-1.0.0rc18.tar.gz

Built distribution (wheel)

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

Total release size: 113.0 kB

Release files / limitry-1.0.0rc18.tar.gz

Download URL limitry-1.0.0rc18.tar.gz
Size 53.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1829e13c2d33683b804773ff0e04dc67821e1a135ce48436a7b53940dd487f11
BLAKE2b-256 checksum
How to use checksums
1c805002408c31510d58725cd000384beab54ec2b4da5579911a20fdf2ca30e0
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 Nov 22, 2026.

Transparency log

Release files / limitry-1.0.0rc18-py3-none-any.whl

Download URL limitry-1.0.0rc18-py3-none-any.whl
Size 59.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4cff1aa39f8675684852d60c97da81cc8150b98c35ffdacb1fed00dfaa104b4
BLAKE2b-256 checksum
How to use checksums
f64c4ff1a0cda71cddf2d64618d5cf132720b5e7809e9670272f2f759fbaba1a
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 Nov 22, 2026.

Transparency log

Security for limitry 1.0.0rc18

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 limitry-1.0.0rc18.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 22, 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