Jupyter Notebook

Query & search registries

This guide walks through different ways of querying & searching LaminDB registries.

Let’s start by creating a few exemplary datasets and saving them into a LaminDB instance (hidden cell).

# pip install 'lamindb[bionty]'
!lamin init --storage ./test-registries --modules bionty
Hide code cell output
 initialized lamindb: testuser1/test-registries
import lamindb as ln
import bionty as bt

ln.track()

# Create non-curated datasets
ln.Artifact(ln.core.datasets.file_jpg_paradisi05(), key="images/my_image.jpg").save()
ln.Artifact(ln.core.datasets.file_fastq(), key="raw/my_fastq.fastq.gz").save()
ln.Artifact.from_df(ln.core.datasets.df_iris(), key="iris.parquet").save()

# Features
ln.Feature(name="perturbation", dtype=ln.ULabel).save()
ln.Feature(name="sample_note", dtype=str).save()
ln.Feature(name="cell_type_by_expert", dtype=bt.CellType).save()
ln.Feature(name="cell_type_by_model", dtype=bt.CellType).save()
ln.Feature(name="temperature", dtype=float).save()
ln.Feature(name="experiment", dtype=ln.ULabel).save()
ln.Feature(name="date_of_study", dtype="date").save()
ln.Feature(name="study_note", dtype=str).save()

# Labels
ln.ULabel.from_values(["DMSO", "IFNG"], create=True).save()
ln.ULabel.from_values(["Experiment 1", "Experiment 2"], create=True).save()
bt.CellType.from_values(["B cell", "T cell"], create=True).save()

# Schema
schema = ln.Schema(
    components={
        "obs": ln.Schema(itype=ln.Feature).save(),
        "var": ln.Schema(itype=bt.Gene.ensembl_gene_id).save(),
    }
).save()

# Ingest dataset1
adata = ln.core.datasets.small_dataset1(otype="AnnData")
artifact = ln.Artifact.from_anndata(
    adata, key="example_datasets/dataset1.h5ad", schema=schema
)
artifact.features.add_values(adata.uns)

# Ingest dataset2
adata = ln.core.datasets.small_dataset2(otype="AnnData")
artifact = ln.Artifact.from_anndata(
    adata, key="example_datasets/dataset2.h5ad", schema=schema
)
artifact.features.add_values(adata.uns)
library(laminr)
ln <- import_module("lamindb")  # instantiate the central object of the API
bt <- import_module("bionty")  # instantiate the central object of the API

ln$track()

# Create non-curated datasets
ln$Artifact(ln$core$datasets$file_jpg_paradisi05(), key="images/my_image.jpg")$save()
ln$Artifact(ln$core$datasets$file_fastq(), key="raw/my_fastq.fastq.gz")$save()
ln$Artifact$from_df(ln$core$datasets$df_iris(), key="iris.parquet")$save()

# Features
ln$Feature(name="perturbation", dtype=ln$ULabel)$save()
ln$Feature(name="sample_note", dtype="character")$save()
ln$Feature(name="cell_type_by_expert", dtype=bt$CellType)$save()
ln$Feature(name="cell_type_by_model", dtype=bt$CellType)$save()
ln$Feature(name="temperature", dtype="numeric")$save()
ln$Feature(name="experiment", dtype=ln$ULabel)$save()
ln$Feature(name="date_of_study", dtype="date")$save()
ln$Feature(name="study_note", dtype="character")$save()

# Labels
ln$ULabel$from_values(c("DMSO", "IFNG"), create=TRUE)$save()
ln$ULabel$from_values(c("Experiment 1", "Experiment 2"), create=TRUE)$save()
bt$CellType$from_values(c("B cell", "T cell"), create=TRUE)$save()

# Schema
schema <- ln$Schema(
  components=list(
    "obs" = ln$Schema(itype=ln$Feature)$save(),
    "var" = ln$Schema(itype=bt$Gene$ensembl_gene_id)$save()
  )
)$save()

# Ingest dataset1
adata <- ln$core$datasets$small_dataset1(otype="AnnData")
artifact <- ln$Artifact$from_anndata(
  adata, key="example_datasets/dataset1.h5ad", schema=schema
)
artifact$features$add_values(adata$uns)

# Ingest dataset2
adata <- ln$core$datasets$small_dataset2(otype="AnnData")
artifact <- ln$Artifact$from_anndata(
  adata, key="example_datasets/dataset2.h5ad", schema=schema
)
artifact$features$add_values(adata$uns)
Hide code cell content
import lamindb as ln
import bionty as bt

ln.track()

# Create non-curated datasets
ln.Artifact(ln.core.datasets.file_jpg_paradisi05(), key="images/my_image.jpg").save()
ln.Artifact(ln.core.datasets.file_fastq(), key="raw/my_fastq.fastq.gz").save()
ln.Artifact.from_df(ln.core.datasets.df_iris(), key="iris.parquet").save()

