Python SDK for OnceOnly idempotency API
Project description
OnceOnly Python SDK
The Idempotency Layer for AI Agents, Webhooks, and Distributed Systems.
OnceOnly is a high-performance Python SDK that ensures exactly-once execution. It prevents duplicate actions (payments, emails, tool calls) in unstable environments like AI agents, webhooks, retries, or background workers.
Website: https://onceonly.tech/ai/
Documentation: https://onceonly.tech/docs/
Features
- Sync + Async client (httpx-based)
- Fail-open mode for production safety
- Stable idempotency keys (supports Pydantic & dataclasses)
- Decorators for zero-boilerplate usage
- Native AI API (long-running jobs, local side-effects)
- Optional AI / LangChain integrations
Installation
pip install onceonly-sdk
With LangChain support included:
pip install "onceonly-sdk[langchain]"
Quick Start (Webhooks / Automations)
from onceonly import OnceOnly
client = OnceOnly(
api_key="once_live_...",
fail_open=True # default: continues if API is down
)
res = client.check_lock(key="order:123", ttl=300)
if res.duplicate:
print("Duplicate blocked")
else:
print("First execution")
Use check_lock() for:
- Webhooks
- Make / Zapier scenarios
- Cron jobs
- Distributed workers
AI Jobs (Server-side)
Use the AI API for long-running or asynchronous jobs.
result = client.ai.run_and_wait(
key="ai:job:daily_summary:2026-01-09",
metadata={"task": "daily_summary", "model": "gpt-4.1"},
timeout=60,
)
print(result.status)
print(result.result)
- Charged once per key
- Polling is free
- Safe across retries and restarts
AI Agents / Local Side-Effects
Use the AI Lease API when your code performs the side-effect locally (payments, emails, webhooks) but still needs exactly-once guarantees.
lease = client.ai.lease(key="ai:agent:charge:user_42:invoice_100", ttl=300)
if lease["status"] == "acquired":
try:
do_side_effect()
client.ai.complete(key=KEY, lease_id=lease["lease_id"], result={"ok": True})
except Exception:
client.ai.fail(key=KEY, lease_id=lease["lease_id"], error_code="failed")
LangChain Integration 🤖
from onceonly.integrations.langchain import make_idempotent_tool
tool = make_idempotent_tool(
original_tool,
client=client,
key_prefix="agent:tool"
)
Repeated tool calls with the same inputs will execute exactly once, even across retries or agent restarts.
See examples/ai/ for canonical patterns.
Decorators
from onceonly.decorators import idempotent
@idempotent(client, ttl=3600)
def process_order(order_id):
...
Idempotency keys are generated automatically and remain stable across restarts.
Fail-Open Mode
Fail-open is enabled by default.
Network errors, timeouts, or server errors (5xx) will not break your application. The SDK will allow execution to continue safely.
Fail-open never applies to:
- Auth errors (401 / 403)
- Plan limits (402)
- Validation errors (422)
- Rate limits (429)
Support
Need help?
Email: support@onceonly.tech
Or open an issue on GitHub.
License
MIT
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 onceonly_sdk-2.0.1.tar.gz.
File metadata
- Download URL: onceonly_sdk-2.0.1.tar.gz
- Upload date:
- Size: 16.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd6966772524c44bcb54b38160b5c09e324bbb3f123d9cbcb7edec1b42917ea9
|
|
| MD5 |
a76b1b7c1d0b28e82ac72e39fd1e8f06
|
|
| BLAKE2b-256 |
6115c6107011a946206c462878c53ca3898dd9ac1dd373a92f1082b83069c773
|
Provenance
The following attestation bundles were made for onceonly_sdk-2.0.1.tar.gz:
Publisher:
release.yml on mykolademyanov/onceonly-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
onceonly_sdk-2.0.1.tar.gz -
Subject digest:
cd6966772524c44bcb54b38160b5c09e324bbb3f123d9cbcb7edec1b42917ea9 - Sigstore transparency entry: 809137248
- Sigstore integration time:
-
Permalink:
mykolademyanov/onceonly-python@c3a66350d98c5aa0325775f801fa1ce1c22ebeaa -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/mykolademyanov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c3a66350d98c5aa0325775f801fa1ce1c22ebeaa -
Trigger Event:
release
-
Statement type:
File details
Details for the file onceonly_sdk-2.0.1-py3-none-any.whl.
File metadata
- Download URL: onceonly_sdk-2.0.1-py3-none-any.whl
- Upload date:
- Size: 16.1 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 |
a18192245ad142c6aae0795c8b0941d0ab9f709cd0859396972a5f9167f56c21
|
|
| MD5 |
8b1f20a7e46ea19388fdd97316f9deae
|
|
| BLAKE2b-256 |
9bb1cd8dd1703283089adac42c96e65efcf198549a5bd778581c35acd78e43b1
|
Provenance
The following attestation bundles were made for onceonly_sdk-2.0.1-py3-none-any.whl:
Publisher:
release.yml on mykolademyanov/onceonly-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
onceonly_sdk-2.0.1-py3-none-any.whl -
Subject digest:
a18192245ad142c6aae0795c8b0941d0ab9f709cd0859396972a5f9167f56c21 - Sigstore transparency entry: 809137279
- Sigstore integration time:
-
Permalink:
mykolademyanov/onceonly-python@c3a66350d98c5aa0325775f801fa1ce1c22ebeaa -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/mykolademyanov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c3a66350d98c5aa0325775f801fa1ce1c22ebeaa -
Trigger Event:
release
-
Statement type: