Skip to main content

Typed Python client for the Detent rate-limiting API.

Project description

detent-sdk

Typed Python client for the Detent rate-limiting API. Sync and async, one dependency (httpx).

pip install detent-sdk

Usage

from detent import Detent

rg = Detent(api_key="dt_live_...")

# Rate-limit check (fails open by default on transport error or 5xx)
r = rg.limit(namespace="api", key=user_id)
if not r.allowed:
    ...  # return HTTP 429

# Concurrent-limit lease (auto-released)
with rg.lease(namespace="jobs", key=user_id):
    run_expensive_job()

# Read-only usage stats
stats = rg.get_stats(namespace="api")

Async

from detent import AsyncDetent

async with AsyncDetent(api_key="dt_live_...") as rg:
    r = await rg.limit(namespace="api", key=user_id)
    async with rg.lease(namespace="jobs", key=user_id):
        await run_expensive_job()

Configuration

Option Default Notes
api_key — (required) dt_live_… / dt_test_…
base_url https://api.detent.dev Override for self-host / tests
timeout 1.0 Seconds; client-side transport timeout
fail_mode "open" "open" allows, "closed" denies on a degraded backend
on_error None Called on a degraded (transport/5xx) limit() call

limit() never raises on a degraded backend (transport error or 5xx) — it returns a result with degraded=True. A 4xx (bad key, plan gate, unknown rule) raises DetentAPIError.

acquire() / lease() do not fail open — unlike limit(), they raise DetentTransportError when Detent is unreachable, regardless of fail_mode. A failed-open acquire would return no lease_id, so the work would run holding a slot it can never release (a lease leak). Raising lets you decide whether to proceed or shed load. This is distinct from the server's own Redis fail-open, where the API still returns 200 with allowed=True and a None lease_id.

When an account exceeds its monthly hard ceiling the API returns 429, and limit()/acquire() raise DetentQuotaExceeded (a DetentAPIError subclass carrying status/body). It is never failed open — the cap is a deliberate block. Catch it to alert or prompt an upgrade:

from detent import DetentQuotaExceeded

try:
    result = client.limit(namespace="api", key=user_id)
    if not result.allowed:
        ...  # routine per-key rate deny → return HTTP 429
except DetentQuotaExceeded:
    ...  # account over its monthly ceiling → page ops / upgrade nudge

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

detent_sdk-0.3.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

detent_sdk-0.3.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file detent_sdk-0.3.0.tar.gz.

File metadata

  • Download URL: detent_sdk-0.3.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for detent_sdk-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d0a3005315d6bc00aad5cecf78ae43bc6f9a915346cdc2c82fb6581111368cbc
MD5 7c96f9cb3a72f6bd6e8ee76100188df1
BLAKE2b-256 19e4d71a82b2c11d3ac824402da64af14fbf6966e6ea2ff6aeb5b4ccd602acad

See more details on using hashes here.

Provenance

The following attestation bundles were made for detent_sdk-0.3.0.tar.gz:

Publisher: release.yml on cguillerminet/detent-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file detent_sdk-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: detent_sdk-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for detent_sdk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0fca17e44b2e007a3cd96b8864544a62b51434f538fc1724528cbd1a223d8221
MD5 9ab9ef533a955fb854c0bdb236d9f1ff
BLAKE2b-256 255cbdea19eb9e72603be975ae81675fd1cee35242791b58f6d38bb6509f78b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for detent_sdk-0.3.0-py3-none-any.whl:

Publisher: release.yml on cguillerminet/detent-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page