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 Dataset, 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 file in storage is also deleted unless it has a semantic key.

Setup#

!lamin init --storage test-delete
✅ saved: User(uid='DzTjkKse', handle='testuser1', name='Test User1', updated_at=2023-12-08 11:32:56 UTC)
✅ saved: Storage(uid='owCZndl3', root='/home/runner/work/lamindb/lamindb/docs/faq/test-delete', type='local', updated_at=2023-12-08 11:32:56 UTC, created_by_id=1)
💡 loaded instance: testuser1/test-delete
💡 did not register local instance on hub

import lamindb as ln
import pandas as pd
💡 lamindb instance: testuser1/test-delete
file = ln.File(pd.DataFrame({"a": [1, 2], "b": [3, 4]}), description="mydf")
file.save()
❗ no run & transform get linked, consider passing a `run` or calling ln.track()
ln.File.filter().df()
uid storage_id key suffix accessor description version size hash hash_type transform_id run_id initial_version_id visibility key_is_virtual updated_at created_by_id
id
1 heBmDcUZSbbsRR6dMz2r 1 None .parquet DataFrame mydf None 2240 AdqYk9VZLVMTdfmjwkra9A md5 None None None 1 True 2023-12-08 11:32:58.003084+00:00 1

Trash a file#

file.delete()
❗ moved file to trash

No longer visible:

ln.File.filter().df()
uid key suffix accessor description version size hash hash_type visibility key_is_virtual updated_at storage_id transform_id run_id initial_version_id created_by_id
id

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

ln.File.filter(visibility=None).df()
uid storage_id key suffix accessor description version size hash hash_type transform_id run_id initial_version_id visibility key_is_virtual updated_at created_by_id
id
1 heBmDcUZSbbsRR6dMz2r 1 None .parquet DataFrame mydf None 2240 AdqYk9VZLVMTdfmjwkra9A md5 None None None -1 True 2023-12-08 11:32:58.040169+00:00 1

You can restore a file from trash:

file.restore()
ln.File.filter().df()
uid storage_id key suffix accessor description version size hash hash_type transform_id run_id initial_version_id visibility key_is_virtual updated_at created_by_id
id
1 heBmDcUZSbbsRR6dMz2r 1 None .parquet DataFrame mydf None 2240 AdqYk9VZLVMTdfmjwkra9A md5 None None None 1 True 2023-12-08 11:32:58.088727+00:00 1

Permanent delete#

Calling file.delete on a trashed file triggers a permanent delete dialog. You can pass permanent=True to auto-confirm the deletion.

file.delete(permanent=True)

Now its gone in the database:

ln.File.filter(visibility=None).df()
uid key suffix accessor description version size hash hash_type visibility key_is_virtual updated_at storage_id transform_id run_id initial_version_id created_by_id
id