lamindb_setup.evolve .md

Manage schema evolutions for datasets.

Import plan declarations before connecting to an instance:

from lamindb_setup.evolve import create_plan

Use the lamin evolve CLI to validate, preview, and apply the plan.

Internal subpackages may change without notice.

Plans

Define a Plan and declare its reusable outputs with PlanExports.

create_plan(func)

Turn a declaration function into a Plan.

Plan(name)

Collect metadata declarations for validation, preview, and apply.

PlanContext()

Mutable context passed to Plan.run() for plan-wide settings.

PlanExports()

Base class for declaring the reusable outputs of a Plan.

PlanDeclarationError

A plan declares something that can never do what it says.

Declarations

Declare features and group them into a Schema, RecordType, or Sheet.

Feature(name, *, dtype[, type, synonyms, ...])

Declare a feature and its validation settings.

FeatureType(name, *[, type, space_uid])

Declare a type that groups related features.

SchemaType(name, *[, description, type, ...])

Declare a type that groups related schemas.

Schema([name, index, optionals, ...])

Declare validation rules for a dataset or a sheet's records.

RecordType(name, *[, description, type, ...])

Declare a type that classifies records (is_type=True).

Sheet(name, *, schema[, description, type, ...])

Declare a record type whose records must satisfy schema.

Record([name, type, features, description, ...])

Seed a named record, optionally with a type and feature values.

Typed models and dtypes

Use Python type annotations and feature() to describe schema fields.

SchemaModel()

Declarative base class for schemas (see the module docstring).

SchemaConfig

Schema-level configuration for a SchemaModel.

LaminDType()

Legacy dtype wrapper exposing an object dtype + cat_filters dict.

DType(*args, **kwargs)

A simple, non-categorical dtype (annotation only, e.g. x: DType[int]).

ListDType(*args, **kwargs)

A list dtype (annotation only, e.g. x: ListDType[int]).

CatDType

Annotate a registry type with the filters for a categorical feature.

DEFAULT_NAME_FIELD

Default lookup field for each categorical registry.

RecordCat(*, type__uid[, name_field, ...])

Filters for cat[Record[...]] features.

ULabelCat(*[, name_field, type__uid])

Filters for cat[ULabel] features.

ResolvedDType(dtype, cat_filters)

lamindb's canonical dtype string + cat_filters for an annotation.

get_dtype(annotation)

Resolve a dtype annotation into lamindb's canonical dtype string.

inline_cat_filters(dtype_str, cat_filters)

Fold cat_filters into a list[cat[...]] dtype string.

feature(*[, name, dtype, type, synonyms, ...])

Declare per-field feature options on a SchemaModel field.

Data migrations

Use fill_nulls(), map_values(), and other helpers to migrate existing data.

DataMigration(*, name, migrate[, reason, ...])

A narrowing data migration attached to a plan object.

MigrationReport([kept, matched, mapped, ...])

Per-value outcome counters a migration reports back to the caller.

MigrationError

Raised when a data migration fails to relocate every value.

fill_nulls([value, name, reason])

A migration giving a value to every row that is null for a feature made non-nullable.

fill_missing([value, feature, name, reason])

A migration giving every row that omits a newly-required member a value.

map_values(*[, mapping, transform, ...])

A migration rewriting scalar values for a narrowed scalar dtype.

map_to_records(*[, mapping, transform, ...])

A migration relocating scalar values onto existing records.

map_to_str(*[, mapping, transform, field, ...])

A migration rendering categorical values back to strings.

drop_values(*[, name, reason])

A migration deleting every value stored for the feature.

drop_rows(*[, name, reason])

A migration trashing the records of a record type the plan deletes.

revalidate_against(*, schema[, reason, ...])

A declaration pointing the datasets a deleted schema validated at another.

revalidate_rows(*[, reason, name])

A declaration asking the apply to check a sheet's rows against its new schema.

reexport_sheets(*[, sheet, name, reason])

A migration re-exporting the sheet snapshots a schema change invalidated.

accept_non_null(*[, reason, name])

A declaration vouching that datasets validated with a feature hold no nulls for it.

accept_index_change(*[, reason, ...])

A migration accepting a change to a schema's index despite validated data.

accept_flexible_change(*[, reason, name])

A migration accepting that a schema's flexible goes off despite validated data.

drop_member_values(*[, feature, name, reason])

A migration deleting the values a removed schema member still holds.

keep_member_values(*[, feature, name, reason])

A migration that retires a schema member and keeps its values.

drop_nonmember_annotations(*[, name, reason])

