an.library#
The asset library: reusable assets that outlive their videos (ADR 0005).
A library holds characters, props, environments, sounds, styles, voices and
motion clips across videos and styles; a project is one video that checks
assets out of it. Each package has its own library root (an →
~/.local/share/an, a genre such as cutan → ~/.local/share/cutan),
read together as an ordered search path.
The example publishes a character, which is the cut-out genre’s asset (pip install
"an[cutout]"), so it is not run where that package is absent:
>>> import tempfile
>>> from cutan.characters.schema import CharacterDescriptor
>>> with tempfile.TemporaryDirectory() as d:
... lib = open_library("an", root=d)
... doc = CharacterDescriptor(name="blob")
... r = publish(lib, "character.blob", doc, style="reiniger")
... [h.ref for h in find(lib, kind="character", affords="swap.view:front")]
['character.blob@v001']
What lives where:
an.library.root— the root of each package’s data (vendored XDG logic);an.library.ids— asset ids, version labels, library references;an.library.stores— the mall:records, write-onceversions, content-addressedblobs, append-onlylabels, all injectedMutableMappings;an.library.federation—Libraryand the search path;an.library.affordances— capabilities and per-kind analysers (the seed of ADR 0002’s registry);an.library.character— the character analyser;an.library.rights— the most-restrictive roll-up overAssetSource;an.library.floor— the strictest statement any library on the machinemakes about a blob;
an.library.registry— the machine’s registry of library roots the floor reads, independent of the environment;an.library.api—publish,find,vocabulary,show,promote;an.library.checkout—checkout,verify_checkout,check_pins,drift_findings(both run byan validate);an.library.lock— the project lockfile (a project store,mall["library_lock"]);an.library.kits— kits: a curated, pinned set of assets a project checks out in one call (publish_kit,checkout_kit); the kit is recorded in the lockfile’skitssection;an.library.cli—an library …, a projection of the same functions.
Functions
|
|
|
The library mall of |
|
Findings where a scene's |
|
Materialise a library version into a project, carry its rights, pin it. |
|
Check the members of a kit out into a project, pin each, and record the kit. |
|
One |
|
The rights of a version, recomputed from its sources, its lineage and its bytes. |
|
Assets matching every facet given (AND across facets, OR within one facet's values). |
|
The data root of |
|
The library of |
|
Parse a library reference. |
|
The default directory of the agent-made project |
|
Where agent-made projects go by default: |
|
Copy one version into another library — by default the core |
|
Publish |
|
Publish an asset folder as it sits in a project store ( |
|
Publish a kit — a pinned set of assets — as the next version of |
|
Rebuild |
|
Retire an asset id: recorded, hidden from |
|
Register an analyser. |
|
Register (or re-register) an asset kind. |
|
Register a capability (or a |
|
Record |
|
|
|
|
|
Roll labelled sources (and parents' rights) up to one |
|
Every asset's head version in |
|
The ordered libraries |
|
Set an asset's curation status, recording who and why; return the record. |
|
Write a contact sheet of |
|
The record, the resolved version, its recomputed rights and the list of versions. |
|
|
|
The labels recorded on a stored version since it was published, oldest first. |
|
Every facet with its values and counts, and the registered capabilities. |
Classes
|
A registered capability: its name, what it means, and how to add it. |
|
Where a checked-out version landed in the project, and its pin. |
|
Hits, near misses (with |
|
One asset that answers a query — or nearly does ( |
|
The kit document: a name, its pinned members, and a note saying what it is for. |
|
One member of a kit: a pinned reference and the project key it lands under. |
|
One library: its name (the namespace of its ids), its mall, and its root if on disk. |
|
A parsed |
|
|
|
What a publish did: the version it names, and whether it made one. |
|
The rolled-up rights of one version, as stored on it. |
Exceptions
An asset id, version label or library reference that does not parse. |
|
No library on the search path holds the asset or version asked for. |
|
A version cannot be materialised into this project as asked. |
|
Stored bytes, paths or a stored manifest do not match what was recorded. |
|
A library operation refused, with a sentence saying why and what to do. |
|
The machine's registry or statement memory cannot be read or written; nothing proceeds. |
|
A private or unknown version would leave the user's library without an override. |
|
A write-once key was written twice, or deleted. |
- exception an.library.AssetIdError[source]#
Bases:
ValueErrorAn asset id, version label or library reference that does not parse.
- exception an.library.AssetNotFoundError[source]#
Bases:
LookupErrorNo library on the search path holds the asset or version asked for.
- class an.library.Capability(name, description, remedy, subject='asset', command=None, version='1')[source]#
Bases:
objectA registered capability: its name, what it means, and how to add it.
commandis the CLI that adds it, when one exists (an character add-views);versionbumps when the meaning of the name changes (a persisted name is never redefined in place).
- exception an.library.CheckoutError[source]#
Bases:
LibraryErrorA version cannot be materialised into this project as asked.
- class an.library.CheckoutResult(ref, store, key, manifest_sha256, files, changed, rights)[source]#
Bases:
objectWhere a checked-out version landed in the project, and its pin.
- class an.library.FindResult(hits, near, counts)[source]#
Bases:
objectHits, near misses (with
near=True), and per-facet value counts over the hits.
- class an.library.Hit(library, asset_id, version, score, title=None, license_class='unknown', missing=<factory>, remedies=<factory>, federated=False)[source]#
Bases:
objectOne asset that answers a query — or nearly does (
missingnon-empty).
- exception an.library.IntegrityError[source]#
Bases:
LibraryErrorStored bytes, paths or a stored manifest do not match what was recorded.
- class an.library.Kit(**data)[source]#
Bases:
BaseModelThe kit document: a name, its pinned members, and a note saying what it is for.
- class an.library.KitMember(**data)[source]#
Bases:
BaseModelOne member of a kit: a pinned reference and the project key it lands under.
key=Nonetakes the check-out’s default (the asset id’s slug).
- class an.library.Library(name, mall, root=None)[source]#
Bases:
objectOne library: its name (the namespace of its ids), its mall, and its root if on disk.
- property blob_rights: MutableMapping#
sha256 -> {asset: statement}, derived (an.library.floor).
- property blobs: MutableMapping#
sha256 -> bytes(content-addressed).
- property labels: MutableMapping#
statements made about a version after it was published (an#307).
- Type:
<asset_id>@<vNNN>/<id> -> label(write-once)
- property records: MutableMapping#
asset_id -> record(mutable curation).
- property versions: MutableMapping#
<asset_id>@<vNNN> -> version(write-once).
- exception an.library.LibraryError[source]#
Bases:
ExceptionA library operation refused, with a sentence saying why and what to do.
- class an.library.LibraryRef(asset_id, version=None, namespace=None)[source]#
Bases:
objectA parsed
[<namespace>:]<asset_id>[@<version>].versionisNonewhen the reference gave none (read aslatestby readers; refused where a pin is required, e.g.AssetRef.library).- with_namespace(namespace)[source]#
The same asset and version, qualified by another library name.
- Return type:
- class an.library.ProjectLock(project_dir)[source]#
Bases:
MutableMapping<store>/<key> -> pinover a project’sassets.lock.json.Every write rewrites the whole (small) file, sorted, so the lockfile diffs cleanly under version control. The mapping is the
assetssection;kitsis thekitssection, and a write to either keeps the other.
- class an.library.PublishResult(ref, manifest_sha256, created, rights, affordances, advice=(), conflicts=())[source]#
Bases:
objectWhat a publish did: the version it names, and whether it made one.
- exception an.library.RegistryError[source]#
Bases:
OSErrorThe machine’s registry or statement memory cannot be read or written; nothing proceeds.
- class an.library.Rights(license_class, reasons=<factory>)[source]#
Bases:
objectThe rolled-up rights of one version, as stored on it.
- exception an.library.RightsRefusal[source]#
Bases:
PermissionErrorA private or unknown version would leave the user’s library without an override.
- exception an.library.VersionExistsError[source]#
Bases:
KeyErrorA write-once key was written twice, or deleted. Versions are immutable.
- an.library.analyse(kind, doc, art=None)[source]#
(profile, analysers)of one subject: its capabilities and the analyser versions used.A kind with no registered analyser affords nothing derived and records no analyser — an honest empty answer, not a guess.
>>> analyse("no-such-kind", {}) ({}, {})
- an.library.build_library_mall(root=None, *, package='an', **overrides)[source]#
The library mall of
package:records,versions(write-once),blobs(CAS).- Return type:
- root: the package’s data root (default: resolved by
an.library.root.library_root()—root→<PKG>_HOME→ the platform data folder); the stores live under<root>/library/
package: whose library this is (
an, or a genre such ascutan) overrides: a store per name to inject instead of the folder default — adictfor tests, an S3 or database mapping later. An injectedversionsis still made write-once and an injectedblobsstill content-addressed and undeletable, so injection cannot drop an invariant.Nothing is created until the first write: opening a library (or mistyping one on a search path) leaves the disk as it was.
- an.library.check_pins(scene, lock)[source]#
Findings where a scene’s
AssetRef.libraryand the project lockfile disagree.The lockfile is the source of truth (it is what the check-out wrote, beside the files); the scene’s
library:restates it. Two records of one pin can drift — a re-check-out updates the lockfile, not the scene — soan validateruns this on every project (an#240). Each disagreement, and eachlibrary:the lockfile does not pin, is awarning.
- an.library.checkout(libraries, project_dir, ref, *, key=None, mall=None, lock=None, overwrite=False, upgrade=False, for_kit=False)[source]#
Materialise a library version into a project, carry its rights, pin it.
- Return type:
project_dir: the project to check out into ref:
[<library>:]<asset_id>[@<version>];latest(or no version) isresolved now and pinned
key: the key in the project store (default: the asset id’s slug) mall: the project mall (default:
build_project_mall(project_dir)) lock: the lockfile mapping (default: the mall’slibrary_lockstore,<project_dir>/assets.lock.json)- overwrite: replace an existing entry that is not exactly this version — a
local fork (any edited file or descriptor) or another asset; without it that is refused
- upgrade: update in place an entry pinned to an EARLIER version of this
very asset (by lineage) and unedited since: only the files the earlier version named are replaced, and the pin moves (an#346). Without it such an entry refuses, naming this flag — never a copy beside it; an edited one refuses either way (publish it first, or
overwrite)
for_kit: the check-out of a kit member (its refusals do not name
key)An entry that already IS this version byte for byte — the folder a
publishjust sent to the library, still unedited — is recognised and linked (origin block, carried source, pin) withoutoverwrite: publishing a project’s asset and checking it back out is the natural first round trip.Every stored path, blob and the manifest are verified before anything is written, and every file is written inside the entry’s folder or not at all. Editing the checked-out copy forks it;
publishof the edited folder sends it back as a new version derived from this one.
- an.library.checkout_kit(libraries, project_dir, ref, *, overwrite=False, upgrade=False, only=None, skip=(), mall=None, lock=None)[source]#
Check the members of a kit out into a project, pin each, and record the kit.
libraries: where the kit and its members resolve project_dir: the project to check out into ref:
[<library>:]<kit asset id>[@<version>];latestis resolved now overwrite: replace project entries that are not exactly their member’s version upgrade: update in place a member’s entry pinned to an earlier version ofthat member, unedited since (
checkout())- only: check out only these members, each named by the key it lands under
(
narrator) or by its asset id (voice.narrator); default: all
skip: leave these members out, named the same way mall: the project mall (default:
build_project_mall(project_dir)) lock: the lockfile (default: the mall’slibrary_lockstore); it needs akitssection, asProjectLockhasReturns one
CheckoutResultper member checked out, in the kit’s order. Each member is checked out bycheckout()under itskeyand pinned inassets.lock.jsonas any check-out is; the kit itself is recorded under the lockfile’skitssection (its pinned reference, manifest and the members’ lockfile keys), soan libraryreaders and a human can see which kit the project came from. Checking the same kit out again is idempotent. A partial check-out (only,skip, an#400) records the members the project holds: a later check-out of more members of the same kit version adds to them.All members are resolved and checked before the first is written: a missing member, a member that is itself a kit, a corrupt stored file, or a project entry that is a fork (without
overwrite) raisesCheckoutErrorand the project is untouched.- Return type:
- an.library.drift_findings(project_dir=None, *, mall=None, lock=None, libraries=None)[source]#
One
infoFinding per checked-out entry that is no longer — or cannot be shown to be — its pinned version.An edited check-out is a fork, not a mistake — hence
info: it says the pin now records where the copy CAME FROM, not what it IS, so nothing may treat the pin as standing for the content (an#240), and publishing the folder would make a new version. A pin this machine cannot check (its library is at a custom root, or elsewhere) is its owninfo, with no advice to check anything out again — that could swap the asset for a same-named other one.project_dir: the project (not needed when both
mallandlockare given)
- an.library.effective_rights(libraries, version, *, floor=<object object>, owner=None, rule=None)[source]#
The rights of a version, recomputed from its sources, its lineage and its bytes.
owner: the library holding
version(seeversion_sources()) rule: a_PerFileRuleto share with the caller (one per operation)- Return type:
>>> lib = open_library("an", records={}, versions={}, blobs={}) >>> _ = publish(lib, "prop.vase", {"name": "vase"}, ... source={"provider": "film", "license": "all-rights-reserved"}) >>> effective_rights(lib, read_version(lib, "prop.vase", "v001"), owner=lib).license_class 'private'
- an.library.find(libraries, *, kind=None, style=None, affords=None, rights='any', family=None, origin=None, status=None, tags=None, art=None, near=False, index=<function scan_index>)[source]#
Assets matching every facet given (AND across facets, OR within one facet’s values).
- Return type:
- affords: capabilities the asset must ALL have —
limbs.legs, or swap.view:sidefor a capability with a given key. Each capability is its own boolean facet, so a list of them is AND, as across facets. An unregistered name raises, naming the close ones- rights:
any(default — study renders are legitimate),publishable (
free+attribution+noncommercial),commercial(free+attribution: what a commercial video may use, an#373), or licence classes. Rights are recomputed from each version’s sources and lineage, not read from its cache- status: curation statuses; an asset whose status is hidden
(
HIDDEN_STATUSES:retired) is offered only when its status is asked for by name- near: also return assets that pass every other facet but miss some
capabilities, or are curated for another style than asked, each with what is missing and the remedy that would add it (a style mismatch is listed as
style:<wanted>, remedied by restyling: an#271)
index: the index to read (default: a scan of the stores)
>>> lib = open_library("an", records={}, versions={}, blobs={}) >>> _ = publish(lib, "prop.lamp", {"name": "lamp"}, style=["reiniger", "gilliam"]) >>> [h.ref for h in find(lib, kind="prop", style="gilliam")] ['prop.lamp@v001'] >>> len(find(lib, kind="prop", rights="publishable")) # no source: unknown 0
- an.library.library_root(root=None, *, package='an', environ=None, platform=None)[source]#
The data root of
package— its library and its projects live under it.- Return type:
root: an explicit root; wins over everything package: the package whose root this is (
anfor the core library, agenre’s own name for its library)
environ: the environment to read (default
os.environ; injectable for tests) platform:sys.platformvalue to resolve for (default: this one)>>> library_root("~/x", package="an").name 'x'
- an.library.open_library(package='an', root=None, **overrides)[source]#
The library of
package, atroot(resolved as inan.library.root).- Return type:
- overrides: stores to inject (
records,versions,blobs), as in
>>> lib = open_library("an", records={}, versions={}, blobs={}) >>> (lib.name, lib.root) ('an', None)
- an.library.parse_ref(text, *, require_version=False, require_pin=False)[source]#
Parse a library reference.
require_version=Truerefuses a reference with no@<version>;require_pin=Truealso refuses@latest— the grammar ofAssetRef.library, where a floating reference would make a render depend on whatever the library’s head is that day.- Return type:
>>> parse_ref("character.alice") LibraryRef(asset_id='character.alice', version=None, namespace=None) >>> parse_ref("character.alice@sha256:0a1b2c3d").version 'sha256:0a1b2c3d' >>> parse_ref("character.alice", require_version=True) Traceback (most recent call last): AssetIdError: ...
- an.library.project_dir(project_id, root=None, *, package='an', environ=None)[source]#
The default directory of the agent-made project
project_id(design §7.5).an init <dir>with an explicit directory keeps working anywhere; this is the default for projects an agent makes (an init --id <id>), so they never land in a session’s working folder or a repository.packageis the library package of the genre the video is made in (an.genres.genre_library(); the core’s,an, by default — the core names no genre).- Return type:
>>> project_dir("alice-and-bob", "/lib").as_posix() '/lib/projects/alice-and-bob' >>> project_dir("../escape", "/lib") Traceback (most recent call last): ValueError: ...
- an.library.projects_root(root=None, *, package='an', environ=None)[source]#
Where agent-made projects go by default:
<root>/projects/.- Return type:
>>> projects_root("/lib", package="cutan").as_posix() '/lib/projects'
- an.library.promote(libraries, ref, *, to=None, as_id=None, allow_restricted=False, strict_assets=False)[source]#
Copy one version into another library — by default the core
anlibrary.An asset made in a genre’s library and reused across genres is promoted to the core (plan §1 decision 7). The copy is a new version in the target, derived from the source version, with the record’s curation carried over.
A
privateorunknownversion is refused unlessallow_restricted=True: private-study material never leaves its library by default (ADR 0005 decision 10). The rights checked are recomputed from the version’s sources and lineage, and the stricter of those and the stored ones wins.If the target already has an asset with this id that does not derive from the one promoted (another character that happens to share the id), it is refused: promoting would make it a new version of an unrelated asset.
as_idpromotes under another id.strict_assets: refuse a copy that would record a rights conflict (publish()’s, an#357), instead of recording it.
- Return type:
- an.library.publish(library, asset_id, doc, files=None, *, source=None, relicense=None, relabel=None, derived_from=(), title=None, family=None, style=None, origin=None, status=None, tags=None, replace_curation=False, note=None, expect_head=<object object>, search=None, carry_source=True, license_parts=None, file_sources=None, strict_assets=False)[source]#
Publish
docand itsfilesas the next version ofasset_idinlibrary.library: the owning library (writes never go to a search path) asset_id:
<kind>.<slug>; the kind must be registered doc: the descriptor — the existing documentanalready versions(
CharacterDescriptor, …), as a model or its JSON dict, stored verbatim- files: the asset’s files, by the relative paths the descriptor uses
(
parts/head.svg) — stored once each in the content-addressed blobs- source: provenance declared for the asset as a whole. It contributes BESIDE
the descriptor’s own
source(the most restrictive wins), never instead of it. With nosource, and a descriptor declaring nothing or exactly what the head’s declared, the source of the previous version carries forward (carry_source) — for the bytes it was declared on only: a file changed or added since is recorded asunlabelledon the version and isunknown. Later versions inherit that gap throughpreviouseven when they passsource=;relabel(or a relicence) answers it. With no source at all the version isunknown— recorded and visible, not refused- relicense:
{"by": who, "reason": why}— the ONLY way to relax rights. Rights attach to the bytes and the lineage: a new version inherits the version it follows (
previous), every version it derives from, and every version holding the same file bytes, and may only be more restrictive than they are — a cc0 in the descriptor or insource=never relabels private art. A relicence makessource(required) the whole statement, records who and why on the version (and in its manifest and reasons), and covers these bytes for later versions- relabel:
{"by": who, "reason": why}beside an explicitsource= (required) — a first statement about bytes NOBODY labelled (an#263): the gaps of this asset’s own version chain (files an earlier version recorded
unlabelled, files no person’s source spoke for, an earlier version with no source at all) are answered withsource, and so is another asset’s silence about a file the chain held once and this version no longer holds (an#307). It relaxes no statement anyone made: a private (or any) licence, a per-part source, a version this one derives from, and every other asset’s statement about bytes this version holds still bind. On content that changed, recorded on the new version, in its manifest and in its reasons; on UNCHANGED content, recorded on the head in the append-onlylabelsstore (version_labels()) and no version is minted (an#307)- derived_from: library references this version derives from (an earlier version,
the original of a recolour); each must resolve, and its rights are inherited. A descriptor checked out of a library derives from its origin by default
- title, family, style, origin, status, tags: curation, stored on the record;
given again with unchanged content they update the record and make no version.
styleandtagsadd to what is there, or replace it withreplace_curation=True
note: what changed, stored on the version expect_head: guard against publishing into an asset you did not mean:
None— the id must be new;"vNNN"— the head must be that version- search: further libraries where
derived_fromreferences resolve (the owning library is always searched first)
- license_parts:
{glob: source}— a per-file statement for every stored path a glob matches (
match_license_parts():*stays in one folder,**crosses folders, case-exact; a glob matching nothing, two globs disagreeing on a path, or a near miss refuse), each pinned to the file’s digest (an#345). Needs an asset-levelsource(given or carried): the files no glob names are stated with the version’s label computed WITHOUT these statements. A per-file statement never relaxes what the bytes already carry — the per-part source of the same file, the same bytes at another path, and every earlier statement of this asset’s chain or of a version it derives from about them: a looser one is kept and recorded as a rights conflict, the stricter binding (an#357), unlessrelicenserecords who and why (the relicence then lists the digests it covers, and a per-file statement stricter than it keeps binding). At a later publish a statement is carried for its file while the bytes are unchanged; a file changed since is recordedunlabelled- file_sources:
{path: source}— the same, by exact stored path (what a stored version holds;
promote()passes it)- strict_assets: refuse a publish that would record a rights conflict
(
RightsConflict: a per-part or per-file statement freer than what binds its bytes) instead of recording it with aRightsConflictWarning(an#357: inform, don’t block, by default)
>>> lib = open_library("an", records={}, versions={}, blobs={}) >>> doc = {"name": "lamp", "source": {"provider": "me", "license": "cc0-1.0"}} >>> r = publish(lib, "prop.lamp", doc, {"parts/lamp.svg": b"<svg/>"}, style="reiniger") >>> str(r.ref), r.created, r.rights.license_class ('an:prop.lamp@v001', True, 'free') >>> publish(lib, "prop.lamp", doc, {"parts/lamp.svg": b"<svg/>"}).created False
- Return type:
- an.library.publish_dir(library, folder, asset_id, **kwargs)[source]#
Publish an asset folder as it sits in a project store (
assets/characters/alice/).The descriptor is the kind’s descriptor file (
character.json); every other file under the folder is published as one of the asset’s files, so a check-out reproduces the folder — except operating-system clutter (.DS_Store, hidden files,Thumbs.db:an.stores._common.is_os_junk()) that the descriptor does not name — a part it names is published whatever its file is called (review-288 S2). Keyword arguments go topublish().- Return type:
- an.library.publish_kit(library, asset_id, members, *, search=None, name=None, note=None, **curation)[source]#
Publish a kit — a pinned set of assets — as the next version of
asset_idinlibrary.library: the owning library (writes never go to a search path) asset_id:
kit.<slug>members: each a library reference ([<library>:]<asset_id>[@<version>]), a(reference, key)pair, or a mapping{"ref": …, "key": …};keyis the name the member takes in the project’s store (default: the asset’s slug)- search: further libraries where member references resolve (the owning library
is always searched first, as in
publish())
name: the kit’s name in its document (default: the asset id’s slug) note: what the kit is for, stored in the document and on the version curation: everything else
publish()takes —source=(the kit document is its author’s own authoring: its rights come from this, never from its members),
title,style,tags, …Every member must resolve;
latestand unversioned references are pinned to the concrete version now, so the kit version is reproducible. A member that is itself a kit, one with no project store, or two members landing in one(store, key)are refused.>>> lib = open_library("an", records={}, versions={}, blobs={}) >>> _ = publish(lib, "style.noir", {"name": "noir"}, source={"provider": "me", "license": "cc0-1.0"}) >>> r = publish_kit(lib, "kit.noir-base", ["style.noir"], source={"provider": "me", "license": "cc0-1.0"}) >>> lib.versions["kit.noir-base@v001"]["doc"]["members"] [{'ref': 'style.noir@v001', 'key': None}]
- Return type:
- an.library.register_analyser(kind, *, version='', subject='asset', owner='an')[source]#
Register an analyser. Two forms.
register_analyser(Analyser(...), owner=...)registers the object and returns it (a genre’sanalysersfield goes this way). With akindstring it is a decorator:@register_analyser("character", version="0.1.0")registers the decorated derivation.- Return type:
- an.library.register_asset_kind(name, *, store=None, descriptor=None, credits_store=None)[source]#
Register (or re-register) an asset kind. Returns it.
- Return type:
- an.library.register_capability(name, *, description='', remedy='', subject='asset', command=None, version='1', owner='an')[source]#
Register a capability (or a
Capability). Returns it.Re-registering the same definition is a no-op; a different definition under a name another owner holds raises, because capability names are persisted and two meanings for one name would make a stored facet lie.
- Return type:
>>> cap = register_capability("demo.thing", description="a thing", remedy="add one", owner="demo") >>> CAPABILITIES["demo.thing"] is cap True >>> _ = drop_owner("demo")
- an.library.register_root(package, root, *, registry=None)[source]#
Record
root(package’s library root) in the registry;Trueif it was new.Idempotent. Raises
RegistryErrorwhen the registry cannot be read or written: a library the floor cannot find later must not be written to.- Return type:
- an.library.registered_roots(*, registry=None)[source]#
(package, root)for every root ever registered, oldest first, each once.A line that does not parse (a torn append) is skipped; existence is the caller’s to check. A registry that exists but cannot be read raises
RegistryError.
- an.library.reindex(library, *, search=None)[source]#
Rebuild
library’s floor index from its versions. Returns the number of blobs indexed.Lineage resolves through
searchand then every library on this machine (an.library.floor.machine_libraries()), so a promoted copy’s parent in a genre’s library is read without being named (an#361).The index is derived data: rebuilding it is always safe, and the way to repair a library whose index was lost or written by an older
an. It also (re-)registers the library’s root in the machine registry (an.library.registry), so a library made at a custom root before the registry existed becomes visible to every other library’s rights floor.reindex_changes()says first what a rebuild would change.The new index is computed in full first, then written over the old one entry by entry, and only then are stale entries removed: a crash midway leaves old and new statements side by side, never an empty floor (an#249 R4-N4).
- Return type:
- an.library.resolve(libraries, ref)[source]#
(library, pinned_ref, version_doc)for a reference, along the search path.A namespaced reference reads only its library; a bare one reads the first library holding the asset.
latestresolves to that library’s head andsha256:<prefix>to the one version whose manifest hash starts with it. The returned reference is pinned (vNNN) and namespaced with the library it resolved in.
- an.library.retire(library, asset_id, *, by, reason)[source]#
Retire an asset id: recorded, hidden from
findby default, never deleted.Its versions stay readable — a project pinned to one still checks it out and validates — and its rights statements still bind the floor (retiring is curation, not a relabel).
find(status="retired")lists it; a publish into it is refused unless it passesstatus=to revive it.>>> lib = open_library("an", records={}, versions={}, blobs={}) >>> _ = publish(lib, "prop.dead", {"name": "dead"}) >>> _ = retire(lib, "prop.dead", by="me", reason="superseded") >>> len(find(lib)), [h.asset_id for h in find(lib, status="retired")] (0, ['prop.dead'])
- an.library.roll_up(sources, *, inherited=())[source]#
Roll labelled sources (and parents’ rights) up to one
Rights.A
Nonesource isunknown. The reasons name every contributor of the winning class, so a reader sees why a version is restricted.- Return type:
>>> roll_up([("asset", None)]).to_dict() {'license_class': 'unknown', 'publishable': False, 'reasons': ['asset: no source recorded (unknown)']}
- an.library.scan_index(library)[source]#
Every asset’s head version in
library, read from the stores.Affordances snapshotted by an older analyser are recomputed, not trusted. A record or version that cannot be read (a damaged file) is skipped with a
LibraryIndexWarningnaming it, so one bad entry never blinds every search.- Return type:
- an.library.search_path(package='an', *, extra=(), roots=None)[source]#
The ordered libraries
packagereads: its own, then the corean, thenextra.- extra: further libraries, by package name (resolved like any root) or as
Libraryobjects (a team share, a seed library)- roots: an explicit root per package name (tests, a non-default layout);
unnamed packages resolve as usual (
<PKG>_HOME, then the data folder)
A name appears once, at its first position.
- an.library.set_status(library, asset_id, status, *, by, reason)[source]#
Set an asset’s curation status, recording who and why; return the record.
The record’s
status_historyis appended to, never rewritten, and no version is touched: a project pinned to one keeps reading it.>>> lib = open_library("an", records={}, versions={}, blobs={}) >>> _ = publish(lib, "prop.lamp", {"name": "lamp"}) >>> set_status(lib, "prop.lamp", "approved", by="me", reason="looks right")["status"] 'approved'
- an.library.sheet(refs, *, libraries=None, package=None, out=None, cell=256, columns=None, parts=False, allow_private_here=False)[source]#
Write a contact sheet of
refs([<library>:]<id>[@<version>]) to one PNG.libraries: where the references resolve (default:
package’s search path) out: the PNG (defaultDFLT_SHEET) parts: tile each version’s art files instead of one specimen frame allow_private_here: write a not-publishable sheet inside a git work treethat does not ignore the path
- Return type:
- an.library.show(libraries, ref)[source]#
The record, the resolved version, its recomputed rights and the list of versions.
>>> lib = open_library("an", records={}, versions={}, blobs={}) >>> _ = publish(lib, "prop.lamp", {"name": "lamp"}, title="A lamp") >>> s = show(lib, "prop.lamp") >>> s["ref"], s["record"]["title"], s["versions"] ('an:prop.lamp@v001', 'A lamp', ['v001'])
- an.library.verify_checkout(libraries, project_dir, *, mall=None, lock=None)[source]#
{<store>/<key>: differences}for every pinned entry; empty lists are intact copies.- libraries: where the pinned versions resolve (
None: the library each pin names, at its default root —
pinned_libraries())
What makes a pin usable as more than provenance: an entry with no differences is byte-for-byte the version its pin names. An entry whose pinned version cannot be found, or is found with another manifest (a same-named asset in another library), reads
["cannot verify: …"]— never as an edit.- libraries: where the pinned versions resolve (
- an.library.version_labels(library, version)[source]#
The labels recorded on a stored version since it was published, oldest first.
A relabel of a version’s UNCHANGED content is recorded on that version, in the library’s append-only
labelsstore, instead of minting a new version (an#307). A label counts only for the very version it was made on: itsmanifestmust be this version’s (a same-named library’s otherx@v001never inherits it). An unreadable label is skipped with aLibraryIndexWarning; skipping one can only leave the version stricter.
- an.library.vocabulary(libraries, *, index=<function scan_index>)[source]#
Every facet with its values and counts, and the registered capabilities.
What an agent reads to turn words into a typed query (spectrum (b)): “a Reiniger character who can walk in profile” →
style=reiniger,affords=["limbs.legs", "swap.view:side"]. The counts are over whatfindoffers by default — the same recomputed rights, and no asset of a hidden status (retired), whose numbers are underhidden.>>> lib = open_library("an", records={}, versions={}, blobs={}) >>> v = vocabulary(lib) >>> sorted(v) ['capabilities', 'facets', 'hidden', 'kinds', 'rights', 'statuses'] >>> isinstance(v["capabilities"], (dict, list, tuple)) True
Modules
Affordances for the library: the capability registry, re-exported from |
|
The library's verbs: |
|
|
|
Libraries federated by a search path: one read view, writes to the owner (plan §1 decision 7). |
|
The rights floor of a blob: the strictest statement any library on this machine makes about its bytes. |
|
Asset ids, version labels and library references — the library's persisted names. |
|
Asset kinds: the |
|
Kits: a curated, versioned set of library assets that a project checks out in one call. |
|
The project lockfile, as the asset library sees it (re-exported from |
|
The machine's memory of its libraries: every root ever written, and every statement ever made (an#249). |
|
Rights on every version: the most restrictive licence class wins (ADR 0005 decision 10, design §9). |
|
Where a package's library lives on disk: one root per package (ADR 0005 §2, plan §1 decisions 7–8). |
|
|
|
The library mall: |