What happens when importing lamindb and the instance is not yet setup?¶
Show code cell content
!lamin disconnect
• no instance loaded
# !pip install 'lamindb[jupyter]'
import lamindb as ln
import pytest
! To use lamindb, you need to connect to an instance.
Connect to an instance: `ln.connect()`. Init an instance: `ln.setup.init()`.
If you used the CLI to set up lamindb in a notebook, restart the Python session.
If you try to use lamindb, it will raise an InstanceNotSetupError
and ask you to init
or load
an instance via the python API.
Show code cell content
with pytest.raises(ln._InstanceNotSetupError):
ln.track()
ln.setup.init(storage="./testsetup")
→ connected lamindb: testuser1/testsetup
Now we can access functionality:
ln.track("2lhqA4uTKSFP0000")
→ created Transform('2lhqA4uT'), started new Run('ibqtswbm') at 2024-11-21 05:40:27 UTC
→ notebook imports: lamindb==0.76.16 lamindb_setup==0.81.1 pytest==8.3.3
Let us try to init another instance in the same Python session: It doesn’t work.
from lamindb_setup._init_instance import CannotSwitchDefaultInstance
with pytest.raises(CannotSwitchDefaultInstance):
ln.setup.init(storage="./testsetup2")
!lamin delete --force testsetup
• deleting instance testuser1/testsetup