Init on-prem instance#
Show code cell content
!lamin login testuser1
import lamindb_setup as ln_setup
Local database & storage#
SQLite#
ln_setup.init(storage="./mydata")
This automatically assigns an instance name that equals the name of the storage root along with a few other settings:
ln_setup.settings.instance
If you want to register the instance on the hub at lamin.ai, use lamindb_setup.register()
.
Show code cell content
from pathlib import Path
assert ln_setup.settings.instance.storage.is_cloud == False
assert ln_setup.settings.instance.owner == ln_setup.settings.user.handle
assert ln_setup.settings.instance.name == "mydata"
assert ln_setup.settings.storage.root.as_posix() == Path("mydata").resolve().as_posix()
assert ln_setup.settings.storage.id is not None
assert (
ln_setup.settings.instance.db
== f"sqlite:///{Path('./mydata').resolve().as_posix()}/{ln_setup.settings.instance.id.hex}.lndb"
)
See the info on the current instance & user:
ln_setup.info() # CLI: lamin info
To delete an instance, call:
ln_setup.delete("mydata", force=True)
Show code cell content
from lamindb_setup.dev._settings_store import instance_settings_file
settings_file = instance_settings_file("mydata", "testuser1")
assert settings_file.exists() == False
Postgres#
from laminci.db import setup_local_test_postgres
pgurl = setup_local_test_postgres()
A connection string for postgres looks like this:
'postgresql://postgres:pwd@0.0.0.0:5432/pgtest'
You can call init like so:
ln_setup.init(storage="./mydatapg", db='postgresql://postgres:pwd@0.0.0.0:5432/pgtest') # CLI: lamin init --storage ./mystorage --db 'postgresql://postgres:pwd@0.0.0.0:5432/pgtest'
Your instance name will then be pgtest
!
Custom instance name#
Instead of having the instance name be auto-determined from storage
or db
, you can provide a custom name:
ln_setup.init(
storage="./mystorage", name="mydata2", db=pgurl
) # CLI: lamin init --storage ./mystorage --name "mydata" --db ...
Configure with default cloud storage#
AWS#
You need to have access to AWS S3 (run pip instsall awscli
and aws configure
).
Consider the special case of a cloud SQLite instance:
ln_setup.init(
storage="s3://lamindb-ci/mydata"
) # CLI: lamin init --storage "s3://lamindb-ci/mydata"
Under the hood LaminDB then keeps track of a cloud & and a synched local SQLite file.
# you can inspect these:
ln_setup.settings.instance._sqlite_file
ln_setup.settings.instance._sqlite_file_local
GCP#
You need to authenticate for Google Cloud.
Either, set the environment variable
export GOOGLE_APPLICATION_CREDENTIALS=<HOME-DIR>/.lndb/<GOOGLE CLOUD PROJECT>.json
.Alternatively, if you set up the
gcloud
CLI, log in withgcloud auth application-default login
.
ln_setup.init(storage="gs://lamindb-ci-us") # CLI: lamin init --storage "gs://lamindb-ci-us"