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(**data)[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(**data)[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(**data)[source]#
Bases:
BaseModelHardware constraints model. An unset field reserves nothing.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.RetryPolicyModel(**data)[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(**data)[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(**data)[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(**data)[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(**data)[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.OpRunCreateFromDefinition(**data)[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:
- 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(**data)[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(**data)[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(**data)[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(**data)[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(**data)[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(**data)[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(**data)[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(**data)[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(**data)[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(**data)[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(**data)[source]#
Bases:
BaseModelRequest model for adding an event to an attempt.
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gyoza.server.api.models.EventEntryResponse(**data)[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(**data)[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(**data)[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(**data)[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(**data)[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(**data)[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(**data)[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(**data)[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(**data)[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(**data)[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(**data)[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=<factory>, running_ops=<factory>, 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]#
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=<factory>)[source]#
Bases:
objectRepresentation of a single GPU.
- Parameters:
- class gyoza.server.worker.resources.Resources(cpu_cores, ram_mb, gpus=<factory>)[source]#
Bases:
objectHardware resources available on a worker.
- Parameters:
- class gyoza.server.worker.resources.WorkerOpRun(id, image, inputs=<factory>, outputs=<factory>, constraints=<factory>)[source]#
Bases:
objectSimplified OpRun representation for worker execution. Contains only the essential fields needed for a worker to execute a task.
- Parameters:
- constraints: Constraints#
- classmethod from_dict(data)[source]#
Create from dictionary representation.
- Return type:
- Parameters:
- class gyoza.server.worker.resources.Heartbeat(worker_id, resources, tags=<factory>, 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.