Load & close an instance#

Hide code cell content
!lamin close
!yes | lamin delete mydata
!lamin init --storage mydata
!rm -r ./mydata_new_loc
!mv mydata ./mydata_new_loc
!lamin close
import lamindb_setup as ln_setup

Load your own instance by name#

If the user is the instance owner, load the instance by name:

ln_setup.load("mydata")  # CLI: lamin load mydata

You can also load with a new default storage location:

ln_setup.load(
    "mydata", storage="./mydata_new_loc"
)  # CLI: lamin load mydata --storage ./mydata_new_loc
Hide 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_new_loc").resolve().as_posix()
)
assert (
    ln_setup.settings.instance.db
    == f"sqlite:///{Path('./mydata_new_loc').resolve().as_posix()}/{ln_setup.settings.instance.id.hex}.lndb"
)

Load an instance from another account#

If you have the permission, you can load an instance from another owner:

ln_setup.load("<owner>/<instance_name>")  # lamin load <owner>/<instance_name>

If there is a typo, or you get the account wrong, an error will be raised:

import pytest

with pytest.raises(RuntimeError):
    ln_setup.load("testuser2/mydata")

Close an instance#

ln_setup.close()
!yes | lamin delete mydata