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 Gatewaytimeout_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 codeerror_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 denialget_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wear_sdk-0.1.0rc1.tar.gz.
File metadata
- Download URL: wear_sdk-0.1.0rc1.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffc49130969737a6b8a73e875b35970914bcdcc090130d8e4f8eb8924f2df936
|
|
| MD5 |
345479c4ce8ca23c72913c005dcd0690
|
|
| BLAKE2b-256 |
b7e504c94d50105b66772c6800d4915201fdeacdab8c86e2131b0e973057c4d4
|
File details
Details for the file wear_sdk-0.1.0rc1-py3-none-any.whl.
File metadata
- Download URL: wear_sdk-0.1.0rc1-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
747f81132b27e7ddef98088493e709710af1d1667247d15257a4710b68f27333
|
|
| MD5 |
733b7b38896df20b1344fe668a03c9df
|
|
| BLAKE2b-256 |
397ea2696e537c495547cc706fa6ef6ec57e7cba0b331970150868727b29c717
|