Load & close an instance#
Show code cell content
!lamin close
β
Closed testuser1/mydata
import lamindb as ln
πΆ You haven't yet setup an instance using the CLI: Please call `ln.setup.init()` or `ln.setup.load()`
Load your own instance by name#
If the user is the instance owner, just load the instance by name:
ln.setup.load("mydata") # CLI: lamin load mydata
π¬ Found cached instance metadata: /home/runner/.lamin/testuser1-instance-mydata.env
β
Loaded instance: testuser1/mydata
'migrate-unnecessary'
Show code cell content
from pathlib import Path
assert ln.setup.settings.instance.storage.is_cloud == False
assert ln.setup.settings.instance.name == "mydata"
assert (
ln.setup.settings.instance.storage.root.as_posix()
== Path("./mydata").resolve().as_posix()
)
assert ln.setup.settings.instance.storage.cache_dir is None
assert (
ln.setup.settings.instance.db
== f"sqlite:///{Path('./mydata').resolve().as_posix()}/mydata.lndb"
)
Show code cell content
import pytest
# assume we move the storage location
!mv mydata mydata_new_loc
with pytest.raises(
RuntimeError
): # triggers because it does not find the SQLite file anymore
ln.setup.load("mydata")
# now account for the new storage location
ln.setup.load("mydata", storage="./mydata_new_loc")
assert (
ln.setup.settings.instance.storage.root.as_posix()
== Path("./mydata_new_loc").resolve().as_posix()
)
assert ln.setup.settings.instance.storage.cache_dir is None
assert (
ln.setup.settings.instance.db
== f"sqlite:///{Path('./mydata_new_loc').resolve().as_posix()}/mydata.lndb"
)
π¬ Found cached instance metadata: /home/runner/.lamin/testuser1-instance-mydata.env
πΆ SQLite file /home/runner/work/lndb/lndb/docs/guide/mydata/mydata.lndb does not exist
π¬ Found cached instance metadata: /home/runner/.lamin/testuser1-instance-mydata.env
β
Updated storage root j9nEHTlN to /home/runner/work/lndb/lndb/docs/guide/mydata_new_loc
β
Loaded instance: testuser1/mydata
This also works for remote instances:
Show code cell content
# ensure that the locally cached env file is deleted
from lndb.dev._settings_store import instance_settings_file
instance_settings_file("lndb-setup-ci", "testuser1").unlink()
ln.setup.load("lndb-setup-ci") # lamin load lndb-setup-ci
2023-05-30 15:19:56,631:INFO - Found credentials in environment variables.
β
Loaded instance: testuser1/lndb-setup-ci
'migrate-unnecessary'
Show code cell content
assert ln.setup.settings.instance.storage.is_cloud == True
assert ln.setup.settings.instance.storage.root_as_str == "s3://lndb-setup-ci"
assert (
ln.setup.settings.instance._sqlite_file.as_posix()
== "s3://lndb-setup-ci/lndb-setup-ci.lndb"
)
Load an instance from another owner#
If you have the permission, you can load an instance from another owner.
ln.setup.load("testuser1/mydata") # lamin load "testuser1/mydata"
π¬ Found cached instance metadata: /home/runner/.lamin/testuser1-instance-mydata.env
β
Loaded instance: testuser1/mydata
'migrate-unnecessary'
Load an instance from wrong owner.
assert ln.setup.load("testuser2/mydata") == "instance-not-reachable"
β Instance testuser2/mydata neither loadable from hub nor local cache. Check whether instance exists and you have access: https://lamin.ai/testuser2/mydata?tab=collaborators
Close an instance#
ln.setup.close()
β
Closed testuser1/mydata