Skip to main content

Python SDK for CodeRifts — API governance for AI agents

Project description

coderifts-sdk

Python SDK for CodeRifts — API governance for AI agents.

v2.0.0 exposes only the three canonical tools (the same surface agents see by default over MCP). Other live REST endpoints may be added later, additively.

Method HTTP
preflight_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

Branch on execution_action (proceed signal). Use decision for the explanation label.

before = open("openapi-before.json").read()
after = open("openapi-after.json").read()

result = client.preflight_change_set(
    artifacts=[
        {
            "id": "spec-main",
            "type": "openapi",
            "before": before,
            "after": after,
        }
    ],
    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.preflight_change_set(artifacts=[...])
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

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

coderifts_sdk-2.0.0.tar.gz (8.9 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-2.0.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for coderifts_sdk-2.0.0.tar.gz
Algorithm Hash digest
SHA256 9d849b7afd63b3042dc4166008344b022722d491105f4319b5ac0d19792e140a
MD5 8f04f0dd1c14704100ae58104bb9b5c4
BLAKE2b-256 1324882ad0430dd8deb6fa7fcae770a7d07ee21b56ccb00db7e1609cc1a42fa7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: coderifts_sdk-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.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-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c0b94d11d7e69f449f0c79b0311c3d15ca22cc7dd5d5204fa26bdb45c39a5da
MD5 acf9d99152233827fab405710724ee5a
BLAKE2b-256 de2efcb3460c30ef543817f4790f5de01929cef4e7cebed39776bea4d3050902

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