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

Hide code cell content
!lamin close
💡 no instance loaded
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.settings.transform.stem_uid = "2lhqA4uTKSFP"
ln.settings.transform.version = "0"
ln.track()
💡 notebook imports: lamindb==0.71.0 pytest==8.2.0
💡 saved: Transform(uid='2lhqA4uTKSFP6K79', name='What happens when importing lamindb and the instance is not yet setup?', key='setup', version='0', type='notebook', updated_at=2024-05-01 18:51:03 UTC, created_by_id=1)
💡 saved: Run(uid='YH26hmXMjIFgyRyrozyS', transform_id=1, created_by_id=1)

Let us try to init another instance in the same Python session: It doesn’t work.

with pytest.raises(RuntimeError):
    ln.setup.init(storage="./testsetup2")
!lamin delete --force testsetup
💡 deleting instance testuser1/testsetup
💡 not deleting instance from hub as instance not found there