# Features
ln.Feature(name="perturbation", dtype=ln.ULabel).save()
ln.Feature(name="sample_note", dtype=str).save()
ln.Feature(name="cell_type_by_expert", dtype=bt.CellType).save()
ln.Feature(name="cell_type_by_model", dtype=bt.CellType).save()
ln.Feature(name="temperature", dtype=float).save()
ln.Feature(name="experiment", dtype=ln.ULabel).save()
ln.Feature(name="date_of_study", dtype="date").save()
ln.Feature(name="study_note", dtype=str).save()

# Labels
ln.ULabel.from_values(["DMSO", "IFNG"], create=True).save()
ln.ULabel.from_values(["Experiment 1", "Experiment 2"], create=True).save()
bt.CellType.from_values(["B cell", "T cell"], create=True).save()

# Schema
schema = ln.Schema(
    otype="AnnData",
    components={
        "obs": ln.Schema(itype=ln.Feature).save(),
        "var": ln.Schema(itype=bt.Gene.ensembl_gene_id).save(),
    },
).save()

# Ingest dataset1
adata = ln.core.datasets.small_dataset1(otype="AnnData")
artifact = ln.Artifact.from_anndata(
    adata, key="example_datasets/dataset1.h5ad", schema=schema
).save()
artifact.features.add_values(adata.uns)

# Ingest dataset2
adata = ln.core.datasets.small_dataset2(otype="AnnData")
artifact = ln.Artifact.from_anndata(
    adata, key="example_datasets/dataset2.h5ad", schema=schema
).save()
artifact.features.add_values(adata.uns)
 connected lamindb: testuser1/test-registries
 created Transform('ToPOQPeDIQWN0000'), started new Run('hj3gtX8k...') at 2025-04-15 16:35:02 UTC
 notebook imports: bionty==1.3.0 lamindb==1.4.0
! 4 unique terms (50.00%) are not validated for name: 'assay_oid', 'concentration', 'treatment_time_h', 'donor'

Get an overview

The easiest way to get an overview over all artifacts is by typing df(), which returns the 100 latest artifacts in the Artifact registry.

import lamindb as ln

ln.Artifact.df()
Hide code cell output
uid key description suffix kind otype size hash n_files n_observations _hash_type _key_is_virtual _overwrite_versions space_id storage_id schema_id version is_latest run_id created_at created_by_id _aux _branch_code
id
5 7ml7X5ztaFjRGFYG0000 example_datasets/dataset2.h5ad None .h5ad dataset AnnData 22384 LBaHbBqSgCpyiLdZV-FFBQ None 3.0 md5 True False 1 1 3.0 None True 1 2025-04-15 16:35:11.541000+00:00 1 None 1
4 XkgCN7kNOZof3YKQ0000 example_datasets/dataset1.h5ad None .h5ad dataset AnnData 31672 FB3CeMjmg1ivN6HDy6wsSg None 3.0 md5 True False 1 1 3.0 None True 1 2025-04-15 16:35:08.153000+00:00 1 None 1
3 HPvsOOvxLlnULQqV0000 iris.parquet None .parquet dataset DataFrame 5088 8jtyI0r4o8fp7Gl7NayGjw None 150.0 md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.985000+00:00 1 None 1
2 bkeZFFbYrJIZmjg20000 raw/my_fastq.fastq.gz None .fastq.gz None None 20 hi7ZmAzz8sfMd3vIQr-57Q None NaN md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.798000+00:00 1 None 1
1 TkTvSRpT1NMwctkD0000 images/my_image.jpg None .jpg None None 29358 r4tnqmKI_SjrkdLzpuWp4g None NaN md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.790000+00:00 1 None 1

You can include fields from other registries.

ln.Artifact.df(
    include=[
        "created_by__name",
        "ulabels__name",
        "cell_types__name",
        "feature_sets__itype",
        "suffix",
    ]
)
Hide code cell output
uid key description created_by__name ulabels__name cell_types__name feature_sets__itype suffix
id
5 7ml7X5ztaFjRGFYG0000 example_datasets/dataset2.h5ad None Test User1 {IFNG, DMSO, Experiment 2} {T cell, B cell} {bionty.Gene, Feature} .h5ad
4 XkgCN7kNOZof3YKQ0000 example_datasets/dataset1.h5ad None Test User1 {Experiment 1, IFNG, DMSO} {T cell, B cell, CD8-positive, alpha-beta T cell} {bionty.Gene, Feature} .h5ad
3 HPvsOOvxLlnULQqV0000 iris.parquet None Test User1 {None} {None} {None} .parquet
2 bkeZFFbYrJIZmjg20000 raw/my_fastq.fastq.gz None Test User1 {None} {None} {None} .fastq.gz
1 TkTvSRpT1NMwctkD0000 images/my_image.jpg None Test User1 {None} {None} {None} .jpg

You can include information about which artifact measures which feature.

