Skip to main content

Python SDK for Shannon multi-agent AI platform

Project description

Shannon Python SDK

Python client for Shannon multi-agent AI platform.

Version: 0.1.0a2 (Alpha)

Installation

# Development installation (from this directory)
pip install -e .

# With dev dependencies
pip install -e ".[dev]"

Quick Start

from shannon import ShannonClient

# Initialize client (HTTP-only)
client = ShannonClient(
    base_url="http://localhost:8080",
    api_key="your-api-key"  # or use bearer_token
)

# Submit a task
handle = client.submit_task(
    "Analyze market trends for Q4 2024",
    session_id="my-session",
)

print(f"Task submitted: {handle.task_id}")
print(f"Workflow ID: {handle.workflow_id}")

# Get status
status = client.get_status(handle.task_id)
print(f"Status: {status.status}")
print(f"Progress: {status.progress:.1%}")

# Cancel if needed
# client.cancel(handle.task_id, reason="User requested")

client.close()

CLI Examples

# Submit a task and wait for completion
python -m shannon.cli --base-url http://localhost:8080 submit "What is 2+2?" --wait

# List sessions (first 5)
python -m shannon.cli --base-url http://localhost:8080 session-list --limit 5

CLI Commands

Global flags:

  • --base-url (default: http://localhost:8080)
  • --api-key or --bearer-token
Command Arguments Description HTTP Endpoint
submit query --session-id --wait --idempotency-key --traceparent Submit a task (optionally wait) POST /api/v1/tasks
status task_id Get task status GET /api/v1/tasks/{id}
cancel task_id --reason Cancel a running or queued task POST /api/v1/tasks/{id}/cancel
stream workflow_id --types=a,b,c --traceparent Stream events via SSE (optionally filter types) GET /api/v1/stream/sse?workflow_id=...
approve approval_id workflow_id --approve/--reject --feedback Submit approval decision POST /api/v1/approvals/decision
session-list --limit --offset List sessions GET /api/v1/sessions
session-get session_id --no-history Get session details (optionally fetch history) GET /api/v1/sessions/{id} (+ GET /api/v1/sessions/{id}/history)
session-title session_id title Update session title PATCH /api/v1/sessions/{id}
session-delete session_id Delete a session DELETE /api/v1/sessions/{id}

One‑line examples:

  • submit: python -m shannon.cli --base-url http://localhost:8080 submit "Analyze quarterly revenue" --session-id my-session --wait
  • status: python -m shannon.cli --base-url http://localhost:8080 status task-123
  • cancel: python -m shannon.cli --base-url http://localhost:8080 cancel task-123 --reason "No longer needed"
  • stream: python -m shannon.cli --base-url http://localhost:8080 stream workflow-123 --types WORKFLOW_STARTED,LLM_OUTPUT,WORKFLOW_COMPLETED
  • approve: python -m shannon.cli --base-url http://localhost:8080 approve approval-uuid workflow-uuid --approve --feedback "Looks good"
  • session-list: python -m shannon.cli --base-url http://localhost:8080 session-list --limit 10 --offset 0
  • session-get: python -m shannon.cli --base-url http://localhost:8080 session-get my-session
  • session-title: python -m shannon.cli --base-url http://localhost:8080 session-title my-session "My Session Title"
  • session-delete: python -m shannon.cli --base-url http://localhost:8080 session-delete my-session

Async Usage

import asyncio
from shannon import AsyncShannonClient

async def main():
    async with AsyncShannonClient(
        base_url="http://localhost:8080",
        api_key="your-api-key"
    ) as client:
        handle = await client.submit_task("What is 2+2?")
        final = await client.wait(handle.task_id)
        print(f"Result: {final.result}")

asyncio.run(main())

Features

  • ✅ HTTP-only client using httpx
  • ✅ Task submission, status, wait, cancel
  • ✅ Event streaming via HTTP SSE (resume + filtering)
  • ✅ Approval decision endpoint
  • ✅ Session endpoints: list/get/history/events/update title/delete
  • ✅ CLI tool (submit, status, stream, approve, sessions)
  • ✅ Async-first design with sync wrapper
  • ✅ Type-safe enums (EventType, TaskStatusEnum)
  • ✅ Error mapping for common HTTP codes

Examples

The SDK includes comprehensive examples demonstrating key features:

  • simple_task.py - Basic task submission and status polling
  • simple_streaming.py - Event streaming with filtering
  • streaming_with_approvals.py - Approval workflow handling
  • workflow_routing.py - Using labels for workflow routing and task categorization
  • session_continuity.py - Multi-turn conversations with session management
  • template_usage.py - Template-based task execution with versioning

Run any example:

cd clients/python
python examples/simple_task.py

Development

# Run tests
make test

# Lint
make lint

# Format
make format

Project Structure

clients/python/
├── src/shannon/
│   ├── __init__.py      # Public API
│   ├── client.py        # AsyncShannonClient, ShannonClient
│   ├── models.py        # Data models (TaskHandle, TaskStatus, Event, etc.)
│   └── errors.py        # Exception hierarchy
├── tests/               # Integration tests
├── examples/            # Usage examples
└── pyproject.toml       # Package metadata

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

shannon_sdk-0.1.0a3.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

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

shannon_sdk-0.1.0a3-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file shannon_sdk-0.1.0a3.tar.gz.

File metadata

  • Download URL: shannon_sdk-0.1.0a3.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for shannon_sdk-0.1.0a3.tar.gz
Algorithm Hash digest
SHA256 b44cc5fc1f3747b7a280d14a4ea7ff44ab8dc743b80b7914a323948ebd131a65
MD5 56fc73c8c91caf7b8ca78a0b5be9d411
BLAKE2b-256 f9d2014d76b7f4b3fa30e6f24eb63a8da32f0c84b58b1979d88be03b77525726

See more details on using hashes here.

File details

Details for the file shannon_sdk-0.1.0a3-py3-none-any.whl.

File metadata

  • Download URL: shannon_sdk-0.1.0a3-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for shannon_sdk-0.1.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 9ac23ed193738394756fc8a3c4e939dd75430e67ee7064fe6fd6180205daec90
MD5 ea6533a2e2dc919d71c0de06846e7fd4
BLAKE2b-256 0403564f5b11c8c50ada3b91a4c9bce1beb0caaa69c544b159778d087516de74

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