Skip to main content

coderifts-sdk

Python SDK for CodeRifts — API governance for AI agents.

v3.0.0 exposes the three canonical tools (the same surface agents see by default over MCP). Decision Spec v2 requires top-level preflight_mode on preflight. Other live REST endpoints may be added later, additively.

Method HTTP
preflight_change_set / analyze_change_set / authorize_change_set POST /api/v1/preflight
verify_receipt POST /api/v1/verify-receipt
get_decision_details POST /api/v1/decisions/lookup

Installation

pip install coderifts-sdk

Requires Python 3.9+ and requests.

Quick start

from coderifts import CodeRifts, CodeRiftsError

client = CodeRifts(api_key="cr_live_...")

preflight_change_set / analyze_change_set / authorize_change_set

Required keyword-only preflight_mode='analyze'|'authorize' (Decision Spec v2; server returns HTTP 400 if omitted). Prefer the wrappers so the two meanings cannot be mixed.

Branch on execution_action (proceed signal, authorize). Use decision for the explanation label. Analyze is informational (risk-only), not permission.

before = open("openapi-before.json").read()
after = open("openapi-after.json").read()
artifacts = [
    {
        "id": "spec-main",
        "type": "openapi",
        "before": before,
        "after": after,
    }
]

# Risk-only
risk = client.analyze_change_set(artifacts=artifacts)

# Operation-bound authorize (requires context.operation; may mint a receipt)
result = client.authorize_change_set(
    artifacts=artifacts,
    context={
        "operation": "merge",
        "environment": "staging",
    },
)

# Or set the mode explicitly:
result = client.preflight_change_set(
    artifacts=artifacts,
    preflight_mode="authorize",
    context={"operation": "merge", "environment": "staging"},
)

print(result.execution_action)   # e.g. "CONTINUE"
print(result.decision)           # e.g. "ALLOW"
print(result.risk_score)
print(result.breaking_changes)   # integer count, not a list
print(result.safe_for_agent)

# Signed receipt for later verification (when present)
token = result.chain_receipt
decision_id = result.decision_result.decision_id

verify_receipt

A valid signature is not authorization. currently_authorized is True / False / NoneNone means authorization was not evaluated.

# Cryptographic check only
check = client.verify_receipt(token=token)
print(check.valid, check.status)
print(check.currently_authorized)  # often None without intent context

# With intent + the body-bound decision envelope for full authorization
authz = client.verify_receipt(
    token=token,
    operation="merge",
    environment="staging",
    target_id=result.decision_result.artifact_digest,
    fingerprint=result.verdict_fingerprint,
    decision_result=result.decision_result.to_dict(),
)
print(authz.currently_authorized)  # True / False once evaluable
print(getattr(authz, "authz_status", None))

get_decision_details

Look up a stored decision by decision_id or fingerprint.

stored = client.get_decision_details(decision_id=decision_id)
# or: stored = client.get_decision_details(fingerprint=result.verdict_fingerprint)

print(stored.execution_action)
print(stored.decision)
print(stored.meta.source)

Error handling

from coderifts import CodeRifts, ApiError, AuthError, RateLimitError, CodeRiftsError

try:
    client.authorize_change_set(artifacts=[...], context={"operation": "merge"})
except AuthError as e:
    print("auth", e.message)
except RateLimitError as e:
    print("rate limit", e.message)
except ApiError as e:
    print(e.status_code, e.message)
except CodeRiftsError as e:
    print(e.code, e.message)

Response access

Return values are thin wrappers around the JSON object:

result.decision                 # attribute
result["decision"]              # item
"decision" in result            # membership
result.to_dict()                # full dict
result.decision_result.decision_id  # nested dicts wrap too

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coderifts_sdk-3.0.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

coderifts_sdk-3.0.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file coderifts_sdk-3.0.0.tar.gz.

File metadata

  • Download URL: coderifts_sdk-3.0.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for coderifts_sdk-3.0.0.tar.gz
Algorithm Hash digest
SHA256 2199bbd06e6e5dea47aee2ea720aac84207f77da3a3e3483afc8a4b88a2d67ee
MD5 90bfaf8ae2db1d6f6c51e34765b26811
BLAKE2b-256 867c793a91bfdc97e78ec52965eb6b9f9ffe4acfbcd7a99ebdd29b90ceebec89

See more details on using hashes here.

File details

Details for the file coderifts_sdk-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: coderifts_sdk-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for coderifts_sdk-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68d0e47467cd3849ea49d751a6f3f288627e3b4cece7d9cb0b0e24c294d7adb9
MD5 58f93f91c5b16a223680cec959d9c5cd
BLAKE2b-256 2b1ef4f49f154a5cdbf3796ddbc0fa1d70fb43539d5f103a0fdfc519afb9d766

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