df = ln.Artifact.df(features=True)
ln.view(df)  # optionally use ln.view() to see dtypes
Hide code cell output
uidkeydescriptioncell_type_by_expertcell_type_by_modelexperimentperturbationtemperaturestudy_notedate_of_study
idstrstrstrcat[bionty.CellType]cat[bionty.CellType]cat[ULabel]cat[ULabel]floatstrdate
57ml7X5ztaFjRGFYG0000example_datasets/dataset2.h5adNonenan{'T cell', 'B cell'}{'Experiment 2'}{'IFNG', 'DMSO'}{21.6}{'We had a great time performing this study and the results look compelling.'}{'2024-12-01'}
4XkgCN7kNOZof3YKQ0000example_datasets/dataset1.h5adNone{'B cell', 'CD8-positive, alpha-beta T cell'}{'T cell', 'B cell'}{'Experiment 1'}{'IFNG', 'DMSO'}nannannan
3HPvsOOvxLlnULQqV0000iris.parquetNonenannannannannannannan
2bkeZFFbYrJIZmjg20000raw/my_fastq.fastq.gzNonenannannannannannannan
1TkTvSRpT1NMwctkD0000images/my_image.jpgNonenannannannannannannan

The flattened table that includes information from all relevant registries is easier to understand than the normalized data.

