Skip to main content

Python SDK for Contract Lane Operator API

Project description

contractlane-operator-sdk

Python SDK for the Contract Lane Operator API.

Install

pip install contractlane-operator-sdk

Requires Python >=3.10.

Quickstart

from contractlane_operator_sdk import ClientOptions, OperatorClient

client = OperatorClient(
    ClientOptions(
        base_url="https://localhost",
        session_token=lambda: "session-token",
        operator_token=lambda: "operator-token",
        challenge_headers=lambda _: {
            "X-Signup-Challenge": "signup-challenge-token",
            "X-Operator-Challenge": "proof-challenge",
            "X-Operator-Challenge-Token": "challenge-provider-token",
        },
    )
)

1) Human signup/auth

start = client.public.signup.start({"email": "owner@example.com", "org_name": "Acme"})
session_id = start.data["signup_session"]["session_id"]

client.public.signup.verify({"session_id": session_id, "verification_code": "123456"})
client.public.signup.complete({"session_id": session_id, "project_name": "Default", "agent_name": "Primary"})

2) Admin actor + credential issue

org = client.operator.admin.create_org({"name": "Acme", "admin_email": "owner@example.com"})
org_id = org.data["org"]["org_id"]
project = client.operator.admin.create_project(org_id, {"name": "Project A"})
project_id = project.data["project"]["project_id"]
actor = client.operator.admin.create_actor(project_id, {"name": "Bot", "scopes": ["cel.contracts:write"]})
actor_id = actor.data["actor"]["actor_id"]
client.operator.admin.issue_credential({"actor_id": actor_id, "upstream_token": "upstream-token"})

3) Agent-first enrollment

challenge = client.public.agent_enrollment.challenge(
    {"public_key_jwk": {"kty": "OKP", "crv": "Ed25519", "x": "..."}}
)
challenge_id = challenge.data["challenge"]["challenge_id"]
client.public.agent_enrollment.start(
    {
        "challenge_id": challenge_id,
        "signature": "base64url-signature",
        "sponsor_email": "owner@example.com",
        "requested_scopes": ["cel.contracts:write"],
    }
)

4) Gateway contract action

client.gateway.cel.create_contract({"template_id": "tpl_123", "payload": {}})
client.gateway.cel.contract_action("ctr_123", "send", {"note": "go"})

5) Public signing + actor key lifecycle

client.public.signing.resolve("sign_tok")
client.public.signing.accept("sign_tok", {"challenge_id": "chal_123", "signature": "base64url-signature"})

client.operator.actor_keys.challenge(
    "act_123",
    {"public_key_jwk": {"kty": "OKP", "crv": "Ed25519", "x": "..."}},
)
client.operator.actor_keys.list("act_123")
client.operator.admin.list_actors_compat("prj_123")

Notes

  • Mutating operator/public endpoints auto-inject Idempotency-Key.
  • request_id is available via response.meta.request_id.
  • Challenge hooks can provide X-Signup-Challenge, X-Operator-Challenge, and X-Operator-Challenge-Token; per-request headers can override hook values.
  • Failures raise APIError with status, code, message, request_id, meta, raw_body.

Integration Tests

Run against a live operator stack:

python -m pytest tests/integration -m integration

Default pytest run skips integration tests (-m "not integration").

Strictness controls:

  • TEST_ADMIN_STRICT_SUCCESS=1: require admin flow success; otherwise unauthorized admin environments are treated as non-blocking.
  • TEST_GATEWAY_STRICT_SUCCESS=1: require gateway create/action/proof success; otherwise 404 is treated as environment limitation.

Publish (PyPI)

. .venv/bin/activate
pip install -U build twine
python -m build
python -m twine upload dist/*

If using token auth, set:

export TWINE_USERNAME=__token__
export TWINE_PASSWORD=<pypi-token>

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

contractlane_operator_sdk-0.1.1.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

contractlane_operator_sdk-0.1.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file contractlane_operator_sdk-0.1.1.tar.gz.

File metadata

File hashes

Hashes for contractlane_operator_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 98302929a46f981c9a6909c2f648f1297085586e4fe0660f190bbcabbb6ae904
MD5 e791ca71a28c53b90a49f77edf062d2e
BLAKE2b-256 26d010e87e7bd1a680454b4704a6951ff5eb4481aef283f51058177db89ca21b

See more details on using hashes here.

File details

Details for the file contractlane_operator_sdk-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for contractlane_operator_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f38968fb79b9eb7646845c49ab2d1054f646a37a49b1346e13c8c0ccd05f0072
MD5 e15794779ecaf8073791a658afe4ca05
BLAKE2b-256 a8241678f26eb4c0832592740bba8939301fe2c4033778443ebbd35f6e562681

See more details on using hashes here.

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