gyoza.client#
gyoza server API client.
Provides both the GyozaClient class for explicit construction and a
pre-configured gyoza_client singleton for use by other modules.
Environment variables#
- GYOZA_SERVER_URL
Base URL of the gyoza server. Defaults to
http://localhost:5555.- GYOZA_API_KEY
API key for authentication. Required.
- class gyoza.client.GyozaClient(base_url, api_key=None, timeout=30.0)[source]#
Bases:
objectHTTP client covering all gyoza server API endpoints.
- Parameters:
- create_run(image, inputs, *, priority=5, constraints=None, retry_policy=None, event_delivery=None)[source]#
Create an ad-hoc OpRun without an OpDefinition.
- Parameters:
image (
str) – Docker image reference to execute.priority (
int) – Scheduling priority (higher value = higher priority).constraints (
dict[str,Any] |None) – Hardware requirements override.retry_policy (
dict[str,Any] |None) – Retry behaviour override.event_delivery (
dict[str,Any] |None) – Event delivery configuration override.
- Returns:
The created OpRun.
- Return type:
- Raises:
httpx.HTTPStatusError – On non-2xx responses.
- create_run_from_definition(name, inputs, *, version=None, priority=5)[source]#
Create an OpRun from a registered OpDefinition.
- Parameters:
- Returns:
The created OpRun.
- Return type:
- Raises:
httpx.HTTPStatusError – 404 if the definition does not exist, 400 on invalid inputs.
- update_run(run_id, *, state=None, outputs=None, priority=None)[source]#
Partially update an OpRun’s state, outputs, or priority.
- Parameters:
- Returns:
The updated OpRun.
- Return type:
- Raises:
httpx.HTTPStatusError – 404 if not found, 400 on invalid state transition.
- add_event(run_id, event_type, msg, payload=None)[source]#
Append an event to the current attempt of an OpRun.
Called by the worker during execution to report progress, completion, or failure. Special event types (
STARTED,COMPLETED,FAILED,CANCELLED) trigger state transitions on the run.- Parameters:
run_id (
str) – Unique identifier of the OpRun.event_type (
str) – Event type string (seeEventType).msg (
str|int) – Human-readable message or progress value (0–100 for PROGRESS).payload (
dict[str,Any] |None) – Optional event-specific data (e.g.{"outputs": {...}}for COMPLETED,{"error_message": "..."}for FAILED).
- Returns:
The updated OpRun.
- Return type:
- Raises:
httpx.HTTPStatusError – 404 if not found, 400 if the run is locked or event is invalid.
- poll_events(run_id, after=None)[source]#
Poll events for an OpRun, optionally from a given index.
- Parameters:
- Returns:
{"events": [...]}where each entry hasid,type,t,msg, andstate.- Return type:
- Raises:
httpx.HTTPStatusError – 404 if the run does not exist.
- heartbeat(worker_id, resources, tags=None, running_ops=None)[source]#
Register or update a worker via heartbeat.
- Parameters:
worker_id (
str) – Unique identifier for the worker.resources (
dict[str,Any]) – Worker resources with keyscpu_cores,ram_mb, andgpus(list of{"id": int, "vram_mb": int, "tags": [...]})tags (
list[str] |None) – Worker capability tags (e.g.["gpu", "high-mem"]).running_ops (
list[dict[str,Any]] |None) – Currently executing ops asWorkerOpRundicts.
- Returns:
The created or updated Worker object.
- Return type:
- Raises:
httpx.HTTPStatusError – On non-2xx responses.
Unified HTTP client for the gyoza server API.
Used by the worker (heartbeat, claim ops, send events) and the CLI deployment pipeline (upsert definitions, create runs).
- class gyoza.client._client.GyozaClient(base_url, api_key=None, timeout=30.0)[source]#
Bases:
objectHTTP client covering all gyoza server API endpoints.
- Parameters:
- create_run(image, inputs, *, priority=5, constraints=None, retry_policy=None, event_delivery=None)[source]#
Create an ad-hoc OpRun without an OpDefinition.
- Parameters:
image (
str) – Docker image reference to execute.priority (
int) – Scheduling priority (higher value = higher priority).constraints (
dict[str,Any] |None) – Hardware requirements override.retry_policy (
dict[str,Any] |None) – Retry behaviour override.event_delivery (
dict[str,Any] |None) – Event delivery configuration override.
- Returns:
The created OpRun.
- Return type:
- Raises:
httpx.HTTPStatusError – On non-2xx responses.
- create_run_from_definition(name, inputs, *, version=None, priority=5)[source]#
Create an OpRun from a registered OpDefinition.
- Parameters:
- Returns:
The created OpRun.
- Return type:
- Raises:
httpx.HTTPStatusError – 404 if the definition does not exist, 400 on invalid inputs.
- update_run(run_id, *, state=None, outputs=None, priority=None)[source]#
Partially update an OpRun’s state, outputs, or priority.
- Parameters:
- Returns:
The updated OpRun.
- Return type:
- Raises:
httpx.HTTPStatusError – 404 if not found, 400 on invalid state transition.
- add_event(run_id, event_type, msg, payload=None)[source]#
Append an event to the current attempt of an OpRun.
Called by the worker during execution to report progress, completion, or failure. Special event types (
STARTED,COMPLETED,FAILED,CANCELLED) trigger state transitions on the run.- Parameters:
run_id (
str) – Unique identifier of the OpRun.event_type (
str) – Event type string (seeEventType).msg (
str|int) – Human-readable message or progress value (0–100 for PROGRESS).payload (
dict[str,Any] |None) – Optional event-specific data (e.g.{"outputs": {...}}for COMPLETED,{"error_message": "..."}for FAILED).
- Returns:
The updated OpRun.
- Return type:
- Raises:
httpx.HTTPStatusError – 404 if not found, 400 if the run is locked or event is invalid.
- poll_events(run_id, after=None)[source]#
Poll events for an OpRun, optionally from a given index.
- Parameters:
- Returns:
{"events": [...]}where each entry hasid,type,t,msg, andstate.- Return type:
- Raises:
httpx.HTTPStatusError – 404 if the run does not exist.
- heartbeat(worker_id, resources, tags=None, running_ops=None)[source]#
Register or update a worker via heartbeat.
- Parameters:
worker_id (
str) – Unique identifier for the worker.resources (
dict[str,Any]) – Worker resources with keyscpu_cores,ram_mb, andgpus(list of{"id": int, "vram_mb": int, "tags": [...]})tags (
list[str] |None) – Worker capability tags (e.g.["gpu", "high-mem"]).running_ops (
list[dict[str,Any]] |None) – Currently executing ops asWorkerOpRundicts.
- Returns:
The created or updated Worker object.
- Return type:
- Raises:
httpx.HTTPStatusError – On non-2xx responses.