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_configconfigures a model. All keys are optional.default_feature_typeanddefault_feature_spaceare applied to fields that do not set their own viafeature().
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_filtersdict.Retained for existing
Feature(dtype=LaminDType(...))call sites and the introspection codegen. New code should prefer the annotation forms (DType/ListDType/CatDType) resolved withget_dtype(). Usedtype_strfor 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 byinline_cat_filters()when the feature is staged. Resolve it into a concrete lamindb dtype viaget_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__uidselects the record type the categorical points at; pass either a literal uid string or a.uidpromise to a plan-managedRecordType/Sheet(e.g.RecordCat(type__uid=my_record_type.uid, is_type=True)).-
name_field:
str|None= None¶
-
is_type:
bool|None= None¶
-
name_field:
- class lamindb_setup.evolve.ULabelCat(*, name_field=None, type__uid=None)¶
Filters for
cat[ULabel]features.-
name_field:
str|None= None¶
-
name_field:
- class lamindb_setup.evolve.ResolvedDType(dtype, cat_filters)¶
lamindb’s canonical dtype string +
cat_filtersfor an annotation.- property dtype_str: str¶
lamindb’s canonical dtype string (already resolved; excludes cat_filters).
Mirrors
LaminDType.dtype_strso both dtype wrappers expose the same interface toFeature.
- lamindb_setup.evolve.get_dtype(annotation)¶
Resolve a dtype annotation into lamindb’s canonical dtype string.
Handles
DType/ListDTypegeneric aliases,CatDType(Annotated), and bare Python simple/list types. For a categorical annotation thename_fieldselector picks the registry field (defaulting toDEFAULT_NAME_FIELD, else the bare registry). The resulting dtype spec is stringified through lamindb’s ownserialize_dtypemechanism.- Return type:
- lamindb_setup.evolve.inline_cat_filters(dtype_str, cat_filters)¶
Fold
cat_filtersinto alist[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']]]– andparse_dtypereads them back withlist: True. This mirrors the serialization lamindb applies to a scalar categorical, so passing the result as the feature’sdtypeyields exactly the string lamindb would have stored had it accepted the keyword.Raises
ValueErrorwhendtype_stris 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
SchemaModelfield.Assign the result to a
Feature[...]-annotated field to override its name, dtype, feature type, or any otherFeaturesetting:organism: Feature[str] = feature(description="Species", nullable=True)
Returns
Anyso it can be assigned to aFeature[T]-annotated field without a type error, mirroring pydantic’sField().- Return type:
Any