Skip to main content
Back to docs

Python SDK

Seal an event from Python.

Use the Python SDK for scripts, workers, and agent pipelines that need witnessed tool calls and verifiable chain exports.

terminal
pip install rankigi
npx @rankigi/cli init

Configure

Use one credential token.

The CLI writes a single credential and chain ID. Rankigi.from_env() reads both.

.env
RANKIGI_CREDENTIAL=rnk_live_cred_v1...
RANKIGI_CHAIN_ID=chn_your_chain_id

First event

Record one tool call.

seal_tool_call.py
from dotenv import load_dotenv
load_dotenv()

from rankigi import Rankigi

rk = Rankigi.from_env()

rk.track_tool_call(
    "send_email",
    {"to": "customer@example.com", "template": "renewal_notice"},
    {"status": "sent", "provider_id": "msg_abc123"},
)

rk.close()

Wrap work

Wrap any callable.

wrap.py
result = rk.wrap(
    "contract-review",
    {"document_id": "doc_123", "model": "claude-sonnet-4-20250514"},
    lambda: review_contract("doc_123"),
)

LLM calls

Wrap provider calls directly.

anthropic.py
from anthropic import Anthropic

client = Anthropic()

response = rk.wrap_anthropic(
    "contract-review",
    {"model": "claude-sonnet-4-20250514", "document_id": "doc_123"},
    lambda: client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=1024,
        messages=[{"role": "user", "content": "Review doc_123"}],
    ),
)

Methods

The small API surface.

Rankigi.from_env()Reads RANKIGI_CREDENTIAL and RANKIGI_CHAIN_ID.
rk.track_tool_call(tool, input, output)Records a tool invocation as a signed chain event.
rk.wrap(label, args, fn)Wraps any callable and records input plus result hashes.
rk.wrap_anthropic(label, args, fn)Wraps an Anthropic Messages call.
rk.wrap_openai(label, args, fn)Wraps an OpenAI Chat Completions call.
rk.close()Flushes pending events before process exit.

Failure behavior

Passive by design.

RANKIGI does not block your agent. The Python SDK sends on a daemon thread and logs failures to stderr. It does not currently retry failed sends.

failure_behavior.py
rk = Rankigi.from_env()

# RANKIGI is passive. SDK transport failures do not
# raise into your agent path. The Python SDK queues ingest
# on a daemon thread and logs failed sends to stderr.
#
# The Python SDK does not retry. Use the Node SDK for
# production paths that require durable replay semantics.

rk.close()

Verify

End with independent verification.

A sealed event matters only if the exported chain can be checked outside RANKIGI.

verify
# Export a closure bundle from the dashboard.
# Then verify it locally with the reference verifier.

python3 verify.py closure-export.json

# Browser verifier:
# https://rankigi.com/verify