Query & search registries¶
Find & access data using registries.
Setup¶
!lamin init --storage ./mydata
Show code cell output
💡 connected lamindb: testuser1/mydata
import lamindb as ln
ln.settings.verbosity = "info"
💡 connected lamindb: testuser1/mydata
We’ll need some toy data:
ln.Artifact(ln.core.datasets.file_jpg_paradisi05(), description="My image").save()
ln.Artifact.from_df(ln.core.datasets.df_iris(), description="The iris collection").save()
ln.Artifact(ln.core.datasets.file_fastq(), description="My fastq").save()
Show code cell output
❗ no run & transform get linked, consider calling ln.track()
✅ storing artifact 'ZTvbFRQrhQeF2KDyXX2u' at '/home/runner/work/lamindb/lamindb/docs/mydata/.lamindb/ZTvbFRQrhQeF2KDyXX2u.jpg'
❗ no run & transform get linked, consider calling ln.track()
✅ storing artifact '7oyPKlXi5foEtDV5gJdP' at '/home/runner/work/lamindb/lamindb/docs/mydata/.lamindb/7oyPKlXi5foEtDV5gJdP.parquet'
❗ no run & transform get linked, consider calling ln.track()
✅ storing artifact 'NrSxVowDV0zXfStQ1blW' at '/home/runner/work/lamindb/lamindb/docs/mydata/.lamindb/NrSxVowDV0zXfStQ1blW.fastq.gz'
Artifact(uid='NrSxVowDV0zXfStQ1blW', description='My fastq', suffix='.fastq.gz', size=20, hash='hi7ZmAzz8sfMd3vIQr-57Q', hash_type='md5', visibility=1, key_is_virtual=True, created_by_id=1, storage_id=1, updated_at='2024-06-13 12:06:14 UTC')
Look up metadata¶
For entities where we don’t store more than 100k records, a look up object can be a convenient way of selecting a record.
Consider the User
registry:
users = ln.User.lookup(field="handle")
With auto-complete, we find a user:
user = users.testuser1
user
User(uid='DzTjkKse', handle='testuser1', name='Test User1', updated_at='2024-06-13 12:06:12 UTC')
Note
You can also auto-complete in a dictionary:
users_dict = ln.User.lookup().dict()
Filter by metadata¶
Filter for all artifacts created by a user:
ln.Artifact.filter(created_by=user).df()
uid | version | description | key | suffix | accessor | size | hash | hash_type | n_objects | n_observations | visibility | key_is_virtual | storage_id | transform_id | run_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||||||
1 | ZTvbFRQrhQeF2KDyXX2u | None | My image | None | .jpg | None | 29358 | r4tnqmKI_SjrkdLzpuWp4g | md5 | None | None | 1 | True | 1 | None | None | 1 | 2024-06-13 12:06:14.650238+00:00 |
2 | 7oyPKlXi5foEtDV5gJdP | None | The iris collection | None | .parquet | DataFrame | 5629 | ah24lV9Ncc8nPL0MumEsdw | md5 | None | None | 1 | True | 1 | None | None | 1 | 2024-06-13 12:06:14.965248+00:00 |
3 | NrSxVowDV0zXfStQ1blW | None | My fastq | None | .fastq.gz | None | 20 | hi7ZmAzz8sfMd3vIQr-57Q | md5 | None | None | 1 | True | 1 | None | None | 1 | 2024-06-13 12:06:14.973238+00:00 |
To access the results encoded in a filter statement, execute its return value with one of:
.df()
: A pandasDataFrame
with each record stored as a row..all()
: An indexable djangoQuerySet
..list()
: A list of records..one()
: Exactly one record. Will raise an error if there is none..one_or_none()
: Either one record orNone
if there is no query result.
Note
The ORMs in LaminDB are Django Models and any Django query works. LaminDB extends Django’s API for data scientists.
Under the hood, any .filter()
call translates into a SQL select statement.
.one()
and .one_or_none()
are two parts of LaminDB’s API that are borrowed from SQLAlchemy.
Search for metadata¶
ln.Artifact.search("iris").df()
uid | version | description | key | suffix | accessor | size | hash | hash_type | n_objects | n_observations | visibility | key_is_virtual | storage_id | transform_id | run_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||||||
2 | 7oyPKlXi5foEtDV5gJdP | None | The iris collection | None | .parquet | DataFrame | 5629 | ah24lV9Ncc8nPL0MumEsdw | md5 | None | None | 1 | True | 1 | None | None | 1 | 2024-06-13 12:06:14.965248+00:00 |
Let us create 500 notebook objects with fake titles and save them:
ln.save(
[
ln.Transform(name=title, type="notebook")
for title in ln.core.datasets.fake_bio_notebook_titles(n=500)
]
)
We can now search for any combination of terms:
ln.Transform.search("intestine").df().head()
uid | version | name | key | description | type | reference | reference_type | latest_report_id | source_code_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||
4 | G0V7t3TKKt6ON6MQ | None | Intestine Cementoblast investigate rank IgD ca... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.739796+00:00 |
17 | R0FQUvU5M1osp8fp | None | Bone Marrow classify Transitional epithelium B... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.741853+00:00 |
21 | F5V0SOgVmjEt365V | None | Igg Skin IgG3 result intestine IgD. | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.742474+00:00 |
34 | EdThNWTN3DmSBC61 | None | Igd IgG intestine investigate IgG. | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.744514+00:00 |
35 | KpLd4osfrDcvMTf9 | None | Candidate intestine Medulla oblongata IgG3 Med... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.744668+00:00 |
Leverage relations¶
Django has a double-under-score syntax to filter based on related tables.
This syntax enables you to traverse several layers of relations:
ln.Artifact.filter(run__created_by__handle__startswith="testuse").df()
uid | version | description | key | suffix | accessor | size | hash | hash_type | n_objects | n_observations | visibility | key_is_virtual | storage_id | transform_id | run_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
The filter selects all artifacts based on the users who ran the generating notebook.
(Under the hood, in the SQL database, it’s joining the artifact table with the run and the user table.)
Beyond __startswith
, Django supports about two dozen field comparators field__comparator=value
.
Here are some of them.
and¶
ln.Artifact.filter(suffix=".jpg", created_by=user).df()
uid | version | description | key | suffix | accessor | size | hash | hash_type | n_objects | n_observations | visibility | key_is_virtual | storage_id | transform_id | run_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||||||
1 | ZTvbFRQrhQeF2KDyXX2u | None | My image | None | .jpg | None | 29358 | r4tnqmKI_SjrkdLzpuWp4g | md5 | None | None | 1 | True | 1 | None | None | 1 | 2024-06-13 12:06:14.650238+00:00 |
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(created_by=user, size__lt=1e4).df()
uid | version | description | key | suffix | accessor | size | hash | hash_type | n_objects | n_observations | visibility | key_is_virtual | storage_id | transform_id | run_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||||||
2 | 7oyPKlXi5foEtDV5gJdP | None | The iris collection | None | .parquet | DataFrame | 5629 | ah24lV9Ncc8nPL0MumEsdw | md5 | None | None | 1 | True | 1 | None | None | 1 | 2024-06-13 12:06:14.965248+00:00 |
3 | NrSxVowDV0zXfStQ1blW | None | My fastq | None | .fastq.gz | None | 20 | hi7ZmAzz8sfMd3vIQr-57Q | md5 | None | None | 1 | True | 1 | None | None | 1 | 2024-06-13 12:06:14.973238+00:00 |
or¶
from django.db.models import Q
ln.Artifact.filter().filter(Q(suffix=".jpg") | Q(suffix=".fastq.gz")).df()
uid | version | description | key | suffix | accessor | size | hash | hash_type | n_objects | n_observations | visibility | key_is_virtual | storage_id | transform_id | run_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||||||
1 | ZTvbFRQrhQeF2KDyXX2u | None | My image | None | .jpg | None | 29358 | r4tnqmKI_SjrkdLzpuWp4g | md5 | None | None | 1 | True | 1 | None | None | 1 | 2024-06-13 12:06:14.650238+00:00 |
3 | NrSxVowDV0zXfStQ1blW | None | My fastq | None | .fastq.gz | None | 20 | hi7ZmAzz8sfMd3vIQr-57Q | md5 | None | None | 1 | True | 1 | None | None | 1 | 2024-06-13 12:06:14.973238+00:00 |
in¶
ln.Artifact.filter(suffix__in=[".jpg", ".fastq.gz"]).df()
uid | version | description | key | suffix | accessor | size | hash | hash_type | n_objects | n_observations | visibility | key_is_virtual | storage_id | transform_id | run_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||||||
1 | ZTvbFRQrhQeF2KDyXX2u | None | My image | None | .jpg | None | 29358 | r4tnqmKI_SjrkdLzpuWp4g | md5 | None | None | 1 | True | 1 | None | None | 1 | 2024-06-13 12:06:14.650238+00:00 |
3 | NrSxVowDV0zXfStQ1blW | None | My fastq | None | .fastq.gz | None | 20 | hi7ZmAzz8sfMd3vIQr-57Q | md5 | None | None | 1 | True | 1 | None | None | 1 | 2024-06-13 12:06:14.973238+00:00 |
order by¶
ln.Artifact.filter().order_by("-updated_at").df()
uid | version | description | key | suffix | accessor | size | hash | hash_type | n_objects | n_observations | visibility | key_is_virtual | storage_id | transform_id | run_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||||||
3 | NrSxVowDV0zXfStQ1blW | None | My fastq | None | .fastq.gz | None | 20 | hi7ZmAzz8sfMd3vIQr-57Q | md5 | None | None | 1 | True | 1 | None | None | 1 | 2024-06-13 12:06:14.973238+00:00 |
2 | 7oyPKlXi5foEtDV5gJdP | None | The iris collection | None | .parquet | DataFrame | 5629 | ah24lV9Ncc8nPL0MumEsdw | md5 | None | None | 1 | True | 1 | None | None | 1 | 2024-06-13 12:06:14.965248+00:00 |
1 | ZTvbFRQrhQeF2KDyXX2u | None | My image | None | .jpg | None | 29358 | r4tnqmKI_SjrkdLzpuWp4g | md5 | None | None | 1 | True | 1 | None | None | 1 | 2024-06-13 12:06:14.650238+00:00 |
contains¶
ln.Transform.filter(name__contains="search").df().head(10)
uid | version | name | key | description | type | reference | reference_type | latest_report_id | source_code_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||
7 | Bzy9ebSVn0Qa8Rbd | None | Research Vagina Foveolar cell investigate visu... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.740268+00:00 |
11 | 9qYEskyaofJ5YOEa | None | Visualize research Pineal gland Midbrain inves... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.740907+00:00 |
33 | bG1MAqUJ2D5TWpNJ | None | Iga research candidate efficiency IgG2 Foveola... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.744359+00:00 |
46 | KObvc4dLlRS7AYM6 | None | Research IgG1 Transitional epithelium IgM IgG4... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.746369+00:00 |
55 | 62rUxM02zijQysGx | None | Outer Root Sheath intestine research. | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.747785+00:00 |
56 | Swoq1oIqn9KYdoIT | None | Research Medullary Outer root sheath IgG4 clas... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.747946+00:00 |
69 | n1PncK4nDwa6BREr | None | Helper T Cell IgG2 candidate research research. | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.749959+00:00 |
70 | sJEha64nq3zDGijE | None | Research Medullary IgM. | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.750113+00:00 |
78 | TPIFTnCRu96FIiAI | None | Research result Medulla oblongata visualize IgG1. | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.754656+00:00 |
81 | uNGvTyG3hCkI0swB | None | Skin IgE research Medullary IgG Foveolar cell ... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.755113+00:00 |
And case-insensitive:
ln.Transform.filter(name__icontains="Search").df().head(10)
uid | version | name | key | description | type | reference | reference_type | latest_report_id | source_code_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||
7 | Bzy9ebSVn0Qa8Rbd | None | Research Vagina Foveolar cell investigate visu... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.740268+00:00 |
11 | 9qYEskyaofJ5YOEa | None | Visualize research Pineal gland Midbrain inves... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.740907+00:00 |
33 | bG1MAqUJ2D5TWpNJ | None | Iga research candidate efficiency IgG2 Foveola... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.744359+00:00 |
46 | KObvc4dLlRS7AYM6 | None | Research IgG1 Transitional epithelium IgM IgG4... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.746369+00:00 |
55 | 62rUxM02zijQysGx | None | Outer Root Sheath intestine research. | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.747785+00:00 |
56 | Swoq1oIqn9KYdoIT | None | Research Medullary Outer root sheath IgG4 clas... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.747946+00:00 |
69 | n1PncK4nDwa6BREr | None | Helper T Cell IgG2 candidate research research. | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.749959+00:00 |
70 | sJEha64nq3zDGijE | None | Research Medullary IgM. | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.750113+00:00 |
78 | TPIFTnCRu96FIiAI | None | Research result Medulla oblongata visualize IgG1. | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.754656+00:00 |
81 | uNGvTyG3hCkI0swB | None | Skin IgE research Medullary IgG Foveolar cell ... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.755113+00:00 |
startswith¶
ln.Transform.filter(name__startswith="Research").df()
uid | version | name | key | description | type | reference | reference_type | latest_report_id | source_code_id | created_by_id | updated_at | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||
7 | Bzy9ebSVn0Qa8Rbd | None | Research Vagina Foveolar cell investigate visu... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.740268+00:00 |
46 | KObvc4dLlRS7AYM6 | None | Research IgG1 Transitional epithelium IgM IgG4... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.746369+00:00 |
56 | Swoq1oIqn9KYdoIT | None | Research Medullary Outer root sheath IgG4 clas... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.747946+00:00 |
70 | sJEha64nq3zDGijE | None | Research Medullary IgM. | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.750113+00:00 |
78 | TPIFTnCRu96FIiAI | None | Research result Medulla oblongata visualize IgG1. | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.754656+00:00 |
110 | 7WK6LtTMLfNLAoJH | None | Research visualize IgM Midbrain IgG3 Midbrain ... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.759551+00:00 |
120 | D3xGpnFQkyhQlFVI | None | Research Skin Pineal gland study. | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.761024+00:00 |
169 | NXMqCsuItc6YOReh | None | Research Spermatocyte IgD Cementoblast Helper ... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.771042+00:00 |
214 | KZQnSYw9FVacDGkj | None | Research Pineal gland study IgG2 Medullary Tra... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.777707+00:00 |
225 | MBszcF3Dv2cC4Ouc | None | Research IgD Spermatocyte classify Medulla obl... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.779374+00:00 |
250 | FDsEeQsq6f3FKDUO | None | Research cluster efficiency Vagina Medullary e... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.785723+00:00 |
285 | W6TWfNGmqw36PY4e | None | Research IgG IgD IgG3 IgG4 IgG4. | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.790872+00:00 |
324 | TWfDDHrzyx1ig4xY | None | Research visualize IgG2 IgG4 classify Medulla ... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.799247+00:00 |
469 | 22gI3AKhiaezPUYu | None | Research Outer pillar cells of organ of Corti ... | None | None | notebook | None | None | None | None | 1 | 2024-06-13 12:06:19.899530+00:00 |
Show code cell content
# clean up test instance
!lamin delete --force mydata
!rm -r mydata
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.11.9/x64/bin/lamin", line 8, in <module>
sys.exit(main())
^^^^^^
File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/rich_click/rich_command.py", line 367, in __call__
return super().__call__(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/rich_click/rich_command.py", line 152, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/lamin_cli/__main__.py", line 103, in delete
return delete(instance, force=force)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/lamindb_setup/_delete.py", line 98, in delete
n_objects = check_storage_is_empty(
^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/lamindb_setup/core/upath.py", line 779, in check_storage_is_empty
raise InstanceNotEmpty(message)
lamindb_setup.core.upath.InstanceNotEmpty: Storage /home/runner/work/lamindb/lamindb/docs/mydata/.lamindb contains 3 objects ('_is_initialized' ignored) - delete them prior to deleting the instance
['/home/runner/work/lamindb/lamindb/docs/mydata/.lamindb/7oyPKlXi5foEtDV5gJdP.parquet', '/home/runner/work/lamindb/lamindb/docs/mydata/.lamindb/NrSxVowDV0zXfStQ1blW.fastq.gz', '/home/runner/work/lamindb/lamindb/docs/mydata/.lamindb/ZTvbFRQrhQeF2KDyXX2u.jpg', '/home/runner/work/lamindb/lamindb/docs/mydata/.lamindb/_is_initialized']