Transfer artifacts from a local instance to a cloud instanceΒΆ
import lamindb as ln
import bionty as bt
ln.connect("laminlabs/lamin-dev")
bt.settings.organism = "human"
Show code cell content
def cleanup(artifact: ln.Artifact):
features_sets = artifact.feature_sets.all()
experiments = artifact.experiments.all()
try:
artifact.delete(permanent=True)
except Exception:
pass
features_sets.delete()
experiments.delete()
artifacts = ln.Artifact.filter(description='test-transfer-to-cloud').all()
for artifact in artifacts:
cleanup(artifact)
β couldn't delete files outside of default storage
artifact = ln.Artifact.using("testuser1/test-transfer-to-cloud").filter(description='test-transfer-to-cloud').one()
artifact.describe()
Artifact(updated_at=2024-05-23 10:57:58 UTC, uid='qs55jggxaIbEuGE2k35D', suffix='.parquet', accessor='DataFrame', description='test-transfer-to-cloud', size=1654, hash='7D9KyOpePOAwibz6Hl6V4A', hash_type='md5', visibility=1, key_is_virtual=True)
Provenance:
π created_by: User(uid='DzTjkKse', handle='testuser1', name='Test User1')
π storage: uid='VsDWRXhI5XAj', root='/home/runner/work/lamindb/lamindb/docs/storage/test-transfer-to-cloud', type='local', instance_uid='5rYQ1DZky2qU')
Features:
var: FeatureSet(uid='TMLdjgU7TFvTMCqzBfUt', n=2, dtype='number', registry='bionty.CellMarker')
'PD1', 'CD21'
Labels:
π organisms (1, bionty.Organism): 'human'
π experiments (1, wetlab.Experiment): 'experiment-test-transfer-to-cloud'
artifact.save()
β no run & transform get linked, consider calling ln.track()
var
Artifact(updated_at=2024-05-23 10:58:04 UTC, uid='qs55jggxaIbEuGE2k35D', suffix='.parquet', accessor='DataFrame', description='test-transfer-to-cloud', size=1654, hash='7D9KyOpePOAwibz6Hl6V4A', hash_type='md5', visibility=1, key_is_virtual=True, created_by_id=2, storage_id=3)
artifact.describe()
Artifact(updated_at=2024-05-23 10:58:04 UTC, uid='qs55jggxaIbEuGE2k35D', suffix='.parquet', accessor='DataFrame', description='test-transfer-to-cloud', size=1654, hash='7D9KyOpePOAwibz6Hl6V4A', hash_type='md5', visibility=1, key_is_virtual=True)
Provenance:
π created_by: User(uid='DzTjkKse', handle='testuser1', name='Test User1')
π storage: uid='6m3EoLzL', root='/home/runner/work/lamindb/lamindb/docs/storage/test-transfer-to-cloud', type='local')
Features:
var: FeatureSet(uid='TMLdjgU7TFvTMCqzBfUt', n=2, dtype='number', registry='bionty.CellMarker')
'CD21', 'PD1'
Labels:
π organisms (1, bionty.Organism): 'human'
π experiments (1, wetlab.Experiment): 'experiment-test-transfer-to-cloud'
assert artifact._state.db == "default"
assert artifact.organisms.get().name == "human"
assert artifact.experiments.get().name == "experiment-test-transfer-to-cloud"
assert artifact.features["var"].count() == 2
!lamin delete --force test-transfer-to-cloud
!rm -r ./test-transfer-to-cloud
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.9.19/x64/bin/lamin", line 8, in <module>
sys.exit(main())
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/rich_click/rich_command.py", line 367, in __call__
return super().__call__(*args, **kwargs)
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/click/core.py", line 1157, in __call__
return self.main(*args, **kwargs)
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/rich_click/rich_command.py", line 152, in main
rv = self.invoke(ctx)
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/lamin_cli/__main__.py", line 103, in delete
return delete(instance, force=force)
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/lamindb_setup/_delete.py", line 98, in delete
n_objects = check_storage_is_empty(
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/site-packages/lamindb_setup/core/upath.py", line 760, in check_storage_is_empty
raise InstanceNotEmpty(message)
lamindb_setup.core.upath.InstanceNotEmpty: Storage /home/runner/work/lamindb/lamindb/docs/storage/test-transfer-to-cloud/.lamindb contains 1 objects ('_is_initialized' ignored) - delete them prior to deleting the instance
['/home/runner/work/lamindb/lamindb/docs/storage/test-transfer-to-cloud/.lamindb/_is_initialized', '/home/runner/work/lamindb/lamindb/docs/storage/test-transfer-to-cloud/.lamindb/qs55jggxaIbEuGE2k35D.parquet']