A migration removing what the flexible match annotated, as flexible goes off.

keep_stale_exports(*[, sheet, name, reason])

A migration that leaves an invalidated sheet export as it is.

keep_values(*[, name, reason])

A migration that deletes a feature and keeps its stored values.

keep_validated(*[, reason, name])

A declaration vouching for the datasets a schema the plan deletes validated.

keep_rows(*[, type, reason, name])

A declaration keeping the records of a record type the plan deletes.

move_rows(*, to[, reason, ...])

A declaration moving the records of a record type the plan deletes.

adopt_children(*[, to, reason, name])

A declaration re-parenting the children of a type the plan deletes.

update_record(*[, values, description, ...])

A declaration opting a seeded record into the plan's edits.

drop_record(*[, relocate_to, name, reason])

A declaration trashing a seeded record the plan no longer declares.

NULL

Sentinel for "this value is null".

DEFAULT

Sentinel for "write the feature's default_value".

Custom migrations

Write custom migration logic with helpers such as backfill_members().

MigrationContext(feature, desired_dtype, ...)

What a DataMigration callable receives when it runs.

DeclarationTarget(kind, answers[, by_key])

One kind of target a DataMigration can be declared for.

MemberMigrationContext(schema, features[, ...])

What a DataMigration attached to a schema receives.

MemberRemovalContext(schema, features[, ...])

What a DataMigration attached to a schema losing a member receives.

IndexChangeContext(schema, previous, index)

What a DataMigration attached to a schema whose index changes receives.

FlexibleChangeContext(schema, previous, flexible)

What a DataMigration attached to a schema turning flexible off receives.

FeatureRemovalContext(feature[, report])

What a DataMigration attached to a deleted feature receives.

RecordTypeRemovalContext(record_type[, report])

What a DataMigration attached to a deleted record type receives.

SchemaRemovalContext(schema[, report])

What a DataMigration attached to a deleted schema receives.

SheetExportContext(schema, exports[, ...])

Context for rewriting stale sheet exports after a schema migration.

RecordUpdateContext(record[, values, ...])

What a DataMigration attached to a seeded record receives.

RecordRemovalContext(record[, relocate_to, ...])

What a DataMigration declared for a record the plan drops receives.

backfill_members(context, /[, value, feature])

Annotate every row that omits one of the schema's newly-required members.

clear_values(context, /)

Delete every value stored for the feature, scalar and categorical alike.

clear_member_values(context, /, *[, feature])

Delete the values a schema's removed members hold on the rows it validates.

clear_nonmember_annotations(context, /)

Remove what the flexible match annotated on the artifacts a schema curated.

relocate_to_records(context, /, *[, ...])

Relocate a feature's scalar values onto existing records (str -> cat).

relocate_to_str(context, /, *[, mapping, ...])

Relocate a feature's categorical values to strings (cat -> str).

rewrite_values(context, /, *[, mapping, ...])

Rewrite a feature's scalar values for a narrowed scalar dtype.

Plan result types

SpaceUID(value, *[, registry])

UID subclass for Space registry, enforcing 12-character length.

FeatureUID(value, *[, registry])

UID subclass for Feature registry, enforcing 12-character length.

RecordUID(value, *[, registry])

UID subclass for Record registry, enforcing 16-character length.

SchemaUID(value, *[, registry])

UID subclass for Schema registry, enforcing 16-character length.

Promise(arg, func, *[, label])

A deferred call.

Dependency(obj, *[, requires])

Represents a dependency on another object that needs to be materialized first.

DependencyDAG(dependencies)

Dependencies ordered so that required objects are created first.

Moved(obj, from_)

A declared address change: obj was previously known as from_.

Migrated(obj, migration)

A migration declared for obj via migrate().

WriteStrategy(value[, names, module, ...])

How a relocation wrote the replacement annotations.

Environment variables

Configure tracking before applying plans. Explicit nonblank track_prefix and track_space settings in the instance’s CI configuration take precedence over the environment.

Variable

Value and purpose

Default

LAMIN_SCHEMA_EVOLUTION_TRACK_PREFIX

String prefix for tracked transform keys.

schema_evolution

LAMIN_SCHEMA_EVOLUTION_TRACK_SPACE

Space name or UID for tracked runs, transforms, and outputs.

all

LAMIN_SCHEMA_EVOLUTION_TRACEBACK

Any nonempty value enables tracebacks for handled command-line errors. It does not change Python API exceptions.

Unset

PLAN_TRANSFORM_STEM_UID is a variable in each plan file, not an environment variable. Keep it stable when editing the plan.