Skip to main content

verity-sdk (Python)

Exactly-once effect protection for AI agents and autonomous systems.

The Python SDK for Verity — ensures real-world actions like payments, refunds, emails, and infrastructure provisioning happen exactly once, are safe to retry, and are fully auditable.

pip install verityinc-sdk

Quick Start

from verity import VerityClient

verity = VerityClient(
    base_url="https://api.useverity.io/v1",
    api_key="vk_live_xxxxxx",
    namespace="payments",
)

# Protect a side effect — Verity guarantees it runs exactly once
charge = await verity.protect("charge-order-456", {
    "act": lambda: stripe.Charge.create(amount=5000, currency="usd"),
})

If an agent crashes mid-flight, the next attempt either returns the cached result (if already committed) or uses observe() to detect the completed action in the external system — preventing duplicate charges.

With Crash Recovery (Observe)

charge = await verity.protect("charge-order-789", {
    "observe": async_check_stripe,
    "act": async_create_charge,
})

async def async_check_stripe():
    """Check if a prior agent already completed this charge."""
    existing = stripe.Charge.list(metadata={"order_id": "789"})
    return existing.data[0] if existing.data else None

async def async_create_charge():
    return stripe.Charge.create(
        amount=5000,
        currency="usd",
        metadata={"order_id": "789"},
    )

Workflow Mode (Multi-Effect)

run = verity.workflow("refund_flow").case("order_123").run()

# effectKey = "order_123:notify_customer"
await run.protect("notify_customer", {
    "act": lambda: email_service.send(to=customer.email, template="refund"),
})

# effectKey = "order_123:refund_payment"
await run.protect("refund_payment", {
    "act": lambda: stripe.Refund.create(charge=charge_id),
})

If a crash occurs between steps, the retry run skips already-committed effects and resumes from where it left off.

Configuration

from verity import VerityClient

verity = VerityClient(
    # Required
    base_url="https://api.useverity.io/v1",
    api_key="vk_live_xxxxxx",

    # Optional
    namespace="payments",           # default namespace
    agent_id="worker-1",            # identifies this agent in audit logs
    auto_renew=True,                # auto-renew leases in background
    renew_at_fraction=0.65,         # renew at 65% of lease duration
    request_timeout_ms=20_000,      # HTTP timeout per request

    # Conflict retry (when another agent holds the lease)
    conflict_retry={
        "enabled": True,
        "max_attempts": 12,
        "initial_delay_ms": 500,
        "max_delay_ms": 15_000,
        "jitter": True,
    },

    # Custom logger
    logger=my_logger,               # any logging.Logger instance
)

Error Handling

from verity import VerityClient
from verity.errors import (
    CommitUncertainError,
    LeaseConflictError,
    EffectPreviouslyFailedError,
)

try:
    await verity.protect("charge-order-456", {"act": charge})
except CommitUncertainError as e:
    # Action SUCCEEDED but Verity couldn't confirm the commit.
    # DO NOT RETRY — halt and reconcile manually.
    print(f"Action ran but commit uncertain: {e.result}")
    await alert_ops(e)
except LeaseConflictError:
    # Another agent is processing this effect
    print("Effect is being handled by another agent")
except EffectPreviouslyFailedError as e:
    # Prior failure — admin reset required via Explorer
    print(f"Prior failure: {e.cached_error}")

How It Works

Every call to protect() follows the lease → observe → act → commit protocol:

  1. Lease — acquire exclusive, time-bound access to the effect
  2. Observe (optional) — check the external system for a prior completion
  3. Act — execute the real-world side effect
  4. Commit — record the result in Verity's ledger
Agent A                          Verity                         Stripe
  │                                │                              │
  ├── request_lease ──────────────►│                              │
  │◄── granted (fence_token: 1) ──┤                              │
  │                                │                              │
  ├── stripe.Charge.create ────────────────────────────────────────►
  │◄── { id: "ch_xxx" } ──────────────────────────────────────────┤
  │                                │                              │
  ├── commit(result) ─────────────►│                              │
  │◄── accepted ──────────────────┤                              │

Parity with TypeScript SDK

This SDK provides full feature parity with the TypeScript SDK:

Feature TypeScript Python
protect() standalone verity.protect() await verity.protect()
Workflow builder verity.workflow().case().run() verity.workflow().case().run()
Auto lease renewal setInterval + unref() asyncio.create_task()
Conflict retry with backoff ✅ ✅
Observe/Act pattern ✅ ✅
Fence token validation ✅ ✅
CommitUncertainError ✅ ✅
Per-effect namespace ✅ ✅
Key suffix ✅ ✅
Custom logger logger: { warn, error } logger: logging.Logger
Typed request bodies Exported types @dataclass exports

Requirements

  • Python >= 3.10
  • httpx >= 0.27
  • Zero other runtime dependencies

Development

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Type check
mypy src/

# Lint
ruff check src/

License

Proprietary — Verity Systems, Inc.

Metadata

Release files for verityinc-sdk 0.1.1

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

Source distribution (sdist)

Source distribution for verityinc-sdk 0.1.1
File Size Uploaded Provenance
verityinc_sdk-0.1.1.tar.gz 18.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for verityinc-sdk 0.1.1
File Interpreter ABI Platform
verityinc_sdk-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 34.9 kB

Release files / verityinc_sdk-0.1.1.tar.gz

Download URL verityinc_sdk-0.1.1.tar.gz
Size 18.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ce0d37edf78afc9e2fa1c95345141104547e73b3a73787e4f8c48cfe75fa0995
BLAKE2b-256 checksum
How to use checksums
5a26f0e85c4cbeb6399618f54c6c47f0e98d3bbd8ee2a5b8b1bd0ca01a806dba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release files / verityinc_sdk-0.1.1-py3-none-any.whl

Download URL verityinc_sdk-0.1.1-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
93ca1d80a9fdb8c36f65a65b9cf7485ad9885cffb1d253bcde6d1a44dde4120d
BLAKE2b-256 checksum
How to use checksums
a475968c91d90746076ac9992bfd67e3a1a7ce24abc3a277d94a4f3f66abb730
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Security for verityinc-sdk 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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