an.stores#

Project mall: a dict of dol-backed MutableMapping stores.

The mall is the unit of persistence in an. Every long-lived state — assets (characters, props, environments, voices, styles, sounds, recordings), the scene file pair, intermediate artifacts (audio, viseme tracks, best-of-N take records, per-shot mp4s, the content-keyed shot cache, linked transcripts), final output and its caption sidecar, the agent’s decision log, and the asset library’s lockfile of pinned check-outs — is keyed inside a store. Stores are dol-backed so the same call sites work against filesystem, SQLite, S3, etc.

>>> import tempfile
>>> from pathlib import Path
>>> with tempfile.TemporaryDirectory() as d:
...     mall = build_project_mall(d, ensure=True)
...     sorted(mall.keys()) == [
...         'audio', 'captions', 'characters', 'contact_sheets', 'decisions',
...         'environments', 'library_lock', 'measurements', 'output',
...         'pictures', 'previews', 'props', 'recordings', 'render_reports', 'scenes',
...         'shot_cache', 'shots', 'sounds', 'sources', 'styles', 'takes',
...         'transcripts', 'visemes', 'voices',
...     ]
True

Module Attributes

UNSTORED_FOLDERS

The folders of a project's tree that no store owns, which ensure=True lays out beside the stores' own: ir/, where the scene store writes the default scene's IR (the store's root is the project folder itself).

Functions

asset_ref_problem(rel)

Why rel, a path an asset document names, is NOT a clean relative path inside the asset's folder, or None when it is one (an#483).

asset_ref_problems(doc[, folder, file_problems])

