gyoza.server#
gyoza server runtime — FastAPI application, repositories, and scheduler.
- gyoza.server.start(host=None, port=None, reload=None, workers=None, log_level=None)[source]#
Start the gyoza server.
Parameters passed explicitly take precedence over environment variables, which in turn take precedence over the built-in defaults. This lets the
gyoza server startCLI pass Typer-parsed values directly.
API#
Pydantic models for API request/response validation.
- class gyoza.server.api.models.InputSpecModel(*, type, required=True, default=None, description=None, example=None)[source]#
Bases:
BaseModelInput specification model.
- Parameters:
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.OutputSpecModel(*, type, description=None, example=None)[source]#
Bases:
BaseModelOutput specification model.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.ConstraintsModel(*, ram_mb=None, vram_mb=None, cpu=None, gpu_id=None, tags=<factory>)[source]#
Bases:
BaseModelHardware constraints model. An unset field reserves nothing.
- Parameters:
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.RetryPolicyModel(*, max_attempts=3)[source]#
Bases:
BaseModelRetry policy model.
- Parameters:
max_attempts (int)
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.EventDeliveryModel(*, topic='', attributes=None)[source]#
Bases:
BaseModelEvent delivery configuration model.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.OpDefinitionCreate(*, id, version, image, description=None, input_specs=None, output_specs=None, constraints=None, retry_policy=None, event_delivery=None)[source]#
Bases:
BaseModelRequest model for creating/updating OpDefinition.
- Parameters:
id (str)
version (str)
image (str)
description (str | None)
input_specs (dict[str, InputSpecModel] | None)
output_specs (dict[str, OutputSpecModel] | None)
constraints (ConstraintsModel | None)
retry_policy (RetryPolicyModel | None)
event_delivery (EventDeliveryModel | None)
- input_specs: dict[str, InputSpecModel] | None#
- output_specs: dict[str, OutputSpecModel] | None#
- constraints: ConstraintsModel | None#
- retry_policy: RetryPolicyModel | None#
- event_delivery: EventDeliveryModel | None#
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.OpDefinitionResponse(*, id, version, image, description=None, input_specs, output_specs, constraints, retry_policy, event_delivery, createdAt, updatedAt)[source]#
Bases:
BaseModelResponse model for OpDefinition.
- Parameters:
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.OpDefinitionDeleteResponse(*, id, version=None, deleted)[source]#
Bases:
BaseModelResponse model for an OpDefinition deletion.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.LogicalSubmission(*, inputs, outputs)[source]#
Bases:
BaseModelStable resources/parameters supplied by the caller, excluding signed URLs.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.OpRunCreateFromDefinition(*, idempotency_key=None, logical_payload=None, inputs=<factory>, outputs=<factory>, priority=0, event_delivery=None)[source]#
Bases:
BaseModelRequest model for creating OpRun from OpDefinition.
This is used when creating a run from a template (OpDefinition). For creating runs from scratch, use OpRunCreate (to be implemented).
- Parameters:
idempotency_key (str | None)
logical_payload (LogicalSubmission | None)
priority (int)
event_delivery (EventDeliveryModel | None)
- logical_payload: LogicalSubmission | None#
- event_delivery: EventDeliveryModel | None#
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.OpRunResponse(*, id, state, priority, progress, current_attempt, image, inputs, outputs, events, execution_summary, constraints, reservation, retry_policy, event_delivery, op_definition, op_definition_version=None, idempotency_key=None, createdAt, updatedAt)[source]#
Bases:
BaseModelResponse model for OpRun.
- Parameters:
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.OpRunListItem(*, id, state, priority, progress, current_attempt, image, inputs=None, outputs=None, events=None, execution_summary, constraints, retry_policy, event_delivery, op_definition, createdAt, updatedAt)[source]#
Bases:
BaseModelOpRun as returned by the list endpoint.
inputs,outputsandeventscan be arbitrarily large (GeoJSON inputs, one event per progress line), so the listing omits them unless explicitly requested via?expand=.- Parameters:
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.OpRunListResponse(*, object='list', data, has_more, url='/runs')[source]#
Bases:
BaseModelStripe-style list response with cursor-based pagination.
- Parameters:
object (str)
data (list[OpRunListItem])
has_more (bool)
url (str)
- data: list[OpRunListItem]#
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.RunStatsWindow(*, start, end, bucket_seconds, buckets)[source]#
Bases:
BaseModelThe resolved time window a stats response covers.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.RunStatsTotals(*, all, by_state=<factory>)[source]#
Bases:
BaseModelRun counts over the whole window.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.RunStatsDefinition(*, op_definition, count, buckets)[source]#
Bases:
BaseModelPer-definition activity within the window.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.RunStatsResponse(*, object='run_stats', window, totals, definitions)[source]#
Bases:
BaseModelAggregated run activity, computed server-side.
Lets a dashboard render totals and per-definition sparklines from one small response instead of paginating every run in the window.
- Parameters:
object (str)
window (RunStatsWindow)
totals (RunStatsTotals)
definitions (list[RunStatsDefinition])
- window: RunStatsWindow#
- totals: RunStatsTotals#
- definitions: list[RunStatsDefinition]#
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.OpRunCreate(*, image, priority=0, inputs=<factory>, outputs=<factory>, constraints=None, retry_policy=None, event_delivery=None)[source]#
Bases:
BaseModelRequest model for creating OpRun directly (ad-hoc).
This is used when creating a run from scratch without a template. For creating runs from OpDefinition, use OpRunCreateFromDefinition.
- Parameters:
image (str)
priority (int)
constraints (ConstraintsModel | None)
retry_policy (RetryPolicyModel | None)
event_delivery (EventDeliveryModel | None)
- constraints: ConstraintsModel | None#
- retry_policy: RetryPolicyModel | None#
- event_delivery: EventDeliveryModel | None#
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.OpRunUpdate(*, state=None, outputs=None, priority=None)[source]#
Bases:
BaseModelRequest model for updating OpRun via PATCH.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.OpAttemptResponse(*, id, op_run_id, attempt, state, progress, events, inputs, outputs, execution_summary, constraints, reservation, started_at, finished_at)[source]#
Bases:
BaseModelResponse model for OpAttempt.
- Parameters:
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.AddEventRequest(*, type, msg, payload=None, attempt=None, worker_id=None)[source]#
Bases:
BaseModelRequest model for adding an event to an attempt.
- Parameters:
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.EventEntryResponse(*, id, type, t, msg, state, payload=<factory>)[source]#
Bases:
BaseModelResponse model for a single event entry.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.EventsResponse(*, events)[source]#
Bases:
BaseModelResponse model for polling events.
- Parameters:
events (list[EventEntryResponse])
- events: list[EventEntryResponse]#
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.TopicEventResponse(*, cursor, run_id, attempt, type, msg, t, state, payload=<factory>)[source]#
Bases:
BaseModelA single event in the topic feed.
- Parameters:
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.TopicEventsResponse(*, events, next_cursor=None, has_more=False)[source]#
Bases:
BaseModelCursor-paginated event feed for a topic.
- Parameters:
events (list[TopicEventResponse])
next_cursor (str | None)
has_more (bool)
- events: list[TopicEventResponse]#
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.ErrorResponse(*, detail, errors=None)[source]#
Bases:
BaseModelError response model.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.GPUModel(*, id, vram_mb, tags=<factory>)[source]#
Bases:
BaseModelGPU resource model.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.ResourcesModel(*, cpu_cores, ram_mb, gpus=<factory>)[source]#
Bases:
BaseModelHardware resources model.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.HeartbeatRequest(*, worker_id, resources, tags=<factory>, running_ops=None)[source]#
Bases:
BaseModelRequest model for worker heartbeat.
- Parameters:
- resources: ResourcesModel#
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.WorkerResponse(*, id, resources, tags, running_ops, created_at, last_heartbeat_at, is_active)[source]#
Bases:
BaseModelResponse model for Worker.
- Parameters:
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.WorkerOpRunResponse(*, id, image, inputs, outputs=<factory>, constraints, attempt=None, reservation=None)[source]#
Bases:
BaseModelResponse model for WorkerOpRun.
- Parameters:
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.ClaimOpsResponse(*, ops)[source]#
Bases:
BaseModelResponse model for claim ops endpoint.
- Parameters:
ops (list[WorkerOpRunResponse])
- ops: list[WorkerOpRunResponse]#
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Op Definition#
Repository for OpDefinition persistence.
This is the only place that knows about MongoDB. It handles serialization and deserialization of OpDefinition entities. OpDefinitions are identified by a composite key (id + version). Multiple versions of the same definition can coexist.
- class gyoza.server.op_definition.repository.OpDefinitionRepository(collection)[source]#
Bases:
objectRepository for OpDefinition persistence.
Supports versioning - definitions are identified by (id, version). Same id + version = replace. Same id + different version = new entry.
- Parameters:
collection (
Collection) – MongoDB collection for OpDefinitions.
- get(definition_id, version=None)[source]#
Retrieve an OpDefinition by its ID and optionally version.
- Parameters:
- Returns:
The OpDefinition if found, None otherwise.
- Return type:
- upsert(definition)[source]#
Create or update an OpDefinition.
If an OpDefinition with the same id AND version exists, it will be replaced. If the version is different, a new entry is created (preserving old versions).
- Parameters:
definition (
OpDefinition) – The OpDefinition to upsert.- Returns:
The upserted OpDefinition with updated timestamps.
- Return type:
- save(definition)[source]#
Persist an OpDefinition (insert or update).
- Parameters:
definition (
OpDefinition) – The OpDefinition to persist.- Return type:
- delete(definition_id, version=None)[source]#
Delete an OpDefinition by its ID and optionally version.
- list_all()[source]#
List all OpDefinitions (all versions).
- Returns:
All OpDefinitions in the collection.
- Return type:
- list_versions(definition_id)[source]#
List all versions of an OpDefinition.
- Parameters:
definition_id (
str) – The unique identifier of the OpDefinition.- Returns:
All versions of the definition, sorted by created_at descending.
- Return type:
MongoDB connection for the op_definition subdomain.
This module is responsible for: - Creating the MongoClient (with internal connection pool) - Selecting the database - Exposing ready-to-use collections
This runs ONCE when the subdomain is imported.
Op Run#
Scheduler#
Worker Pool#
WorkerPool for in-memory worker management.
Workers register via heartbeats and are stored in memory. No database persistence since workers are ephemeral.
- class gyoza.server.worker.pool.WorkerPool[source]#
Bases:
objectIn-memory pool of workers.
Workers register themselves via heartbeats containing their full configuration. Each heartbeat creates or updates the worker entry.
- heartbeat(hb)[source]#
Register or update a worker via heartbeat.
If worker exists, updates resources, tags and last_heartbeat_at. If worker is new, creates it with current timestamp.
Worker entity.
Workers are ephemeral resources that execute tasks and send heartbeats.
- class gyoza.server.worker.worker.Worker(id, resources, tags=list(), running_ops=list(), created_at=<factory>, last_heartbeat_at=<factory>)[source]#
Bases:
objectRepresentation of a worker that can execute tasks.
Workers are identified by their id (name) and register themselves via heartbeats containing their resources and tags.
- Parameters:
- running_ops: list[WorkerOpRun]#
- can_run(constraints)[source]#
Check if a run asking for constraints fits this worker when idle.
- Parameters:
constraints (
Constraints) – Requirements of the run.- Returns:
True if the worker has every required tag, enough RAM and a GPU with enough VRAM.
- Return type:
Value objects for the Worker subdomain.
These are simple data structures representing hardware resources and execution tasks.
- class gyoza.server.worker.resources.GPU(id, vram_mb, tags=list())[source]#
Bases:
objectRepresentation of a single GPU.
- Parameters:
- class gyoza.server.worker.resources.Resources(cpu_cores, ram_mb, gpus=list())[source]#
Bases:
objectHardware resources available on a worker.
- Parameters:
- class gyoza.server.worker.resources.WorkerOpRun(id, image, inputs=dict(), outputs=dict(), constraints=Constraints(), attempt=None, reservation=None)[source]#
Bases:
objectSimplified OpRun representation for worker execution. Contains only the essential fields needed for a worker to execute a task.
- Parameters:
id (
str) – Unique identifier for the run.image (
str) – Docker image identifier.outputs (
dict[str,Any]) – Partial outputs template (fields pre-filled with upload URLs).constraints (
Constraints) – Hardware requirements.attempt (
int|None) – Attempt number the worker was handed. Its events carry it so the server can refuse the ones an abandoned attempt sends late.
- constraints: Constraints#
- classmethod from_dict(data)[source]#
Create from dictionary representation.
- Return type:
- Parameters:
- class gyoza.server.worker.resources.Heartbeat(worker_id, resources, tags=list(), running_ops=None)[source]#
Bases:
objectHeartbeat sent by a worker to register or update itself.
This is the payload workers send via REST to announce their presence.
- Parameters:
- running_ops: list[WorkerOpRun] | None = None#
Runner#
Server runner.
Entry point called by gyoza server start. Verifies connections and
starts the uvicorn server with configuration from environment variables.
Environment variables#
- GYOZA_HOST
Host to bind to. Defaults to
127.0.0.1.- GYOZA_PORT
Port to bind to. Defaults to
5555.- GYOZA_RELOAD
Enable auto-reload for development. Defaults to
false.- GYOZA_WORKERS
Number of uvicorn worker processes. Defaults to
1.- GYOZA_LOG_LEVEL
Logging level (
debug,info,warning,error). Defaults toinfo.
- gyoza.server.runner.start(host=None, port=None, reload=None, workers=None, log_level=None)[source]#
Start the gyoza server.
Parameters passed explicitly take precedence over environment variables, which in turn take precedence over the built-in defaults. This lets the
gyoza server startCLI pass Typer-parsed values directly.