How to delete records?¶
SQLRecords 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
→ initialized lamindb: testuser1/test-delete
import lamindb as ln
import pandas as pd
→ connected lamindb: testuser1/test-delete
artifact = ln.Artifact.from_dataframe(
pd.DataFrame({"a": [1, 2], "b": [3, 4]}), description="mydf"
)
artifact.save()
! creating spaces manually on sqlite databases is possible for demo purposes, but does *not* affect access permissions
! creating spaces manually on sqlite databases is possible for demo purposes, but does *not* affect access permissions
! no run & transform got linked, call `ln.track()` & re-run
Artifact(uid='EZAPr7jsI0GNs4si0000', is_latest=True, description='mydf', suffix='.parquet', kind='dataset', otype='DataFrame', size=2068, hash='vIComCdSf8v4UQirJDcJcg', n_observations=2, branch_id=1, space_id=1, storage_id=1, created_by_id=1, created_at=2025-09-07 19:25:41 UTC)
ln.Artifact.to_dataframe()
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_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||||||||||||
1 | EZAPr7jsI0GNs4si0000 | None | mydf | .parquet | dataset | DataFrame | 2068 | vIComCdSf8v4UQirJDcJcg | None | 2 | md5 | True | False | 1 | 1 | None | None | True | None | 2025-09-07 19:25:41.856000+00:00 | 1 | {'af': {'0': True}} | 1 |
Trash an artifact¶
artifact.delete()
! creating spaces manually on sqlite databases is possible for demo purposes, but does *not* affect access permissions
! moved record to trash (`branch_id = -1`): Artifact(uid='EZAPr7jsI0GNs4si0000', is_latest=True, description='mydf', suffix='.parquet', kind='dataset', otype='DataFrame', size=2068, hash='vIComCdSf8v4UQirJDcJcg', n_observations=2, branch_id=-1, space_id=1, storage_id=1, created_by_id=1, created_at=2025-09-07 19:25:41 UTC)
No longer visible:
ln.Artifact.to_dataframe()
uid | id | 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_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).to_dataframe()
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_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||||||||||||
1 | EZAPr7jsI0GNs4si0000 | None | mydf | .parquet | dataset | DataFrame | 2068 | vIComCdSf8v4UQirJDcJcg | None | 2 | md5 | True | False | 1 | 1 | None | None | True | None | 2025-09-07 19:25:41.856000+00:00 | 1 | {'af': {'0': True}} | -1 |
You can restore an artifact from trash:
artifact.restore()
ln.Artifact.to_dataframe()
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_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||||||||||||
1 | EZAPr7jsI0GNs4si0000 | None | mydf | .parquet | dataset | DataFrame | 2068 | vIComCdSf8v4UQirJDcJcg | None | 2 | md5 | True | False | 1 | 1 | None | None | True | None | 2025-09-07 19:25:41.856000+00:00 | 1 | {'af': {'0': True}} | 1 |
ln.Storage.to_dataframe()
uid | root | description | type | region | instance_uid | space_id | run_id | created_at | created_by_id | _aux | branch_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||
1 | Fe7okodFrxwh | /home/runner/work/lamindb/lamindb/docs/faq/tes... | None | local | None | 4Kf3utIIfnlJ | 1 | None | 2025-09-07 19:25:39.432000+00:00 | 1 | None | 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).to_dataframe()
uid | id | 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_id |
---|
!lamin delete --force test-delete
• deleting instance testuser1/test-delete