API Reference¶
All public Python APIs in assgen are documented here, auto-generated from
source-code docstrings using mkdocstrings.
Every function, class, and attribute shown below includes its type signature,
parameter descriptions, and return/raises information derived directly from the
code — no separate doc-maintenance required.
Catalog¶
Job-type → HuggingFace model ID mapping. Users can override entries in
~/.config/assgen/models.yaml.
catalog ¶
Catalog loader — merges the built-in catalog.yaml with any user overrides.
The catalog maps every game-dev job type (e.g. visual.model.create) to a
HuggingFace model ID and associated metadata. The built-in defaults live in
catalog.yaml alongside this module; users can override any entry by adding
the same key to ~/.config/assgen/models.yaml under the catalog: key.
Example
from assgen.catalog import load_catalog, get_model_for_job catalog = load_catalog() entry = get_model_for_job("visual.model.create") entry["model_id"] 'stabilityai/TripoSR'
load_catalog
cached
¶
Load and return the merged job-type → model catalog.
Reads the built-in catalog.yaml first, then overlays any entries
found in ~/.config/assgen/models.yaml. The result is cached; call
load_catalog.cache_clear() after modifying the user catalog.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
A dict mapping job-type strings to catalog entry dicts. Each entry |
dict[str, dict[str, Any]]
|
contains at least |
Example
catalog = load_catalog() "visual.model.create" in catalog True
Source code in src/assgen/catalog.py
get_model_for_job ¶
Return the catalog entry for job_type, or None if unknown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_type
|
str
|
Dot-separated task identifier, e.g. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
A dict with keys |
dict[str, Any] | None
|
|
Example
get_model_for_job("audio.sfx.generate")["name"] 'AudioGen Medium'
Source code in src/assgen/catalog.py
all_job_types ¶
Return a sorted list of every job type in the catalog.
Returns:
| Type | Description |
|---|---|
list[str]
|
Alphabetically sorted list of job-type strings. |
all_model_ids ¶
Return a deduplicated list of every HF model ID referenced in the catalog.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of |
list[str]
|
duplicates (multiple job types often share the same base model). |
Source code in src/assgen/catalog.py
Database¶
SQLite persistence layer for jobs, models, and usage records.
db ¶
SQLite database schema and helpers for assgen.
Tables
jobs — all submitted jobs and their lifecycle state model_usage — record of which model was used for each job (analytics) models — locally installed model metadata
Migrations are handled by a simple version table; new columns/tables are added incrementally so existing databases are upgraded automatically.
JobStatus ¶
String constants for job lifecycle states.
Attributes:
| Name | Type | Description |
|---|---|---|
QUEUED |
Job is waiting to be picked up by a worker. |
|
RUNNING |
A worker is actively processing the job. |
|
COMPLETED |
Job finished successfully. |
|
FAILED |
Job terminated with an error. |
|
CANCELLED |
Job was explicitly cancelled before completion. |
|
TERMINAL |
The set of states from which no transition is possible. |
get_connection ¶
Open a SQLite connection with WAL mode and foreign-key enforcement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_path
|
Path | None
|
Path to the SQLite file. Defaults to the platform-appropriate
config directory ( |
None
|
Returns:
| Type | Description |
|---|---|
Connection
|
An open |
Connection
|
WAL journal mode, and foreign keys enabled. |
Source code in src/assgen/db.py
transaction ¶
Context manager that commits on success or rolls back on any exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
An open SQLite connection. |
required |
Yields:
| Type | Description |
|---|---|
Connection
|
The same connection, for use inside a |
Raises:
| Type | Description |
|---|---|
Exception
|
Re-raises whatever caused the rollback. |
Source code in src/assgen/db.py
init_db ¶
Ensure the database is initialised and migrated; return an open connection.
Source code in src/assgen/db.py
create_job ¶
create_job(conn: Connection, job_type: str, params: dict[str, Any], priority: int = 0, tags: list[str] | None = None) -> str
Insert a new QUEUED job and return its UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
An open database connection. |
required |
job_type
|
str
|
Dot-separated task identifier, e.g. |
required |
params
|
dict[str, Any]
|
Arbitrary key/value pairs forwarded to the inference handler. |
required |
priority
|
int
|
Worker priority; higher values are processed first (0–100). |
0
|
tags
|
list[str] | None
|
Optional list of string labels for filtering/grouping. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The newly created job's UUID string. |
Source code in src/assgen/db.py
get_job ¶
Look up a job by exact UUID or unambiguous 8-character prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
An open database connection. |
required |
job_id
|
str
|
Full UUID or a prefix of at least 8 characters. If the prefix
matches more than one job, |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
A dict representation of the job row, or |
Source code in src/assgen/db.py
list_jobs ¶
list_jobs(conn: Connection, statuses: list[str] | None = None, limit: int = 50) -> list[dict[str, Any]]
Return a list of jobs, newest first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
An open database connection. |
required |
statuses
|
list[str] | None
|
If provided, only return jobs whose status is in this list.
Use |
None
|
limit
|
int
|
Maximum number of rows to return (default 50, max 500 via API). |
50
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
A list of job dicts ordered by |
Source code in src/assgen/db.py
update_job_status ¶
update_job_status(conn: Connection, job_id: str, status: str, progress: float | None = None, progress_message: str | None = None, output: dict[str, Any] | None = None, error: str | None = None, worker_id: str | None = None) -> None
Update a job's status and optional progress/output fields.
Automatically sets started_at when transitioning to RUNNING and
completed_at when transitioning to any terminal state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
An open database connection. |
required |
job_id
|
str
|
The job's full UUID. |
required |
status
|
str
|
New status — use a |
required |
progress
|
float | None
|
Completion fraction 0.0–1.0. |
None
|
progress_message
|
str | None
|
Human-readable progress description shown in the CLI bar. |
None
|
output
|
dict[str, Any] | None
|
Arbitrary result payload stored as JSON (e.g. |
None
|
error
|
str | None
|
Error message to store when the job fails. |
None
|
worker_id
|
str | None
|
Identifier of the worker thread handling this job. |
None
|
Source code in src/assgen/db.py
reset_stale_running_jobs ¶
Mark any RUNNING jobs as FAILED on server startup (crash recovery).
Returns the number of jobs reset.
Source code in src/assgen/db.py
upsert_model ¶
Insert or update a model row.
Source code in src/assgen/db.py
record_model_usage ¶
Source code in src/assgen/db.py
Configuration¶
Platform-aware config directory resolution and YAML load/save helpers.
config ¶
OS-agnostic configuration and path management for assgen.
Config directory follows the XDG Base Directory spec on Linux/macOS and %APPDATA% on Windows, via platformdirs.
Layout inside the config dir
client.yaml — client configuration (server URL, defaults) server.yaml — server configuration (host, port, workers, device) models.yaml — user model catalog overrides (merged with built-in catalog) assgen.db — SQLite database (jobs, model usage, etc.) server.pid — local server PID + URL (runtime, not committed) outputs/ — default output directory for generated assets
get_config_dir ¶
Return (and create) the OS-appropriate config directory.
get_db_path ¶
get_models_cache_dir ¶
load_server_config ¶
Source code in src/assgen/config.py
save_server_config ¶
load_client_config ¶
Server — Model Manager¶
Downloads, caches, and tracks HuggingFace models on the server side.
model_manager ¶
HuggingFace model manager.
Responsible for: - Resolving which model to use for a given job type (catalog lookup) - Downloading models from the Hub into the local cache - Tracking installed models in the SQLite database - Reporting model status (configured / downloading / installed)
ModelManager ¶
ModelManager(conn: Connection, device: str = 'auto', server_cfg: dict | None = None, db_path: str | None = None)
Manage HuggingFace model downloads, caching, and status tracking.
One ModelManager is instantiated per server process and shared across
all worker threads via the server_cfg stored in app.state.
Attributes:
| Name | Type | Description |
|---|---|---|
conn |
SQLite connection used to persist model metadata. |
|
device |
Resolved device string — |
Initialise the manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
An open SQLite connection (must have |
required |
device
|
str
|
Preferred device — |
'auto'
|
server_cfg
|
dict | None
|
The loaded server configuration dict (used for allow-list enforcement). |
None
|
db_path
|
str | None
|
Filesystem path to the SQLite database file. Required for thread-safe writes from the worker thread. |
None
|
Source code in src/assgen/server/model_manager.py
ensure_model ¶
Download model if not already cached; return the local cache path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
HuggingFace model identifier in |
required |
progress_cb
|
ProgressCallback | None
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Local |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Exception
|
Re-raised from |
Source code in src/assgen/server/model_manager.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
ensure_for_job_type ¶
ensure_for_job_type(job_type: str, progress_cb: ProgressCallback | None = None) -> tuple[str | None, Path | None]
Resolve the catalog model for job_type and ensure it is cached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_type
|
str
|
Dot-separated task identifier, e.g. |
required |
progress_cb
|
ProgressCallback | None
|
Optional progress callback forwarded to :meth: |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
A |
Path | None
|
the job type has no associated model (e.g. pure format-conversion). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If job_type is not found in the catalog. |
Source code in src/assgen/server/model_manager.py
list_status ¶
Return status of every model in the catalog.
Source code in src/assgen/server/model_manager.py
install_all ¶
Download every model referenced in the catalog.
Source code in src/assgen/server/model_manager.py
detect_device ¶
Source code in src/assgen/server/model_manager.py
Server — Validation¶
Allow-list enforcement and model↔task compatibility checks.
validation ¶
Model↔task compatibility validation and server allow-list enforcement.
When a job is submitted the server:
1. Checks the model_id is on the allow_list (if one is configured).
2. Fetches the model's pipeline_tag from the HuggingFace Hub API.
3. Verifies that tag is compatible with the catalog task for this job type.
Both checks can be bypassed by setting skip_model_validation: true in
server.yaml (server admin opt-out). The allow-list is always enforced
unless it is empty (empty = "allow everything").
HF Hub API is queried via a lightweight HTTP call so that the inference extras (torch, transformers, …) are not required just for validation.
TASK_COMPATIBLE_TAGS
module-attribute
¶
TASK_COMPATIBLE_TAGS: dict[str, frozenset[str]] = {'text-to-image': frozenset({'text-to-image'}), 'image-to-image': frozenset({'image-to-image', 'text-to-image'}), 'inpainting': frozenset({'image-to-image', 'text-to-image'}), 'image-to-3d': frozenset({'image-to-3d', 'text-to-3d'}), 'text-to-3d': frozenset({'text-to-3d', 'image-to-3d'}), 'image-to-3dgs': frozenset({'image-to-3d', 'text-to-3d', 'image-to-3dgs'}), 'mesh-retopology': frozenset({'image-to-3d', 'text-to-3d', 'mesh-retopology'}), 'uv-unwrap': frozenset({'image-to-3d', 'text-to-3d', 'uv-unwrap'}), 'texture-generation': frozenset({'text-to-image', 'image-to-image', 'texture-generation'}), 'texture-bake': frozenset({'texture-bake', 'text-to-image', 'image-to-image'}), 'auto-rig': frozenset({'auto-rig', 'image-to-3d', 'object-detection', 'image-classification'}), 'skeleton-rig': frozenset({'skeleton-rig', 'image-to-3d'}), 'motion-retarget': frozenset({'motion-retarget', 'skeleton-rig'}), 'text-to-animation': frozenset({'text-to-motion', 'text-to-video', 'text-to-animation', 'animation-generate'}), 'text-to-motion': frozenset({'text-to-motion', 'text-to-video'}), 'video-to-motion': frozenset({'video-to-motion', 'video-classification'}), 'video-to-pose': frozenset({'video-classification', 'image-classification', 'video-to-pose', 'pose-estimation'}), 'animation-generate': frozenset({'text-to-motion', 'animation-generate'}), 'text-to-audio': frozenset({'text-to-audio', 'audio-to-audio', 'text-to-speech'}), 'text-to-music': frozenset({'text-to-audio', 'audio-generation', 'music-generation'}), 'audio-generation': frozenset({'text-to-audio', 'audio-generation'}), 'music-generation': frozenset({'text-to-audio', 'audio-generation', 'music-generation'}), 'audio-to-audio': frozenset({'audio-to-audio', 'text-to-audio'}), 'automatic-speech-recognition': frozenset({'automatic-speech-recognition'}), 'text-to-speech': frozenset({'text-to-speech', 'text-to-audio'}), 'voice-clone': frozenset({'text-to-speech', 'voice-conversion', 'voice-clone', 'text-to-audio'}), 'text-to-video': frozenset({'text-to-video'}), 'image-to-video': frozenset({'image-to-video', 'text-to-video'}), 'text-to-panorama': frozenset({'text-to-image', 'text-to-panorama', 'text-to-3d', 'image-to-image'}), 'collision-mesh': frozenset({'collision-mesh', 'image-to-3d', 'text-to-3d'}), 'mesh-export': frozenset({'mesh-export'}), 'keypoint-detection': frozenset({'keypoint-detection', 'image-to-image', 'image-classification'}), 'text-generation': frozenset({'text-generation', 'text2text-generation'}), 'translation': frozenset({'translation', 'text2text-generation'}), 'question-answering': frozenset({'question-answering'}), 'feature-extraction': frozenset({'feature-extraction'}), 'depth-estimation': frozenset({'depth-estimation'}), 'object-detection': frozenset({'object-detection'}), 'image-segmentation': frozenset({'image-segmentation'})}
check_allow_list ¶
Raise ValueError if model_id is not on the configured allow list.
An empty (or absent) allow_list means all models are permitted.
Source code in src/assgen/server/validation.py
fetch_hf_pipeline_tag ¶
Return the HF pipeline_tag for model_id, or None on failure.
Uses a lightweight HTTP call to the HF Hub REST API — no heavy ML dependencies required.
Source code in src/assgen/server/validation.py
validate_model_task_compatibility ¶
validate_model_task_compatibility(model_id: str, catalog_task: str | None, server_cfg: dict[str, Any]) -> tuple[bool, str]
Check whether model_id is suitable for catalog_task.
Returns (ok, reason) where reason is a human-readable explanation
when ok is False.
Validation is skipped (returns (True, "skipped") ) when:
- server_cfg["skip_model_validation"] is truthy
- catalog_task is None (job type has no associated HF task)
- The task is not in TASK_COMPATIBLE_TAGS (unknown/custom task)
- The HF Hub API returns no pipeline_tag for the model
Source code in src/assgen/server/validation.py
validate_job_model ¶
Run all validations for a given model_id + catalog_task pair.
Raises ValueError with a descriptive message on failure.
Source code in src/assgen/server/validation.py
Version¶
version ¶
Version introspection for assgen.
Canonical approach
importlib.metadata.version("assgen")is the installed version — the single source of truth. hatch-vcs writes this from the git tag atpip install/pip install -e .time.git describe --tags --long --dirtysurfaces the current source state so you can tell whether the working tree has changed since the install.- The
--version/-Vflag on both CLIs combines these two pieces so you always know exactly what code is running.
Version string examples¶
-
Production install from a tagged release wheel::
assgen 0.1.0
-
Editable install from a clean dev checkout (16 commits after v0.0.1)::
assgen 0.0.2.dev16+gc9ee176 source v0.0.1-16-gc9ee176 (clean) python 3.12.2
-
Editable install with uncommitted changes in the working tree::
assgen 0.0.2.dev16+gc9ee176 source v0.0.1-16-gc9ee176-dirty ⚠ uncommitted changes python 3.12.2
get_version_info
cached
¶
Return a dict with version, git_describe, dirty, and python fields.
version— installed package version from :mod:importlib.metadata.git_describe— output ofgit describe --tags --long --dirty, or None when git is unavailable (e.g. running from a wheel install).dirty—Trueif the git working tree has uncommitted changes.python— Python version string.
Source code in src/assgen/version.py
format_version_string ¶
Return a human-readable version string for --version output.