## Typed models and dtypes

Describe schema fields with Python type annotations.

# Schema models

class lamindb_setup.evolve.SchemaModel

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

class lamindb_setup.evolve.SchemaConfig

 Schema-level configuration for a "SchemaModel".

 Mirrors the way pydantic's "model_config" configures a model.  All
 keys are optional.  "default_feature_type" and
 "default_feature_space" are applied to fields that do not set their
 own via "feature()".

# Feature dtypes

class lamindb_setup.evolve.LaminDType(dtype: type[T], /, **cat_filters: Any)
class lamindb_setup.evolve.LaminDType(dtype: Literal['num'], /, **cat_filters: Any)
class lamindb_setup.evolve.LaminDType(dtype: Literal['path'], /, **cat_filters: Any)
class lamindb_setup.evolve.LaminDType(dtype: Literal['url'], /, **cat_filters: Any)
| class lamindb_setup.evolve.LaminDType(dtype: list[Any] | tuple[Any, ...], /) |

 Legacy dtype wrapper exposing an object "dtype" + "cat_filters"
 dict.

 Retained for existing "Feature(dtype=LaminDType(...))" call sites
 and the introspection codegen.  New code should prefer the
 annotation forms ("DType" / "ListDType" / "CatDType") resolved with
 "get_dtype()".  Use "dtype_str" for lamindb's canonical string.

 property dtype: Any

 The underlying dtype, re-resolved against the connected
 instance.

 Categorical dtypes store the registry's qualified name. Reading
 this property resolves the class against the current connection.

 property dtype_str: str

 lamindb's canonical dtype string for this dtype (excludes
 cat_filters).

class lamindb_setup.evolve.DType(*args: Any, **kwargs: Any)

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

 Resolve it into a concrete lamindb dtype via "get_dtype()".

class lamindb_setup.evolve.ListDType(*args: Any, **kwargs: Any)

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

 The inner type is a simple dtype ("ListDType[int]") or a
 categorical ("ListDType[CatDType[Record,
 RecordCat(type__uid=...)]]"); a categorical's filters are folded
 into the dtype string by "inline_cat_filters()" when the feature is
 staged.  Resolve it into a concrete lamindb dtype via
 "get_dtype()".

lamindb_setup.evolve.CatDType

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

lamindb_setup.evolve.DEFAULT_NAME_FIELD = {'Artifact': 'key', 'Biologic': 'name', 'CellLine': 'name', 'CellMarker': 'name', 'CellType': 'name', 'Collection': 'key', 'CombinationPerturbation': 'name', 'Compound': 'name', 'CompoundPerturbation': 'name', 'DevelopmentalStage': 'name', 'Disease': 'name', 'EnvironmentalPerturbation': 'name', 'Ethnicity': 'name', 'ExperimentalFactor': 'name', 'Feature': 'name', 'Gene': 'symbol', 'GeneticPerturbation': 'name', 'Organism': 'name', 'Pathway': 'name', 'PerturbationTarget': 'name', 'Phenotype': 'name', 'Project': 'name', 'Protein': 'name', 'Record': 'name', 'Reference': 'name', 'Run': 'started_at', 'Schema': 'name', 'Source': 'name', 'Storage': 'root', 'Tissue': 'name', 'Transform': 'key', 'ULabel': 'name', 'User': 'handle'}

 Default lookup field for each categorical registry.

class lamindb_setup.evolve.RecordCat(*, type__uid, name_field=None, schema__uid=None, is_type=None)

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

 "type__uid" selects the record type the categorical points at; pass
 either a literal uid string or a ".uid" promise to a plan-managed
 "RecordType" / "Sheet" (e.g.
 "RecordCat(type__uid=my_record_type.uid, is_type=True)").

| name_field: "str" | "None" = None |

| schema__uid: "str" | "Promise"["Any", "Any"] | "None" = None |

| is_type: "bool" | "None" = None |

class lamindb_setup.evolve.ULabelCat(*, name_field=None, type__uid=None)

 Filters for "cat[ULabel]" features.

| name_field: "str" | "None" = None |

| type__uid: "str" | "Promise"["Any", "Any"] | "None" = None |

class lamindb_setup.evolve.ResolvedDType(dtype, cat_filters)

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

 property dtype_str: str

 lamindb's canonical dtype string (already resolved; excludes
 cat_filters).

 Mirrors "LaminDType.dtype_str" so both dtype wrappers expose the
 same interface to "Feature".

lamindb_setup.evolve.get_dtype(annotation)

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

 Handles "DType"/"ListDType" generic aliases, "CatDType"
 ("Annotated"), and bare Python simple/list types.  For a
 categorical annotation the "name_field" selector picks the registry
 field (defaulting to "DEFAULT_NAME_FIELD", else the bare registry).
 The resulting dtype spec is stringified through lamindb's own
 "serialize_dtype" mechanism.

 Return type:
 "ResolvedDType"

lamindb_setup.evolve.inline_cat_filters(dtype_str, cat_filters)

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

 lamindb's "Feature(..., cat_filters=...)" keyword rejects every
 nested dtype ("cat_filters are incompatible with nested dtypes"),
 so a *list* of a filtered categorical cannot be declared through
 it.  Its dtype string *grammar* does support the filters inline,
 though -- "list[cat[Record[<type-uid>]]]",
 "list[cat[bionty.CellType[source__uid='x']]]" -- and "parse_dtype"
 reads them back with "list: True".  This mirrors the serialization
 lamindb applies to a scalar categorical, so passing the result as
 the feature's "dtype" yields exactly the string lamindb would have
 stored had it accepted the keyword.

 Raises "ValueError" when "dtype_str" is not a list of a single
 categorical (a union carries no filters -- lamindb forbids them).

 Return type:
 "str"

# Field declarations

lamindb_setup.evolve.feature(*, name=None, dtype=None, type=None, synonyms=None, unit=None, description=None, nullable=None, optional=None, default_value=None, coerce=None, space_uid=None)

 Declare per-field feature options on a "SchemaModel" field.

 Assign the result to a "Feature[...]"-annotated field to override
 its name, dtype, feature type, or any other "Feature" setting:

 organism: Feature[str] = feature(description="Species", nullable=True)

 Returns "Any" so it can be assigned to a "Feature[T]"-annotated
 field without a type error, mirroring pydantic's "Field()".

 Return type:
 "Any"