ln.view()
Hide code cell output
****************
* module: core *
****************
Artifact
uid key description suffix kind otype size hash n_files n_observations _hash_type _key_is_virtual _overwrite_versions space_id storage_id schema_id version is_latest run_id created_at created_by_id _aux _branch_code
id
5 7ml7X5ztaFjRGFYG0000 example_datasets/dataset2.h5ad None .h5ad dataset AnnData 22384 LBaHbBqSgCpyiLdZV-FFBQ None 3.0 md5 True False 1 1 3.0 None True 1 2025-04-15 16:35:11.541000+00:00 1 None 1
4 XkgCN7kNOZof3YKQ0000 example_datasets/dataset1.h5ad None .h5ad dataset AnnData 31672 FB3CeMjmg1ivN6HDy6wsSg None 3.0 md5 True False 1 1 3.0 None True 1 2025-04-15 16:35:08.153000+00:00 1 None 1
3 HPvsOOvxLlnULQqV0000 iris.parquet None .parquet dataset DataFrame 5088 8jtyI0r4o8fp7Gl7NayGjw None 150.0 md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.985000+00:00 1 None 1
2 bkeZFFbYrJIZmjg20000 raw/my_fastq.fastq.gz None .fastq.gz None None 20 hi7ZmAzz8sfMd3vIQr-57Q None NaN md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.798000+00:00 1 None 1
1 TkTvSRpT1NMwctkD0000 images/my_image.jpg None .jpg None None 29358 r4tnqmKI_SjrkdLzpuWp4g None NaN md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.790000+00:00 1 None 1
Feature
uid name dtype is_type unit description array_rank array_size array_shape proxy_dtype synonyms _expect_many _curation space_id type_id run_id created_at created_by_id _aux _branch_code
id
8 32BLQiUCBS50 study_note str None None None 0 0 None None None True None 1 None 1 2025-04-15 16:35:04.335000+00:00 1 {'af': {'0': None, '1': True, '2': False}} 1
7 sSfRNwkRXxLo date_of_study date None None None 0 0 None None None True None 1 None 1 2025-04-15 16:35:04.329000+00:00 1 {'af': {'0': None, '1': True, '2': False}} 1
6 dXlNRtja4dQT experiment cat[ULabel] None None None 0 0 None None None True None 1 None 1 2025-04-15 16:35:04.323000+00:00 1 {'af': {'0': None, '1': True, '2': False}} 1
5 NKdTJ5Iot0Cm temperature float None None None 0 0 None None None True None 1 None 1 2025-04-15 16:35:04.318000+00:00 1 {'af': {'0': None, '1': True, '2': False}} 1
4 RZwW2CC1s9q2 cell_type_by_model cat[bionty.CellType] None None None 0 0 None None None True None 1 None 1 2025-04-15 16:35:04.312000+00:00 1 {'af': {'0': None, '1': True, '2': False}} 1
3 JOCJndiGHmCl cell_type_by_expert cat[bionty.CellType] None None None 0 0 None None None True None 1 None 1 2025-04-15 16:35:04.306000+00:00 1 {'af': {'0': None, '1': True, '2': False}} 1
2 C9TRyBW0SkFb sample_note str None None None 0 0 None None None True None 1 None 1 2025-04-15 16:35:04.264000+00:00 1 {'af': {'0': None, '1': True, '2': False}} 1
FeatureValue
value hash space_id feature_id run_id created_at created_by_id _aux _branch_code
id
1 21.6 None 1 5 1 2025-04-15 16:35:09.030000+00:00 1 None 1
2 2024-12-01 None 1 7 1 2025-04-15 16:35:09.030000+00:00 1 None 1
3 We had a great time performing this study and ... None 1 8 1 2025-04-15 16:35:09.030000+00:00 1 None 1
4 22.6 None 1 5 1 2025-04-15 16:35:12.213000+00:00 1 None 1
5 2025-02-13 None 1 7 1 2025-04-15 16:35:12.213000+00:00 1 None 1
Run
uid name started_at finished_at reference reference_type _is_consecutive _status_code space_id transform_id report_id _logfile_id environment_id initiated_by_run_id created_at created_by_id _aux _branch_code
id
1 hj3gtX8kDMosY89Y5Erk None 2025-04-15 16:35:02.853418+00:00 None None None None 0 1 1 None None None None 2025-04-15 16:35:02.854000+00:00 1 None 1
Schema
uid name description n itype is_type otype dtype hash minimal_set ordered_set maximal_set _curation slot space_id type_id validated_by_id composite_id run_id created_at created_by_id _aux _branch_code
id
1 PghHUjZZZM1GnhwysvgI None None -1 Feature False None None g2J9bi8LKs3KVM0SU4hU9w True False False None None 1 None None None 1 2025-04-15 16:35:04.367000+00:00 1 {} 1
2 wXXmDez2t2MHFl04hJ1z None None -1 bionty.Gene.ensembl_gene_id False None num mwsFierZLqdZlNlg7vcGJg True False False None None 1 None None None 1 2025-04-15 16:35:04.370000+00:00 1 {} 1
3 Ci6UpYAIrIYJ2SMEjbL0 None None -1 Composite False AnnData num WYdFo-hBgr6jAHQHqh4ZtA True False False None None 1 None None None 1 2025-04-15 16:35:04.373000+00:00 1 {} 1
4 KIfXjHVXNuq6FMlKbpx8 None None 3 bionty.Gene False None int NQYjX_GYjM3HRHe_IlWJPg True False False None None 1 None None None 1 2025-04-15 16:35:09.002000+00:00 1 {} 1
5 pEVFdPnZZwzCtmp3bOtq None None 4 Feature False DataFrame None ngS28DqQEDRHogk8ZkrXuw True False False None None 1 None None None 1 2025-04-15 16:35:09.007000+00:00 1 {} 1
6 6LhNdp0VCpFU0ZkSEgKz None None 3 bionty.Gene False None int wgoHavNZTfBKcJEq8cKipg True False False None None 1 None None None 1 2025-04-15 16:35:12.188000+00:00 1 {} 1
7 f4nwE2x04fS1Vd7f00ht None None 2 Feature False DataFrame None o0rlY-joJDHecS8QHLUvCw True False False None None 1 None None None 1 2025-04-15 16:35:12.192000+00:00 1 {} 1
Storage
uid root description type region instance_uid space_id run_id created_at created_by_id _aux _branch_code
id
1 WbVbbIsYtoGx /home/runner/work/lamindb/lamindb/docs/test-re... None local None hlGq1WkbeSSf 1 None 2025-04-15 16:34:59.664000+00:00 1 None 1
Transform
uid key description type source_code hash reference reference_type space_id _template_id version is_latest created_at created_by_id _aux _branch_code
id
1 ToPOQPeDIQWN0000 registries.ipynb Query & search registries notebook None None None None 1 None None True 2025-04-15 16:35:02.848000+00:00 1 None 1
ULabel
uid name is_type description reference reference_type space_id type_id run_id created_at created_by_id _aux _branch_code
id
3 Bw51PvBF Experiment 1 False None None None 1 None 1 2025-04-15 16:35:04.353000+00:00 1 None 1
4 04kyjmog Experiment 2 False None None None 1 None 1 2025-04-15 16:35:04.353000+00:00 1 None 1
1 JZNWnv7U DMSO False None None None 1 None 1 2025-04-15 16:35:04.344000+00:00 1 None 1
2 p6GkqEl8 IFNG False None None None 1 None 1 2025-04-15 16:35:04.344000+00:00 1 None 1
******************
* module: bionty *
******************
CellType
uid name ontology_id abbr synonyms description space_id source_id run_id created_at created_by_id _aux _branch_code
id
4 4bKGljt0 cell CL:0000000 None None A Material Entity Of Anatomical Origin (Part O... 1 32 1 2025-04-15 16:35:05.179000+00:00 1 None 1
5 22LvKd01 T cell CL:0000084 None T-cell|T-lymphocyte|T lymphocyte A Type Of Lymphocyte Whose Defining Characteri... 1 32 1 2025-04-15 16:35:05.179000+00:00 1 None 1
6 2K93w3xO motile cell CL:0000219 None None A Cell That Moves By Its Own Activities. 1 32 1 2025-04-15 16:35:05.179000+00:00 1 None 1
7 2cXC7cgF single nucleate cell CL:0000226 None None A Cell With A Single Nucleus. 1 32 1 2025-04-15 16:35:05.179000+00:00 1 None 1
8 4WnpvUTH eukaryotic cell CL:0000255 None None Any Cell That Only Exists In Eukaryota. 1 32 1 2025-04-15 16:35:05.179000+00:00 1 None 1
9 X6c7osZ5 lymphocyte CL:0000542 None None A Lymphocyte Is A Leukocyte Commonly Found In ... 1 32 1 2025-04-15 16:35:05.179000+00:00 1 None 1
10 3VEAlFdi leukocyte CL:0000738 None white blood cell|leucocyte An Achromatic Cell Of The Myeloid Or Lymphoid ... 1 32 1 2025-04-15 16:35:05.179000+00:00 1 None 1
Gene
uid symbol stable_id ensembl_gene_id ncbi_gene_ids biotype synonyms description space_id source_id organism_id run_id created_at created_by_id _aux _branch_code
id
4 iFxDa8hoEWuW CD38 None ENSG00000004468 952 protein_coding CADPR1 CD38 molecule 1 11 1 1 2025-04-15 16:35:11.533000+00:00 1 None 1
1 6Aqvc8ckDYeN CD8A None ENSG00000153563 925 protein_coding P32|CD8|CD8ALPHA CD8 subunit alpha 1 11 1 1 2025-04-15 16:35:08.144000+00:00 1 None 1
2 1j4At3x7akJU CD4 None ENSG00000010610 920 protein_coding T4|LEU-3 CD4 molecule 1 11 1 1 2025-04-15 16:35:08.144000+00:00 1 None 1
3 3bhNYquOnA4s CD14 None ENSG00000170458 929 protein_coding CD14 molecule 1 11 1 1 2025-04-15 16:35:08.144000+00:00 1 None 1
Organism
uid name ontology_id scientific_name synonyms description space_id source_id run_id created_at created_by_id _aux _branch_code
id
1 1dpCL6Td human NCBITaxon:9606 Homo sapiens None None 1 1 1 2025-04-15 16:35:05.786000+00:00 1 None 1
Source
uid entity organism name in_db currently_used description url md5 source_website space_id dataframe_artifact_id version run_id created_at created_by_id _aux _branch_code
id
53 5Xov8Lap bionty.Disease all mondo False False Mondo Disease Ontology http://purl.obolibrary.org/obo/mondo/releases/... None https://mondo.monarchinitiative.org 1 None 2024-02-06 None 2025-04-15 16:34:59.873000+00:00 1 None 1
54 69lnSXfR bionty.Disease all mondo False False Mondo Disease Ontology http://purl.obolibrary.org/obo/mondo/releases/... None https://mondo.monarchinitiative.org 1 None 2024-01-03 None 2025-04-15 16:34:59.873000+00:00 1 None 1
55 4ss2Hizg bionty.Disease all mondo False False Mondo Disease Ontology http://purl.obolibrary.org/obo/mondo/releases/... None https://mondo.monarchinitiative.org 1 None 2023-08-02 None 2025-04-15 16:34:59.873000+00:00 1 None 1
56 Hgw08Vk3 bionty.Disease all mondo False False Mondo Disease Ontology http://purl.obolibrary.org/obo/mondo/releases/... None https://mondo.monarchinitiative.org 1 None 2023-04-04 None 2025-04-15 16:34:59.873000+00:00 1 None 1
57 UUZUtULu bionty.Disease all mondo False False Mondo Disease Ontology http://purl.obolibrary.org/obo/mondo/releases/... None https://mondo.monarchinitiative.org 1 None 2023-02-06 None 2025-04-15 16:34:59.873000+00:00 1 None 1
58 7DH1aJIr bionty.Disease all mondo False False Mondo Disease Ontology http://purl.obolibrary.org/obo/mondo/releases/... None https://mondo.monarchinitiative.org 1 None 2022-10-11 None 2025-04-15 16:34:59.873000+00:00 1 None 1
59 4kswnHVF bionty.Disease human doid False True Human Disease Ontology http://purl.obolibrary.org/obo/doid/releases/2... None https://disease-ontology.org 1 None 2024-05-29 None 2025-04-15 16:34:59.873000+00:00 1 None 1

Auto-complete records

For registries with less than 100k records, auto-completing a Lookup object is the most convenient way of finding a record.

import bionty as bt

# query the database for all ulabels or all cell types
ulabels = ln.ULabel.lookup()
cell_types = bt.CellType.lookup()
Show me a screenshot

With auto-complete, we find a ulabel:

study1 = ulabels.experiment_1
study1
Hide code cell output
ULabel(uid='Bw51PvBF', name='Experiment 1', is_type=False, space_id=1, created_by_id=1, run_id=1, created_at=2025-04-15 16:35:04 UTC)

Get one record

get errors if more than one matching records are found.

print(study1.uid)

# by uid
ln.ULabel.get(study1.uid)

# by field
ln.ULabel.get(name="Experiment 1")
Hide code cell output
Bw51PvBF
ULabel(uid='Bw51PvBF', name='Experiment 1', is_type=False, space_id=1, created_by_id=1, run_id=1, created_at=2025-04-15 16:35:04 UTC)

Query records by fields

Filter for all artifacts annotated by a ulabel:

ln.Artifact.filter(ulabels=study1).df()
Hide code cell output
uid key description suffix kind otype size hash n_files n_observations _hash_type _key_is_virtual _overwrite_versions space_id storage_id schema_id version is_latest run_id created_at created_by_id _aux _branch_code
id
4 XkgCN7kNOZof3YKQ0000 example_datasets/dataset1.h5ad None .h5ad dataset AnnData 31672 FB3CeMjmg1ivN6HDy6wsSg None 3 md5 True False 1 1 3 None True 1 2025-04-15 16:35:08.153000+00:00 1 None 1

To access the results encoded in a filter statement, execute its return value with one of:

  • df(): A pandas DataFrame with each record in a row.

  • all(): A QuerySet.

  • one(): Exactly one record. Will raise an error if there is none. Is equivalent to the .get() method shown above.

  • one_or_none(): Either one record or None if there is no query result.

Note

filter() returns a QuerySet.

The registries in LaminDB are Django Models and any Django query works.

LaminDB re-interprets Django’s API for data scientists.

What does this have to do with SQL?

Under the hood, any .filter() call translates into a SQL select statement.

LaminDB’s registries are object relational mappers (ORMs) that rely on Django for all the heavy lifting.

Of note, .one() and .one_or_none() are the two parts of LaminDB’s API that are borrowed from SQLAlchemy. In its first year, LaminDB built on SQLAlchemy.

Query datasets by features

The Artifact registry is the only registry that additionally allows to query by features.

ln.Artifact.filter(perturbation="DMSO").df(features=True)
uid key description cell_type_by_model cell_type_by_expert experiment perturbation temperature study_note date_of_study
id
4 XkgCN7kNOZof3YKQ0000 example_datasets/dataset1.h5ad None {T cell, B cell} {B cell, CD8-positive, alpha-beta T cell} {Experiment 1} {IFNG, DMSO} {21.6} {We had a great time performing this study and... {2024-12-01}
5 7ml7X5ztaFjRGFYG0000 example_datasets/dataset2.h5ad None {T cell, B cell} NaN {Experiment 2} {IFNG, DMSO} NaN NaN NaN

Query runs by parameters

Here is an example for querying by parameters: Query by run parameters.

Search for records

You can search every registry via search(). For example, the Artifact registry.

ln.Artifact.search("iris").df()
Hide code cell output
uid key description suffix kind otype size hash n_files n_observations _hash_type _key_is_virtual _overwrite_versions space_id storage_id schema_id version is_latest run_id created_at created_by_id _aux _branch_code
id
3 HPvsOOvxLlnULQqV0000 iris.parquet None .parquet dataset DataFrame 5088 8jtyI0r4o8fp7Gl7NayGjw None 150 md5 True False 1 1 None None True 1 2025-04-15 16:35:03.985000+00:00 1 None 1

Here is more background on search and examples for searching the entire cell type ontology: How does search work?

Filter operators

You can qualify the type of comparison in a query by using a comparator.

Below follows a list of the most import, but Django supports about two dozen field comparators field__comparator=value.

and

ln.Artifact.filter(suffix=".h5ad", ulabels=study1).df()
Hide code cell output
uid key description suffix kind otype size hash n_files n_observations _hash_type _key_is_virtual _overwrite_versions space_id storage_id schema_id version is_latest run_id created_at created_by_id _aux _branch_code
id
4 XkgCN7kNOZof3YKQ0000 example_datasets/dataset1.h5ad None .h5ad dataset AnnData 31672 FB3CeMjmg1ivN6HDy6wsSg None 3 md5 True False 1 1 3 None True 1 2025-04-15 16:35:08.153000+00:00 1 None 1

less than/ greater than

Or subset to artifacts greater than 10kB. Here, we can’t use keyword arguments, but need an explicit where statement.

ln.Artifact.filter(ulabels=study1, size__gt=1e4).df()
Hide code cell output
uid key description suffix kind otype size hash n_files n_observations _hash_type _key_is_virtual _overwrite_versions space_id storage_id schema_id version is_latest run_id created_at created_by_id _aux _branch_code
id
4 XkgCN7kNOZof3YKQ0000 example_datasets/dataset1.h5ad None .h5ad dataset AnnData 31672 FB3CeMjmg1ivN6HDy6wsSg None 3 md5 True False 1 1 3 None True 1 2025-04-15 16:35:08.153000+00:00 1 None 1

in

ln.Artifact.filter(suffix__in=[".jpg", ".fastq.gz"]).df()
Hide code cell output
uid key description suffix kind otype size hash n_files n_observations _hash_type _key_is_virtual _overwrite_versions space_id storage_id schema_id version is_latest run_id created_at created_by_id _aux _branch_code
id
1 TkTvSRpT1NMwctkD0000 images/my_image.jpg None .jpg None None 29358 r4tnqmKI_SjrkdLzpuWp4g None None md5 True False 1 1 None None True 1 2025-04-15 16:35:03.790000+00:00 1 None 1
2 bkeZFFbYrJIZmjg20000 raw/my_fastq.fastq.gz None .fastq.gz None None 20 hi7ZmAzz8sfMd3vIQr-57Q None None md5 True False 1 1 None None True 1 2025-04-15 16:35:03.798000+00:00 1 None 1

order by

ln.Artifact.filter().order_by("created_at").df()
Hide code cell output
uid key description suffix kind otype size hash n_files n_observations _hash_type _key_is_virtual _overwrite_versions space_id storage_id schema_id version is_latest run_id created_at created_by_id _aux _branch_code
id
1 TkTvSRpT1NMwctkD0000 images/my_image.jpg None .jpg None None 29358 r4tnqmKI_SjrkdLzpuWp4g None NaN md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.790000+00:00 1 None 1
2 bkeZFFbYrJIZmjg20000 raw/my_fastq.fastq.gz None .fastq.gz None None 20 hi7ZmAzz8sfMd3vIQr-57Q None NaN md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.798000+00:00 1 None 1
3 HPvsOOvxLlnULQqV0000 iris.parquet None .parquet dataset DataFrame 5088 8jtyI0r4o8fp7Gl7NayGjw None 150.0 md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.985000+00:00 1 None 1
4 XkgCN7kNOZof3YKQ0000 example_datasets/dataset1.h5ad None .h5ad dataset AnnData 31672 FB3CeMjmg1ivN6HDy6wsSg None 3.0 md5 True False 1 1 3.0 None True 1 2025-04-15 16:35:08.153000+00:00 1 None 1
5 7ml7X5ztaFjRGFYG0000 example_datasets/dataset2.h5ad None .h5ad dataset AnnData 22384 LBaHbBqSgCpyiLdZV-FFBQ None 3.0 md5 True False 1 1 3.0 None True 1 2025-04-15 16:35:11.541000+00:00 1 None 1
# reverse ordering
ln.Artifact.filter().order_by("-created_at").df()
Hide code cell output
uid key description suffix kind otype size hash n_files n_observations _hash_type _key_is_virtual _overwrite_versions space_id storage_id schema_id version is_latest run_id created_at created_by_id _aux _branch_code
id
5 7ml7X5ztaFjRGFYG0000 example_datasets/dataset2.h5ad None .h5ad dataset AnnData 22384 LBaHbBqSgCpyiLdZV-FFBQ None 3.0 md5 True False 1 1 3.0 None True 1 2025-04-15 16:35:11.541000+00:00 1 None 1
4 XkgCN7kNOZof3YKQ0000 example_datasets/dataset1.h5ad None .h5ad dataset AnnData 31672 FB3CeMjmg1ivN6HDy6wsSg None 3.0 md5 True False 1 1 3.0 None True 1 2025-04-15 16:35:08.153000+00:00 1 None 1
3 HPvsOOvxLlnULQqV0000 iris.parquet None .parquet dataset DataFrame 5088 8jtyI0r4o8fp7Gl7NayGjw None 150.0 md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.985000+00:00 1 None 1
2 bkeZFFbYrJIZmjg20000 raw/my_fastq.fastq.gz None .fastq.gz None None 20 hi7ZmAzz8sfMd3vIQr-57Q None NaN md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.798000+00:00 1 None 1
1 TkTvSRpT1NMwctkD0000 images/my_image.jpg None .jpg None None 29358 r4tnqmKI_SjrkdLzpuWp4g None NaN md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.790000+00:00 1 None 1
ln.Artifact.filter().order_by("key").df()
Hide code cell output
uid key description suffix kind otype size hash n_files n_observations _hash_type _key_is_virtual _overwrite_versions space_id storage_id schema_id version is_latest run_id created_at created_by_id _aux _branch_code
id
4 XkgCN7kNOZof3YKQ0000 example_datasets/dataset1.h5ad None .h5ad dataset AnnData 31672 FB3CeMjmg1ivN6HDy6wsSg None 3.0 md5 True False 1 1 3.0 None True 1 2025-04-15 16:35:08.153000+00:00 1 None 1
5 7ml7X5ztaFjRGFYG0000 example_datasets/dataset2.h5ad None .h5ad dataset AnnData 22384 LBaHbBqSgCpyiLdZV-FFBQ None 3.0 md5 True False 1 1 3.0 None True 1 2025-04-15 16:35:11.541000+00:00 1 None 1
1 TkTvSRpT1NMwctkD0000 images/my_image.jpg None .jpg None None 29358 r4tnqmKI_SjrkdLzpuWp4g None NaN md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.790000+00:00 1 None 1
3 HPvsOOvxLlnULQqV0000 iris.parquet None .parquet dataset DataFrame 5088 8jtyI0r4o8fp7Gl7NayGjw None 150.0 md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.985000+00:00 1 None 1
2 bkeZFFbYrJIZmjg20000 raw/my_fastq.fastq.gz None .fastq.gz None None 20 hi7ZmAzz8sfMd3vIQr-57Q None NaN md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.798000+00:00 1 None 1
# reverse ordering
ln.Artifact.filter().order_by("-key").df()
uid key description suffix kind otype size hash n_files n_observations _hash_type _key_is_virtual _overwrite_versions space_id storage_id schema_id version is_latest run_id created_at created_by_id _aux _branch_code
id
2 bkeZFFbYrJIZmjg20000 raw/my_fastq.fastq.gz None .fastq.gz None None 20 hi7ZmAzz8sfMd3vIQr-57Q None NaN md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.798000+00:00 1 None 1
3 HPvsOOvxLlnULQqV0000 iris.parquet None .parquet dataset DataFrame 5088 8jtyI0r4o8fp7Gl7NayGjw None 150.0 md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.985000+00:00 1 None 1
1 TkTvSRpT1NMwctkD0000 images/my_image.jpg None .jpg None None 29358 r4tnqmKI_SjrkdLzpuWp4g None NaN md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.790000+00:00 1 None 1
5 7ml7X5ztaFjRGFYG0000 example_datasets/dataset2.h5ad None .h5ad dataset AnnData 22384 LBaHbBqSgCpyiLdZV-FFBQ None 3.0 md5 True False 1 1 3.0 None True 1 2025-04-15 16:35:11.541000+00:00 1 None 1
4 XkgCN7kNOZof3YKQ0000 example_datasets/dataset1.h5ad None .h5ad dataset AnnData 31672 FB3CeMjmg1ivN6HDy6wsSg None 3.0 md5 True False 1 1 3.0 None True 1 2025-04-15 16:35:08.153000+00:00 1 None 1

contains

ln.Transform.filter(description__contains="search").df().head(5)
Hide code cell output
uid key description type source_code hash reference reference_type space_id _template_id version is_latest created_at created_by_id _aux _branch_code
id
1 ToPOQPeDIQWN0000 registries.ipynb Query & search registries notebook None None None None 1 None None True 2025-04-15 16:35:02.848000+00:00 1 None 1

And case-insensitive:

ln.Transform.filter(description__icontains="Search").df().head(5)
Hide code cell output
uid key description type source_code hash reference reference_type space_id _template_id version is_latest created_at created_by_id _aux _branch_code
id
1 ToPOQPeDIQWN0000 registries.ipynb Query & search registries notebook None None None None 1 None None True 2025-04-15 16:35:02.848000+00:00 1 None 1

startswith

ln.Transform.filter(description__startswith="Query").df()
Hide code cell output
uid key description type source_code hash reference reference_type space_id _template_id version is_latest created_at created_by_id _aux _branch_code
id
1 ToPOQPeDIQWN0000 registries.ipynb Query & search registries notebook None None None None 1 None None True 2025-04-15 16:35:02.848000+00:00 1 None 1

or

ln.Artifact.filter(ln.Q(suffix=".jpg") | ln.Q(suffix=".fastq.gz")).df()
Hide code cell output
uid key description suffix kind otype size hash n_files n_observations _hash_type _key_is_virtual _overwrite_versions space_id storage_id schema_id version is_latest run_id created_at created_by_id _aux _branch_code
id
1 TkTvSRpT1NMwctkD0000 images/my_image.jpg None .jpg None None 29358 r4tnqmKI_SjrkdLzpuWp4g None None md5 True False 1 1 None None True 1 2025-04-15 16:35:03.790000+00:00 1 None 1
2 bkeZFFbYrJIZmjg20000 raw/my_fastq.fastq.gz None .fastq.gz None None 20 hi7ZmAzz8sfMd3vIQr-57Q None None md5 True False 1 1 None None True 1 2025-04-15 16:35:03.798000+00:00 1 None 1

negate/ unequal

ln.Artifact.filter(~ln.Q(suffix=".jpg")).df()
Hide code cell output
uid key description suffix kind otype size hash n_files n_observations _hash_type _key_is_virtual _overwrite_versions space_id storage_id schema_id version is_latest run_id created_at created_by_id _aux _branch_code
id
2 bkeZFFbYrJIZmjg20000 raw/my_fastq.fastq.gz None .fastq.gz None None 20 hi7ZmAzz8sfMd3vIQr-57Q None NaN md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.798000+00:00 1 None 1
3 HPvsOOvxLlnULQqV0000 iris.parquet None .parquet dataset DataFrame 5088 8jtyI0r4o8fp7Gl7NayGjw None 150.0 md5 True False 1 1 NaN None True 1 2025-04-15 16:35:03.985000+00:00 1 None 1
4 XkgCN7kNOZof3YKQ0000 example_datasets/dataset1.h5ad None .h5ad dataset AnnData 31672 FB3CeMjmg1ivN6HDy6wsSg None 3.0 md5 True False 1 1 3.0 None True 1 2025-04-15 16:35:08.153000+00:00 1 None 1
5 7ml7X5ztaFjRGFYG0000 example_datasets/dataset2.h5ad None .h5ad dataset AnnData 22384 LBaHbBqSgCpyiLdZV-FFBQ None 3.0 md5 True False 1 1 3.0 None True 1 2025-04-15 16:35:11.541000+00:00 1 None 1