Skip to main content

Python SDK for WEAR Gateway

Project description

wear-sdk

Python SDK for the WEAR (Warehouse Exchange Agent Resources) Gateway.

Installation

pip install wear-sdk

Usage

from wear_sdk import WearClient, WearClientOptions, WearError

# Create client
client = WearClient(WearClientOptions(
    base_url="https://wear-gateway-staging-xxx.run.app",
    timeout_ms=10000,  # optional, default 10s
))

try:
    # Start a run (requires JWT from /v1/agents/token)
    result = client.start_run("my-agent-id", jwt)
    print(f"Run started: {result.run_id} at {result.started_at}")
    
except WearError as error:
    print(f"Error {error.status_code}: {error}")
    
    # Check for specific denial types
    if error.is_policy_denied():
        print(f"Policy denied: {error.get_denial_reason()}")
        print(f"Rule ID: {error.error_response.rule_id}")
    elif error.is_budget_denied():
        print(f"Budget exceeded: {error.get_denial_reason()}")

finally:
    client.close()

Context Manager

from wear_sdk import WearClient, WearClientOptions

with WearClient(WearClientOptions(base_url="https://...")) as client:
    result = client.start_run("my-agent-id", jwt)
    print(f"Run ID: {result.run_id}")

API

WearClient

Constructor

WearClient(options: WearClientOptions)

Options:

  • base_url (str, required): Base URL of the WEAR Gateway
  • timeout_ms (int, optional): Request timeout in milliseconds (default: 10000)

Methods

start_run(agent_id: str, jwt: str) -> StartRunResponse

Starts a new agent run.

Headers sent:

  • Authorization: Bearer <jwt>
  • X-WEAR-Agent-ID: <agent_id>

Returns:

StartRunResponse(
    run_id: str,
    started_at: str,
    correlation_id: Optional[str]
)

Raises: WearError on policy denial, budget exceeded, or other errors.

close() -> None

Closes the HTTP client. Always call this when done, or use the context manager.

WearError

Custom exception class with additional context.

Attributes:

  • status_code (int): HTTP status code
  • error_response (WearErrorResponse): Parsed error response from Gateway

Methods:

  • is_policy_denied(): Returns True if this is a policy denial (403 with code)
  • is_budget_denied(): Returns True if this is a budget denial
  • get_denial_reason(): Returns the denial reason if available

Development

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

# Run tests
pytest

# Run tests with coverage
pytest --cov=wear_sdk --cov-report=html

# Type checking
mypy wear_sdk

# Linting
ruff check wear_sdk

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

wear_sdk-0.1.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

wear_sdk-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file wear_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: wear_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for wear_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 08035ba11c2a8fef72a89e60abd60ce7048d70f5076a98bcecf026d2386ac95b
MD5 e778149c3fbcfecd43f22f068a7bb125
BLAKE2b-256 37e96769ef90db234b534678e6ce053adc0491254ec370bc931f6cbe80d9fcb9

See more details on using hashes here.

File details

Details for the file wear_sdk-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for wear_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71b63a3e22f370c2f3ae2a80039c1882c22523bcf39e4c1f3f68618ec2b7b326
MD5 a5d6a92ab0c7351a464ca6f95fe00167
BLAKE2b-256 117767546754fba5ed14432f2e2717090e5159cc916049557b34eb6d3bc99088

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