(label, message) for every reference in doc (asset_references()) that breaks the asset-reference rule (an#483, an#552); [] when none does.

asset_references(doc)

(label, path) for every file path an asset document names (an#552): an environment's image planes (planes/<name>/art/src), a rig's attachments (skins/<skin>/slots/<slot>/<attachment>/path; labelled part <skin>:<slot>/<attachment> outside the default skin), a character's source_svg and the files its colour_roles keys name.

inside_folder(folder, rel)

folder / rel when rel is a relative path that stays inside folder once symlinks are resolved, else None (an#483).

build_project_mall(project_dir, *[, ensure, ...])

Build the standard project mall over project_dir.

Classes

JsonDirStore(root_dir, *[, ensure])

MutableMapping of name -> JSON document, stored as <name>.json files.

CharactersStore(root_dir, *[, ensure])

Per-character directory store.

EnvironmentsStore(root_dir, *[, ensure])

Per-environment directory store (meta + sidecar art).

VoicesStore(root_dir, *[, ensure])

JSON-only voice descriptors.

StylesStore(root_dir, *[, ensure])

Pure-JSON style descriptors.

PropsStore(root_dir, *[, ensure])

Per-prop directory store.

ScenesStore(project_dir[, scene_file])

MutableMapping exposing the scene file pair under a project root.

SoundsStore(root_dir, *[, ensure])

Per-sound directory store.

RecordingsStore(root_dir, *[, ensure])

Per-take directory store: <key>/recording.json + <key>/audio.wav.

AudioArtifactStore(root_dir, *[, ensure])

TTS-rendered audio clips (.wav).

VisemeArtifactStore(root_dir, *[, ensure])

Lip-sync viseme tracks (.json) — stored as bytes for cache uniformity.

TakesArtifactStore(root_dir, *[, ensure])

Best-of-N take records (.json bytes), keyed by the line's audio key: which take was kept, its sha256, every take's score and the scorer (an#265).

ShotArtifactStore(root_dir, *[, ensure])

Per-shot rendered mp4s.

PreviewArtifactStore(root_dir, *[, ensure])

Low-res preview renders (mp4 or png sequence wrapper).

ContactSheetStore(root_dir, *[, ensure])

Contact sheets (.png): frames of a render at its settled beats, labelled with their time, for a person or an agent to LOOK at (core study §2.10).

MeasurementStore(root_dir, *[, ensure])

Measurements a clock-owning renderer made of its content (.json bytes), keyed by that content's key — DERIVED data, never the author's (an#279): a Manim shot's length, its timeline of beats, its findings.

PictureStore(root_dir, *[, ensure])

An opaque renderer's raw picture (.mp4) — a Manim scene's own render, before it is conformed to a film's fps and size, so a change that is not to the picture (narration, fps) does not run Manim again (an#279).

RenderReportStore(root_dir, *[, ensure])

What a render found (.json), keyed like the output it describes — render_reports["main"] — so orchestrate and MCP read the findings that an render warned (an#279).

SourcesStore(root_dir, *[, ensure])

Python scene sources (.py bytes) — a Manim scene file per key.

OutputStore(root_dir, *[, ensure])

Final composited renders.

DecisionLogStore(log_path, *[, ensure])

Append-only JSONL log keyed by ordinal index (as string).

ProjectLock(project_dir)

<store>/<key> -> pin over a project's assets.lock.json.

class an.stores.AudioArtifactStore(root_dir, *, ensure=False)[source]#

Bases: _BlobStore

TTS-rendered audio clips (.wav).

class an.stores.CharactersStore(root_dir, *, ensure=False)[source]#

Bases: JsonSidecarStore

Per-character directory store.

>>> import tempfile
>>> with tempfile.TemporaryDirectory() as d:
...     store = CharactersStore(d)
...     store['maya'] = {'name': 'Maya', 'voice_ref': 'maya-warm'}
...     store['maya']['name']
'Maya'
class an.stores.ContactSheetStore(root_dir, *, ensure=False)[source]#

Bases: _BlobStore

Contact sheets (.png): frames of a render at its settled beats, labelled with their time, for a person or an agent to LOOK at (core study §2.10).

Content-addressed — the key is the sha256 of the PNG bytes — so a shot whose render is reused from the shot cache still points at its sheet through the cached provenance, and two shots with one picture share one file.

class an.stores.DecisionLogStore(log_path, *, ensure=False)[source]#

Bases: MutableMapping

Append-only JSONL log keyed by ordinal index (as string).

Mutating in-place (__setitem__, __delitem__) is intentionally forbidden; the log is append-only by design.

>>> import tempfile, os
>>> with tempfile.TemporaryDirectory() as d:
...     log = DecisionLogStore(os.path.join(d, 'decisions.jsonl'))
...     _ = log.append(kind='test', body={'x': 1})
...     _ = log.append(kind='test', body={'x': 2})
...     entries = list(log.values())
...     entries[0]['body']['x'], entries[1]['body']['x']
(1, 2)
append(*, kind, body, **extra)[source]#

Append one decision; returns its ordinal index.

Return type:

int

class an.stores.EnvironmentsStore(root_dir, *, ensure=False)[source]#

Bases: JsonSidecarStore

Per-environment directory store (meta + sidecar art).

class an.stores.JsonDirStore(root_dir, *, ensure=False)[source]#

Bases: LazyFolder, MutableMapping

MutableMapping of name -> JSON document, stored as <name>.json files.

Backed by the filesystem under root_dir. Keys are the file stems; values are arbitrary JSON-serializable Python objects. __contains__, __iter__, and __len__ are derived from directory listing. Exported from an.stores for hosts (an#664): a write is atomic and locked() is the contract for a read, change and write shared with other processes.

Its folder follows LazyFolder’s rule (an#696): made by the first write or lock, so a host can scan many folders through the store without leaving an empty one in each.

>>> import tempfile
>>> d = Path(tempfile.mkdtemp()) / "voice_options"
>>> store = JsonDirStore(d)
>>> list(store), "jerry" in store, d.exists()
([], False, False)
>>> store["jerry"] = {"options": []}
>>> list(store), d.exists()
(['jerry'], True)
interrupted_writes()[source]#

The temp files killed writes left in this store’s folder (an#674).

Return type:

list[Path]

locked(key)[source]#

Hold key’s file lock (<key>.json.lock): a read, change and write of key inside it is one step for every process that takes it too (an#587). The lock file and the atomic write’s temp file are never keys.

>>> import tempfile
>>> store = JsonDirStore(tempfile.mkdtemp())
>>> with store.locked("jerry"):
...     store["jerry"] = {"options": []}
>>> list(store), store["jerry"]
(['jerry'], {'options': []})
Return type:

Iterator[None]

class an.stores.MeasurementStore(root_dir, *, ensure=False)[source]#

Bases: _BlobStore

Measurements a clock-owning renderer made of its content (.json bytes), keyed by that content’s key — DERIVED data, never the author’s (an#279): a Manim shot’s length, its timeline of beats, its findings.

class an.stores.OutputStore(root_dir, *, ensure=False)[source]#

Bases: _BlobStore

Final composited renders.

class an.stores.PictureStore(root_dir, *, ensure=False)[source]#

Bases: _BlobStore

An opaque renderer’s raw picture (.mp4) — a Manim scene’s own render, before it is conformed to a film’s fps and size, so a change that is not to the picture (narration, fps) does not run Manim again (an#279). Content-addressed (the key is the sha256 of the mp4): the measurement record under the picture key names it, so a record and its picture are written as one (an#291).

class an.stores.PreviewArtifactStore(root_dir, *, ensure=False)[source]#

Bases: _BlobStore

Low-res preview renders (mp4 or png sequence wrapper).

class an.stores.ProjectLock(project_dir)[source]#

Bases: MutableMapping

<store>/<key> -> pin over a project’s assets.lock.json.

Every write rewrites the whole (small) file, sorted, so the lockfile diffs cleanly under version control. The mapping is the assets section; kits is the kits section, and a write to either keeps the other.

property kits: MutableMapping[str, dict[str, Any]]#

kit asset id -> record of the kits checked out into the project.

class an.stores.PropsStore(root_dir, *, ensure=False)[source]#

Bases: JsonSidecarStore

Per-prop directory store.

>>> import tempfile
>>> with tempfile.TemporaryDirectory() as d:
...     store = PropsStore(d)
...     store['lamp'] = {'name': 'Desk lamp'}
...     store['lamp']['name']
'Desk lamp'
class an.stores.RecordingsStore(root_dir, *, ensure=False)[source]#

Bases: AudioSidecarStore

Per-take directory store: <key>/recording.json + <key>/audio.wav.

ENTRY_NOUN = 'recording'#

What an entry is called in error messages.

class an.stores.RenderReportStore(root_dir, *, ensure=False)[source]#

Bases: _BlobStore

What a render found (.json), keyed like the output it describes — render_reports["main"] — so orchestrate and MCP read the findings that an render warned (an#279).

class an.stores.ScenesStore(project_dir, scene_file='scene.md')[source]#

Bases: MutableMapping

MutableMapping exposing the scene file pair under a project root.

Keys: currently always "main". The store enforces this by raising KeyError for other keys.

patch_shot_durations(durations)[source]#

Set duration on the named shots WITHOUT regenerating scene.md.

__setitem__ rewrites the markdown from the IR, which drops every word of prose and every comment the IR does not hold. This writes the JSON through the read boundary as usual, and patches only each shot’s duration: line in the markdown (inserting one into its ```` `yaml shot `` block, or the block itself, when there is none) — what an sync --accept-measured uses to take a measured duration into the authored scene (an#279).

Return type:

None

property project_dir: Path#

The project folder this store’s scene file is in (its sibling scene files are there too: a continue: reads them, an#542).

class an.stores.ShotArtifactStore(root_dir, *, ensure=False)[source]#

Bases: _BlobStore

Per-shot rendered mp4s.

class an.stores.SoundsStore(root_dir, *, ensure=False)[source]#

Bases: AudioSidecarStore

Per-sound directory store.

>>> import tempfile
>>> with tempfile.TemporaryDirectory() as d:
...     store = SoundsStore(d)
...     store['hit'] = {'description': 'a stick on a table'}
...     store.write_audio('hit', b'RIFF....')
...     store['hit']['description'], store.read_audio('hit')
('a stick on a table', b'RIFF....')
AUDIO_NAME = 'audio.wav'#

an.sounds reads its header for the duration a fade-out needs, deterministically.

Type:

The sidecar holding the audio bytes. WAV only in v1

ENTRY_NOUN = 'sound'#

What an entry is called in error messages.

class an.stores.SourcesStore(root_dir, *, ensure=False)[source]#

Bases: _BlobStore

Python scene sources (.py bytes) — a Manim scene file per key.

class an.stores.StylesStore(root_dir, *, ensure=False)[source]#

Bases: JsonDirStore

Pure-JSON style descriptors.

class an.stores.TakesArtifactStore(root_dir, *, ensure=False)[source]#

Bases: _BlobStore

Best-of-N take records (.json bytes), keyed by the line’s audio key: which take was kept, its sha256, every take’s score and the scorer (an#265).

an.stores.UNSTORED_FOLDERS = ('ir',)#

The folders of a project’s tree that no store owns, which ensure=True lays out beside the stores’ own: ir/, where the scene store writes the default scene’s IR (the store’s root is the project folder itself).

class an.stores.VisemeArtifactStore(root_dir, *, ensure=False)[source]#

Bases: _BlobStore

Lip-sync viseme tracks (.json) — stored as bytes for cache uniformity.

class an.stores.VoicesStore(root_dir, *, ensure=False)[source]#

Bases: JsonDirStore

JSON-only voice descriptors.

>>> import tempfile
>>> with tempfile.TemporaryDirectory() as d:
...     store = VoicesStore(d)
...     store['maya-warm'] = {'provider': 'elevenlabs', 'voice_id': 'xyz'}
...     'maya-warm' in store
True
an.stores.asset_ref_problem(rel)[source]#

Why rel, a path an asset document names, is NOT a clean relative path inside the asset’s folder, or None when it is one (an#483).

An asset reference resolves inside its own folder, never anywhere else: an absolute path, a .. that leaves the folder or a URL is refused by name, before any read — a project may be someone else’s input (a production pack checked on a server), and a reference that reaches outside it is a file-existence and XML-parse oracle on the host. The spelling is held to the library’s rule too (no . or empty segment, no backslash), so a reference that validates here publishes there unchanged.

>>> asset_ref_problem("parts/head.svg") is None
True
>>> asset_ref_problem("/etc/hostname")
'is an absolute path'
>>> asset_ref_problem("../../other/plate.png")
'leaves the asset folder (`..`)'
>>> asset_ref_problem("file:///etc/hostname"), asset_ref_problem("C:/art/x.svg")
('is a URL or a drive path (`:`)', 'is a URL or a drive path (`:`)')
>>> asset_ref_problem("./parts/head.svg"), asset_ref_problem("parts\\head.svg"), asset_ref_problem("")
('has an empty or `.` segment', 'uses a backslash (write the path with `/`)', 'is empty')
Return type:

str | None

an.stores.asset_ref_problems(doc, folder=None, *, file_problems=None)[source]#

(label, message) for every reference in doc (asset_references()) that breaks the asset-reference rule (an#483, an#552); [] when none does. The one rule the core and a genre share.

A reference is judged by NAME first (asset_ref_problem()), and is never read when its name is bad; with a folder, also by where it resolves (inside_folder(): a link out of the folder is the same error). file_problems, when given, is asked about each file that passed (the core passes its SVG self-containment check): it is called for every path that passed the name (and folder) check, whether or not the file exists, so it must tolerate an absent file. Each message it returns is appended to "<label> names <path>, which", so it must begin with a verb ("is SVG that ...", "is not in the folder"). message is a whole sentence, label included, so a caller can report it as is.

>>> asset_ref_problems({"source_svg": "../x.svg", "planes": [
...     {"name": "sky", "art": {"kind": "image", "src": "sky.png"}}]})
[('source_svg', "source_svg names '../x.svg', which leaves the asset folder (`..`):
  an asset reference must be a relative path inside the asset's own folder
  (nothing outside it is read)")]
>>> asset_ref_problems({"source_svg": "source.svg"}, ".")
[]
>>> asset_ref_problems({"source_svg": "ok.svg"}, ".",
...                    file_problems=lambda f: [f"is SVG that holds a <script>"])
[('source_svg', "source_svg names 'ok.svg', which is SVG that holds a <script>")]
Return type:

list[tuple[str, str]]

an.stores.asset_references(doc)[source]#

(label, path) for every file path an asset document names (an#552): an environment’s image planes (planes/<name>/art/src), a rig’s attachments (skins/<skin>/slots/<slot>/<attachment>/path; labelled part <skin>:<slot>/<attachment> outside the default skin), a character’s source_svg and the files its colour_roles keys name.

The one list of what an asset document references; the core’s an validate and a genre’s own validator both walk it, so they cannot disagree about which fields hold a path.

>>> asset_references({"planes": [{"name": "sky", "art": {"kind": "image", "src": "sky.png"}},
...                              {"name": "fill", "art": {"kind": "fill"}}]})
[('plane sky', 'sky.png')]
>>> asset_references({"skins": {"default": {"slots": {"body": {"body": {"path": "parts/body.svg"}}}}},
...                   "source_svg": "source.svg", "colour_roles": {"parts/body.svg": {"#fff": "skin"}}})
[('part body/body', 'parts/body.svg'), ('source_svg', 'source.svg'), ('colour_roles parts/body.svg', 'parts/body.svg')]

A malformed document names nothing where it is malformed (its schema check reports it), rather than raising:

>>> asset_references({"planes": [{"art": "sky.png"}], "skins": {"default": {"slots": ["body"]}},
...                   "source_svg": 3})
[]
>>> asset_references({"planes": "sky.png", "skins": ["default"]})
[]
Return type:

list[tuple[str, str]]

an.stores.build_project_mall(project_dir, *, ensure=False, scene_file='scene.md', **overrides)[source]#

Build the standard project mall over project_dir.

Building it lays out nothing (an#696): every file store makes its folder on its first write, a missing one reading as empty. ensure=True (an init) lays out the tree at once: each store’s folder, through the store, and the UNSTORED_FOLDERS. scene_file picks the scene the scenes store holds (an#539; scene.md by default). Pass keyword overrides to swap in alternate stores (e.g. an in-memory dict for tests).

Return type:

dict[str, MutableMapping]

an.stores.inside_folder(folder, rel)[source]#

folder / rel when rel is a relative path that stays inside folder once symlinks are resolved, else None (an#483). The path is returned as joined, not resolved, so a caller’s own stat and digest see the same spelling they always did.

>>> import tempfile, os
>>> with tempfile.TemporaryDirectory() as d:
...     inside_folder(d, "parts/head.svg") == Path(d) / "parts/head.svg"
...     inside_folder(d, "../head.svg") is None, inside_folder(d, "/etc/hostname") is None
True
(True, True)
Return type:

Path | None

Modules

artifacts

Artifact stores — derived, regeneratable products of the pipeline.

characters

Characters store — descriptor + sidecar folder per character.

decisions

Decision log — append-only JSONL of agent decisions and user approvals.

environments

Environments store — backgrounds, set pieces, and prop bundles.

library_lock

The project lockfile: which library version each checked-out asset came from.

props

Props store — descriptor + sidecar folder per prop.

recordings

Recordings store — one directory per recorded take: recording.json beside audio.wav.

scenes

Scenes store — wraps the project's scene.md + ir/scene.json pair.

sounds

Sounds store — one directory per sound: sound.json beside audio.wav.

sources

The project's opaque scene sources: files a whole-shot renderer runs as they are.

styles

Styles store — visual style presets (color palette, line weight, fonts).

transcripts

Transcripts as linked artifacts in the project store (an#493).

voices

Voices store — pure JSON; one entry per voice.