How to delete records?#

Registry records can be deleted with record.delete(), which will permanently remove them from your database.

When it comes to records of File 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, calling record.delete() triggers permanent delete.

  • During permanent deletion of a record, its artifact in storage is also deleted unless it has a semantic key.

Setup#

!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 get linked, consider calling ln.track()
Artifact(uid='YfpBRfcuc6wGA4Hx33wV', suffix='.parquet', accessor='DataFrame', description='mydf', size=2240, hash='QjcuNamb5uvb0Rs5iXRgeA', hash_type='md5', visibility=1, key_is_virtual=True, updated_at=2024-05-01 18:49:40 UTC, storage_id=1, created_by_id=1)
ln.Artifact.df()
uid storage_id key suffix accessor description version size hash hash_type n_objects n_observations transform_id run_id visibility key_is_virtual created_at updated_at created_by_id
id
1 YfpBRfcuc6wGA4Hx33wV 1 None .parquet DataFrame mydf None 2240 QjcuNamb5uvb0Rs5iXRgeA md5 None None None None 1 True 2024-05-01 18:49:40.673620+00:00 2024-05-01 18:49:40.673661+00:00 1

Trash an artifact#

artifact.delete()
❗ moved artifact to trash (visibility = -1)

No longer visible:

ln.Artifact.df()
uid key suffix accessor description version size hash hash_type n_objects n_observations visibility key_is_virtual created_at updated_at storage_id transform_id run_id created_by_id
id

But the artifact still exists in the database, you can find it by not filtering for visibility:

ln.Artifact.filter(visibility=None).df()
uid storage_id key suffix accessor description version size hash hash_type n_objects n_observations transform_id run_id visibility key_is_virtual created_at updated_at created_by_id
id
1 YfpBRfcuc6wGA4Hx33wV 1 None .parquet DataFrame mydf None 2240 QjcuNamb5uvb0Rs5iXRgeA md5 None None None None -1 True 2024-05-01 18:49:40.673620+00:00 2024-05-01 18:49:40.719084+00:00 1

You can restore an artifact from trash:

artifact.restore()
ln.Artifact.df()
uid storage_id key suffix accessor description version size hash hash_type n_objects n_observations transform_id run_id visibility key_is_virtual created_at updated_at created_by_id
id
1 YfpBRfcuc6wGA4Hx33wV 1 None .parquet DataFrame mydf None 2240 QjcuNamb5uvb0Rs5iXRgeA md5 None None None None 1 True 2024-05-01 18:49:40.673620+00:00 2024-05-01 18:49:40.769823+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 key suffix accessor description version size hash hash_type n_objects n_observations visibility key_is_virtual created_at updated_at storage_id transform_id run_id created_by_id
id