snoozeml.config — Configuration, Worker Scaffolding & Daemon Runner#
Programmatic configuration builder, custom worker scaffolder, and local daemon runner for SnoozeML.
Generates validated models.toml, streams.toml, and models.json configuration
files matching SnoozeML’s Rust configuration schema (src/config.rs), scaffolds
process-isolated Python worker directories (snooze_model.py), and manages local
snooze serve child processes from Python.
- class snoozeml.config.GlobalDefaultsConfig(idle_timeout_secs=300, max_batch_size=16, max_batch_delay_ms=10, device='auto', max_loaded_models=None, min_residency_secs=10, autoscale_queue_threshold=None, max_replicas=None, routing_strategy=None, pinned=None)[source]#
Bases:
objectGlobal fallback model settings matching
[defaults]inmodels.toml.- Parameters:
- class snoozeml.config.ModelConfigEntry(id, path, description=None, device=None, max_batch_size=None, max_batch_delay_ms=None, idle_timeout_secs=None, min_residency_secs=None, autoscale_queue_threshold=None, max_replicas=None, routing_strategy=None, pinned=None)[source]#
Bases:
objectPer-model configuration entry matching
[[models]]inmodels.toml.- Parameters:
id (str)
path (str)
description (str | None)
device (str | None)
max_batch_size (int | None)
max_batch_delay_ms (int | None)
idle_timeout_secs (int | None)
min_residency_secs (int | None)
autoscale_queue_threshold (int | None)
max_replicas (int | None)
routing_strategy (str | None)
pinned (bool | None)
- class snoozeml.config.StreamBinding(name='default-stream', broker='redis', endpoint='redis://127.0.0.1:6379', input_topic='snooze.requests', model_id=None, output_topic='snooze.responses', error_topic='snooze.dlq', consumer_group='snoozeml-group', auto_create_topics=True, concurrency=16, partitions=1, format=StreamWireFormat.JSON)[source]#
Bases:
objectEvent stream binding configuration matching
[[streams]]inmodels.toml.- Parameters:
- model_id#
Optional target model ID (if
None, dynamically routes per messagemodel_id).- Type:
str | None
- output_topic#
Optional destination topic/queue/stream for responses (default
"snooze.responses").- Type:
str | None
- error_topic#
Optional Dead-Letter Queue (DLQ) topic for failed messages (default
"snooze.dlq").- Type:
str | None
- format#
Wire serialization format (
"json"or"protobuf").- Type:
- format: StreamWireFormat | str = 'json'#
- class snoozeml.config.ApiKeyEntry(role=Role.INFERENCE, key=None, key_env=None, name=None)[source]#
Bases:
objectStatic API key configuration entry matching
[[auth.api_keys]].
- class snoozeml.config.JwtSettings(secret=None, secret_env=None, algorithm=JwtAlgorithm.HS256, issuer=None, audience=None, leeway_secs=60)[source]#
Bases:
objectJWT authentication configuration matching
[auth.jwt].- Parameters:
- algorithm: JwtAlgorithm | str = 'HS256'#
- class snoozeml.config.AuthSettings(enabled=True, protect_metrics=False, api_keys=<factory>, jwt=None)[source]#
Bases:
objectAuthentication and RBAC settings matching
[auth]inmodels.toml.- Parameters:
enabled (bool)
protect_metrics (bool)
api_keys (List[ApiKeyEntry])
jwt (JwtSettings | None)
- api_keys: List[ApiKeyEntry]#
- jwt: JwtSettings | None = None#
- class snoozeml.config.SnoozeConfig(defaults=<factory>, models=<factory>, streams=<factory>, auth=None)[source]#
Bases:
objectComplete programmatic configuration for a SnoozeML model directory and streaming pipelines.
Allows Python users to configure models, Kafka/RabbitMQ/Redis streams, and RBAC authentication purely in Python and export them to
models.tomlormodels.jsonfor thesnoozebinary.Example:
from snoozeml import SnoozeConfig cfg = ( SnoozeConfig() .add_model("iris-rf", path="iris_rf.onnx", pinned=True, max_batch_size=32) .add_stream( name="redis-pipeline", broker="redis", endpoint="redis://127.0.0.1:6379", input_topic="snooze.requests", output_topic="snooze.responses", model_id="iris-rf", ) .add_api_key(role="admin", key_env="SNOOZE_ADMIN_KEY", name="admin-cli") ) cfg.save("models/models.toml")
- Parameters:
defaults (GlobalDefaultsConfig)
models (List[ModelConfigEntry])
streams (List[StreamBinding])
auth (AuthSettings | None)
- defaults: GlobalDefaultsConfig#
- models: List[ModelConfigEntry]#
- streams: List[StreamBinding]#
- auth: AuthSettings | None = None#
- add_model(id, path, *, description=None, device=None, max_batch_size=None, max_batch_delay_ms=None, idle_timeout_secs=None, min_residency_secs=None, autoscale_queue_threshold=None, max_replicas=None, routing_strategy=None, pinned=None)[source]#
Appends a model configuration entry and returns
selffor fluent chaining.- Parameters:
id (str)
path (str)
description (str | None)
device (str | None)
max_batch_size (int | None)
max_batch_delay_ms (int | None)
idle_timeout_secs (int | None)
min_residency_secs (int | None)
autoscale_queue_threshold (int | None)
max_replicas (int | None)
routing_strategy (str | None)
pinned (bool | None)
- Return type:
- add_stream(name='default-stream', broker='redis', endpoint='redis://127.0.0.1:6379', input_topic='snooze.requests', *, model_id=None, output_topic='snooze.responses', error_topic='snooze.dlq', consumer_group='snoozeml-group', auto_create_topics=True, concurrency=16, partitions=1, format=StreamWireFormat.JSON)[source]#
Appends a message stream binding (Kafka, RabbitMQ, Redis, or Mock) and returns
self.
- add_api_key(role=Role.INFERENCE, *, key=None, key_env=None, name=None, protect_metrics=None)[source]#
Adds an API key entry to
[auth](enabling authentication) and returnsself.
- set_jwt(*, secret=None, secret_env=None, algorithm=JwtAlgorithm.HS256, issuer=None, audience=None, leeway_secs=60, protect_metrics=None)[source]#
Configures
[auth.jwt]verification settings and returnsself.- Parameters:
- Return type:
- to_toml()[source]#
Serializes the configuration into a TOML string compatible with
src/config.rs.- Return type:
- save(path)[source]#
Writes the configuration to disk as TOML (
.toml) or JSON (.json).- Parameters:
path (str | Path) – Target filesystem path (e.g.
"models/models.toml"or"models/models.json").- Returns:
Resolved
pathlib.Pathof the written configuration file.- Return type:
- classmethod from_dict(data)[source]#
Constructs a
SnoozeConfigfrom a parsed dictionary.- Parameters:
- Return type:
- snoozeml.config.scaffold_worker(output_dir, *, model_code=None, entrypoint='snooze_model.py', class_name='Model', tensor_format='numpy', python=None, env=None, requirements=None, verify=True, verify_inputs=None, verify_device='cpu')[source]#
Scaffolds a process-isolated custom Python worker model directory (snooze_model.py).
Creates
snooze_model.py,snooze_model.json, and an optionalrequirements.txtinsideoutput_dir, and optionally runssnoozeml.worker.run_checkto verify that the worker loads and predicts cleanly.- Parameters:
output_dir (str | Path) – Target model directory (e.g.
"models/my-custom-worker").model_code (str | None) – Python source code defining the worker model class. If
None, generates a ready-to-customize template class.entrypoint (str) – Entrypoint script filename (default
"snooze_model.py").class_name (str) – Model class name inside
entrypoint(default"Model").tensor_format (str) – Input tensor format passed to
predict()("numpy"or"raw").python (str | None) – Optional custom Python interpreter path written to
snooze_model.json.env (Mapping[str, str] | None) – Optional environment variables mapping written to
snooze_model.json.requirements (Sequence[str] | None) – Optional list of pip requirement specifiers written to
requirements.txt.verify (bool) – If
True, smoke-tests the generated worker immediately viarun_check().verify_inputs (Sequence[str] | None) – Input specification strings for
run_check(default["input:2x4"]).verify_device (str) – Device string passed to
run_check(default"cpu").
- Returns:
Resolved
pathlib.Pathto the scaffolded worker directory.- Return type:
- snoozeml.config.find_snooze_binary(explicit_path=None)[source]#
Locates the
snoozedaemon executable on the system.Checks
explicit_path,SNOOZE_BINenvironment variable, systemPATH, and local Cargo build directories (target/release/snooze,target/debug/snooze).
- class snoozeml.config.SnoozeDaemon(*, config=None, models_dir=None, host='127.0.0.1', port=8080, grpc_port=50051, grpc=True, demo=False, api_key=None, jwt_secret=None, binary_path=None, startup_timeout=15.0)[source]#
Bases:
objectContext-managed local
snooze serveprocess controller for Python workflows.Allows launching a configured SnoozeML daemon (including
[[streams]],[[models]], and[auth]) directly from Python scripts, tests, or Jupyter notebooks without modifying the Rust binary.- Parameters:
- build_command(resolved_models_dir, config_path)[source]#
Constructs the
snooze serveCLI command list.
- start()[source]#
Starts the
snooze servechild process and waits until/health/readyresponds.- Return type:
- stop()[source]#
Stops the
snooze servechild process and cleans up temporary directories.- Return type:
None
- client(*, use_grpc=False)[source]#
Returns a configured
SnoozeClientconnected to this daemon.- Parameters:
use_grpc (bool)
- Return type: