Skip to main content

MOSS Partner SDK (Python)

Python SDK for the MOSS Partner API - Manage customers, configure governance, and monitor compliance.

Installation

pip install moss-partner-sdk

Quick Start

import asyncio
from moss_partner_sdk import MossPartner

async def main():
    # Initialize the SDK
    moss = MossPartner(api_key="prt_xxx")

    # Create a customer
    customer = await moss.customers.create(
        external_id="acme_123",
        name="Acme Corp",
        email="admin@acme.com",
        governance={
            "jurisdictions": ["EU", "US"],
            "frameworks": ["eu_ai_act", "nist_ai_rmf"],
        },
    )

    print(f"Customer ID: {customer.id}")
    print(f"Sandbox Token: {customer.sandbox_token}")
    print(f"Status: {customer.status}")

    # Close the client
    await moss.close()

if __name__ == "__main__":
    asyncio.run(main())

Features

  • Customer Management: Create, list, update, promote, suspend, and reactivate customers
  • Session Tokens: Create temporary session tokens for customer dashboard access
  • Compliance Reports: Generate ML-DSA-44 signed compliance reports (PDF/JSON)
  • Webhooks: Manage webhook subscriptions for real-time event notifications
  • Analytics: Access customer, compliance, and billing analytics
  • Async/Await: Full async/await support using httpx
  • Type Hints: Comprehensive type hints with Pydantic models
  • Error Handling: Typed exceptions for API errors, network errors, and validation errors

Usage Examples

Customer Lifecycle

async with MossPartner(api_key="prt_xxx") as moss:
    # Create customer
    customer = await moss.customers.create(
        external_id="acme_123",
        name="Acme Corp",
    )

    # List customers
    result = await moss.customers.list(status="pending", limit=10)
    for c in result.data:
        print(f"{c.name}: {c.status}")

    # Get customer by ID
    customer = await moss.customers.get(customer.id)

    # Update customer limits
    updated = await moss.customers.update(
        customer.id,
        limits={"agents": 50},
    )

    # Promote to production
    promoted = await moss.customers.promote(
        customer.id,
        attestation={
            "kyc_completed": True,
            "terms_accepted": True,
            "compliance_reviewed": True,
            "attested_by": "compliance@partner.com",
        },
        billing={
            "tier": "platform",
            "billing_email": "billing@acme.com",
        },
    )

    print(f"Production Token: {promoted.production_token}")

Session Tokens (M3 Feature)

async with MossPartner(api_key="prt_xxx") as moss:
    # Create 15-minute session token (partner-acting-as-customer)
    # Fixed 15-minute TTL enforced by backend (cannot be customized)
    session = await moss.customers.create_session(
        customer_id="customer-uuid",
        idempotency_key="unique-key-123",  # Optional, for replay protection
    )

    print(f"Session ID: {session.session_id}")
    print(f"Session Token (cust_): {session.token}")
    print(f"Expires At: {session.expires_at}")

    # Revoke specific session
    await moss.customers.revoke_session(
        customer_id="customer-uuid",
        session_id=session.session_id,
    )

    # Revoke ALL sessions for customer (omit session_id)
    await moss.customers.revoke_session(
        customer_id="customer-uuid"
    )

Compliance Reports (ML-DSA-44 Signed)

async with MossPartner(api_key="prt_xxx") as moss:
    # Generate PDF report with ML-DSA-44 signature
    report = await moss.customers.compliance_report(
        customer_id="customer-uuid",
        format="pdf",
        frameworks=["eu_ai_act"],
    )

    print(f"Report ID: {report.report_id}")
    print(f"Signature: {report.signature}")  # ML-DSA-44 signature
    print(f"Key ID: {report.key_id}")
    print(f"Generated: {report.generated_at}")

Webhooks

from moss_partner_sdk import verify_webhook_signature

async with MossPartner(api_key="prt_xxx") as moss:
    # Create webhook
    webhook = await moss.webhooks.create(
        url="https://partner.com/webhooks/moss",
        events=["customer.*", "agent.anomaly_detected"],
    )

    print(f"Webhook ID: {webhook.id}")
    print(f"Secret: {webhook.secret}")

    # List webhooks
    webhooks = await moss.webhooks.list()

    # Delete webhook
    await moss.webhooks.delete(webhook.id)

