makeprov.refs

Functions

dataclass([cls, init, repr, eq, order, ...])

Add dunder methods based on the fields defined in the class.

field(*[, default, default_factory, init, ...])

Return an object to identify dataclass fields.

replace(obj, /, **changes)

Return a new object replacing specified fields with new values.

Classes

Any(*args, **kwargs)

Special type indicating an unconstrained type.

ArtifactRef([id, path, types, digest, ...])

A reference to an entity a run consumed or produced.

Path(*args, **kwargs)

PurePath subclass that can make system calls.

datetime(year, month, day[, hour[, minute[, ...)

The year, month and day arguments are required.

timezone

Fixed offset from UTC implementation of tzinfo.

class makeprov.refs.ArtifactRef(id=None, path=None, types=('prov:Entity', ), digest=None, media_type=None, extent=None, modified=None, label=None, extra=<factory>)

Bases: object

A reference to an entity a run consumed or produced.

A ref is either local or external:

  • local (path set): makeprov reads size, media type, mtime and a SHA-256 digest off the filesystem via resolve().

  • external (id set, no path): makeprov records the IRI and whatever metadata the caller supplied, and never touches the filesystem.

External refs are how a run cites a dataset, object-store key, model checkpoint or database snapshot by stable IRI without makeprov copying that resource’s own metadata into the provenance document.

Examples

ArtifactRef.local("results/model.pkl")
ArtifactRef.external(
    "https://example.org/datasets/train-v17",
    types=("prov:Entity", "schema:Dataset"),
    digest="sha256:...",
)
digest: str | None = None
property exists: bool
extent: int | None = None
classmethod external(id, *, types=('prov:Entity',), digest=None, media_type=None, extent=None, label=None, extra=None)

Reference an entity by IRI without touching the filesystem.

Return type:

ArtifactRef

extra: dict[str, Any]
id: str | None = None
property is_external: bool
label: str | None = None
classmethod local(path, *, types=('prov:Entity',), label=None, extra=None)

Reference a file on disk. Metadata is read lazily by resolve().

Return type:

ArtifactRef

media_type: str | None = None
modified: str | None = None
path: Path | None = None
resolve()

Return a copy with filesystem metadata populated.

External refs are returned unchanged. Local refs are stat-ed and hashed.

Raises:

FileNotFoundError – If this is a local ref and the path is missing. Callers decide the policy for that; this method does not guess.

Return type:

ArtifactRef

types: tuple[str, ...] = ('prov:Entity',)