Skip to main content

Sovereign AI Responsibility Layer SDK for Python

Project description

SOVR SDK for Python

Sovereign AI Responsibility Layer SDK - 为 AI 执行系统提供责任层能力的 Python SDK。

安装

pip install sovr-sdk

快速开始

from sovr_sdk import SOVRClient

# 初始化客户端
client = SOVRClient(
    api_key="your-api-key",
    tenant_id="your-tenant-id",
    endpoint="https://api.sovr.example.com"
)

# 评估决策
result = client.evaluate_decision(
    action="payment",
    resource="order/12345",
    context={"amount": 1000, "currency": "CNY"}
)

print(f"决策结果: {result.verdict}")
print(f"风险评分: {result.risk_score}")
print(f"价值评分: {result.value_score}")

# 根据决策结果执行后续操作
if result.verdict == "approved":
    print("✓ 操作已批准,可以执行")
elif result.verdict == "pending_approval":
    print("⏳ 需要人工审批")
else:
    print("✗ 操作被拒绝")

核心功能

决策评估

result = client.evaluate_decision(
    action="payment",
    resource="order/12345",
    context={"amount": 1000},
    metadata={"trace_id": "abc123"}
)

信任包管理

# 创建信任包
bundle = client.create_trust_bundle(
    name="支付决策信任包",
    description="订单 #12345 的支付决策证据"
)

# 添加证据
client.add_evidence(
    bundle_id=bundle.id,
    evidence_type="document",
    content={"title": "合同文件", "url": "https://..."},
    weight=0.3
)

# 评估充分性
evaluation = client.evaluate_sufficiency(bundle.id)
print(f"充分性评分: {evaluation.score}")

审计日志查询

# 查询审计日志
logs = client.get_audit_logs(
    start_date="2026-01-01",
    end_date="2026-01-25",
    limit=100
)

for log in logs:
    print(f"{log.created_at}: {log.event_type} - {log.action}")

环境变量

SDK 支持通过环境变量配置:

export SOVR_API_KEY="your-api-key"
export SOVR_TENANT_ID="your-tenant-id"
export SOVR_API_ENDPOINT="https://api.sovr.example.com"
# 自动从环境变量读取配置
client = SOVRClient()

错误处理

from sovr_sdk.exceptions import SOVRError, AuthenticationError, RateLimitError

try:
    result = client.evaluate_decision(...)
except AuthenticationError:
    print("认证失败,请检查 API Key")
except RateLimitError as e:
    print(f"请求过于频繁,请在 {e.retry_after} 秒后重试")
except SOVRError as e:
    print(f"SOVR 错误: {e.message}")

文档

许可证

MIT License

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

sovr_sdk-7.0.0.tar.gz (55.6 kB view details)

Uploaded Source

Built Distribution

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

sovr_sdk-7.0.0-py3-none-any.whl (49.5 kB view details)

Uploaded Python 3

File details

Details for the file sovr_sdk-7.0.0.tar.gz.

File metadata

  • Download URL: sovr_sdk-7.0.0.tar.gz
  • Upload date:
  • Size: 55.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0rc1

File hashes

Hashes for sovr_sdk-7.0.0.tar.gz
Algorithm Hash digest
SHA256 cf94e5d535ef48cd37558dc0c530a06c8c95f0ea279f3ba9c4c9999e70c8f0a2
MD5 ee318220bc42b6cfacd29d78a209450d
BLAKE2b-256 69b71d588a58afc31e16ee3ae4952ae8624790fa801f11f6e8927cf6f7cdb200

See more details on using hashes here.

File details

Details for the file sovr_sdk-7.0.0-py3-none-any.whl.

File metadata

  • Download URL: sovr_sdk-7.0.0-py3-none-any.whl
  • Upload date:
  • Size: 49.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0rc1

File hashes

Hashes for sovr_sdk-7.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10c6b88d4d8a8ba39dc4c51dafccd31af1b45cb231b6878df21f16135142c508
MD5 1642d707579557ea16a68e3a68a392c8
BLAKE2b-256 828e88494da81f1ac3fa39c7825eac4f0ecb7d22a18880178957c0ae6ca266f9

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