Python SDK
Use the same ledger operations in your application, locally or through a named connection.
Read as Markdown ↗On this page
Write and read
This example starts a local ledger. A new ledger’s permissive contract accepts this payload; inspect existing ledger rules before writing.
from op_sys import OpSysclient = OpSys(connection="local")client.start()client.ledgers.inspect()result = client.records.append( operation_id="first-record", payload={"message": "Hello"})if result["state"] == "accepted": record = client.records.get(record_id=result["acceptance"]["record_id"]) print(record["record"]["payload"])Target a hosted ledger
Use an authenticated named connection and an authorized ledger ID. The methods and domain results stay the same. Direct hosted use needs no local replica.
Constructors do not make a network request. Existing SDK clients retain their initialized selection until explicitly reconfigured.
client = OpSys(connection="work", ledger="<ledger-id>")ledger = client.ledgers.inspect()page = client.records.list(limit=20)Handle outcomes and retries
Accepted, pending and uncertain outcomes have different meanings. Save an operation ID before dispatch and preserve both it and the intended input for retries. records.outcome checks acceptance without submitting again.
OpSysError.core_error contains the domain code, operation, retry classification and recovery guidance. Follow pagination continuations and coverage; a first page is not the full ledger.
SDK contract and error handlingContribution recovery