What happens when importing lamindb and the instance is not yet setup?

Hide 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.

Hide 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")
→ notebook imports: lamindb==0.76.15 lamindb_setup==0.80.1 pytest==8.3.3
→ created Transform('2lhqA4uT'), started new Run('VaKXixUC') at 2024-11-07 12:43:43 UTC

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