How to delete records?¶
Records can be deleted with record.delete()
, which will permanently remove them from your database.
When it comes to records of Artifact
and Collection
, they are “moved into trash” when you first call record.delete()
.
Trashed records are invisible in the UI and excluded from the query results, see visibility faq.
If a record is already in the trash or
permanent=True
is passed, callingrecord.delete()
triggers permanent delete.
# !pip install lamindb
!lamin init --storage test-delete
→ connected lamindb: testuser1/test-delete
import lamindb as ln
import pandas as pd
→ connected lamindb: testuser1/test-delete
artifact = ln.Artifact.from_df(
pd.DataFrame({"a": [1, 2], "b": [3, 4]}), description="mydf"
)
artifact.save()
! no run & transform got linked, call `ln.track()` & re-run
Artifact(uid='g4QLedwVafMqZO9x0000', is_latest=True, description='mydf', suffix='.parquet', type='dataset', size=2054, hash='HesrmwkODFQaQpPQYsXffg', _hash_type='md5', _accessor='DataFrame', visibility=1, _key_is_virtual=True, storage_id=1, created_by_id=1, created_at=2024-12-20 15:03:24 UTC)
ln.Artifact.df()
uid | key | description | suffix | type | size | hash | n_objects | n_observations | _hash_type | _accessor | visibility | _key_is_virtual | storage_id | transform_id | version | is_latest | run_id | created_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||||||||
1 | g4QLedwVafMqZO9x0000 | None | mydf | .parquet | dataset | 2054 | HesrmwkODFQaQpPQYsXffg | None | None | md5 | DataFrame | 1 | True | 1 | None | None | True | None | 2024-12-20 15:03:24.015428+00:00 | 1 |
Trash an artifact¶
artifact.delete()
→ moved artifact to trash (visibility = -1)
No longer visible:
ln.Artifact.df()
uid | id | key | description | suffix | type | size | hash | n_objects | n_observations | _hash_type | _accessor | visibility | _key_is_virtual | storage_id | transform_id | version | is_latest | run_id | created_at | created_by_id |
---|
But the artifact still exists in the database and in storage, you can find it by passing None
to the visibility filter:
ln.Artifact.filter(visibility=None).df()
uid | key | description | suffix | type | size | hash | n_objects | n_observations | _hash_type | _accessor | visibility | _key_is_virtual | storage_id | transform_id | version | is_latest | run_id | created_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||||||||
1 | g4QLedwVafMqZO9x0000 | None | mydf | .parquet | dataset | 2054 | HesrmwkODFQaQpPQYsXffg | None | None | md5 | DataFrame | -1 | True | 1 | None | None | True | None | 2024-12-20 15:03:24.015428+00:00 | 1 |
You can restore an artifact from trash:
artifact.restore()
ln.Artifact.df()
uid | key | description | suffix | type | size | hash | n_objects | n_observations | _hash_type | _accessor | visibility | _key_is_virtual | storage_id | transform_id | version | is_latest | run_id | created_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||||||||
1 | g4QLedwVafMqZO9x0000 | None | mydf | .parquet | dataset | 2054 | HesrmwkODFQaQpPQYsXffg | None | None | md5 | DataFrame | 1 | True | 1 | None | None | True | None | 2024-12-20 15:03:24.015428+00:00 | 1 |
ln.Storage.df()
uid | root | description | type | region | instance_uid | run_id | created_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|
id | |||||||||
1 | 3haAi2B7iNOa | /home/runner/work/lamindb/lamindb/docs/faq/tes... | None | local | None | 4Kf3utIIfnlJ | None | 2024-12-20 15:03:20.383108+00:00 | 1 |
Permanent delete¶
Calling artifact.delete
on a trashed artifact triggers a permanent delete dialog. You can pass permanent=True
to auto-confirm the deletion.
artifact.delete(permanent=True)
Now its gone in the database:
ln.Artifact.filter(visibility=None).df()
uid | id | key | description | suffix | type | size | hash | n_objects | n_observations | _hash_type | _accessor | visibility | _key_is_virtual | storage_id | transform_id | version | is_latest | run_id | created_at | created_by_id |
---|
!lamin delete --force test-delete
• deleting instance testuser1/test-delete