# Verify webhook signature (in your webhook handler)
def handle_webhook(request):
    is_valid = verify_webhook_signature(
        payload=request.body,
        signature=request.headers["X-Moss-Signature"],
        secret=webhook.secret,
    )

    if not is_valid:
        return Response(status=401)

    # Process webhook event
    event = request.json()
    print(f"Event: {event['type']}")

Analytics

async with MossPartner(api_key="prt_xxx") as moss:
    analytics = await moss.analytics.get(period="30d")

    print(f"Total Customers: {analytics.customers.total}")
    print(f"Sandbox: {analytics.customers.sandbox}")
    print(f"Production: {analytics.customers.production}")
    print(f"Average Compliance Score: {analytics.compliance.average_score}")
    print(f"Current MRR: ${analytics.billing.current_mrr}")

API Reference

MossPartner

Main SDK client.

Constructor:

  • api_key (str): Partner API key (must start with "prt_")
  • base_url (str, optional): Base URL for MOSS API (default: production)
  • timeout (float, optional): Request timeout in seconds (default: 30)
  • retries (int, optional): Number of retries for failed requests (default: 3)

Methods:

  • ping(): Health check - returns True if API is reachable
  • close(): Close HTTP client and release resources

Resources:

  • customers: Customer management methods
  • webhooks: Webhook management methods
  • analytics: Analytics methods

customers

  • create(): Create a new customer
  • list(): List customers with optional filtering
  • get(): Get customer by ID
  • update(): Update customer configuration
  • promote(): Promote customer to production
  • suspend(): Suspend a customer
  • reactivate(): Reactivate a suspended customer
  • create_session(): Create temporary session token
  • revoke_session(): Revoke a session token
  • compliance_report(): Generate ML-DSA-44 signed compliance report

webhooks

  • create(): Create webhook subscription
  • list(): List webhook subscriptions
  • delete(): Delete webhook subscription

analytics

  • get(): Get analytics for specified period

Error Handling

from moss_partner_sdk import MossAPIError, MossNetworkError

try:
    customer = await moss.customers.get("invalid-id")
except MossAPIError as e:
    print(f"API Error {e.status_code} ({e.code}): {e.message}")
except MossNetworkError as e:
    print(f"Network Error: {e.message}")

Development

# Install development dependencies
pip install -e ".[dev]"

# Run linter
ruff check src tests

# Run type checker
mypy src

# Run tests
pytest tests/ -v

# Run integration tests (requires API key)
export MOSS_PARTNER_KEY="prt_xxx"
pytest tests/ -v -m integration

Deployment Workflow

The SDK follows the MOSS staged deployment pattern:

main → staging → production

Branches:

  • main: Development branch (all CI checks, integration tests, PyPI publish)
  • staging: Pre-production validation (tests only, no publish)

CI Behavior:

Job main staging
Tests (Python 3.9-3.12) ✅ Runs ✅ Runs
Integration Tests ✅ Runs ❌ Skipped
Publish to PyPI ✅ Runs ❌ Skipped

Workflow:

  1. Develop on feature branches
  2. Merge to main → full CI + publish
  3. Merge to staging → test validation only
  4. Production releases via PyPI

Requirements

  • Python 3.9+
  • httpx >= 0.24.0
  • pydantic >= 2.0.0

License

MIT

Support

Download files

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

Source Distribution

moss_partner_sdk-0.2.0.tar.gz (111.4 kB view details)

Uploaded Source

Built Distribution

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

moss_partner_sdk-0.2.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file moss_partner_sdk-0.2.0.tar.gz.

File metadata

  • Download URL: moss_partner_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 111.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for moss_partner_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 baf2bdd1a742e2dd56b8b2577debea96ed0a34ed23b97aaf7365b4cb6929fe58
MD5 c4099ec9041cb15a6ae46cf9dd8b01b7
BLAKE2b-256 17344a613c552931b22bfa7657cdb462bc71150a6d61184445ae31d286e59ff9

See more details on using hashes here.

File details

Details for the file moss_partner_sdk-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for moss_partner_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc9c31032ab486887a73a91b30938bff26a61129f1771d278cf6d67ad03a54b8
MD5 7831531015363727f7c27b059edc92c3
BLAKE2b-256 652e1fece1e4eb6dcf98344aa1e039e1a561c0221212801b37d2a0e3a66c750b

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 Sentry Error logging StatusPage Status page