## "lamindb_setup" [image: .md][image]

Setup & configure LaminDB.

Guide: Install & setup.

# Modules and classes

| --- | --- |
| "evolve" | Manage schema evolutions for datasets. |
| --- | --- |
| "migrate" | Manage migrations of the SQL database. |
| () |
| --- | --- |
| "settings" | Global "SetupSettings". |
| --- | --- |
| "errors" | Errors. |
| --- | --- |
| "types" | Types. |
| --- | --- |
| "django"( | Call Django commands. |
| command[, |
| package_n |
| ame]) |
| --- | --- |
| "core" | Core library. |
| --- | --- |

* lamindb_setup.evolve

  * Plans

 * Plans

 * Define a plan

 * "create_plan()"

 * "Plan"

 * "Plan.defining_module"

 * "Plan.ctx"

 * "Plan.exports"

 * "Plan.dependencies"

 * "Plan.own_dependencies"

 * "Plan.inherited_dependencies"

 * "Plan.inherited_moves"

 * "Plan.depends_on"

 * "Plan.active()"

 * "Plan.run()"

 * "Plan.add_dependency()"

 * "Plan.add_plan_dependency()"

 * "Plan.finalize()"

 * "Plan.reset()"

 * "PlanContext"

 * "PlanContext.migrations"

 * "PlanContext.moves"

 * "PlanContext.migrate()"

 * "PlanContext.moved()"

 * "PlanExports"

 * "PlanDeclarationError"

 * Plan result types

 * "SpaceUID"

 * "SpaceUID.registry_name"

 * "FeatureUID"

 * "FeatureUID.registry_name"

 * "RecordUID"

 * "RecordUID.registry_name"

 * "SchemaUID"

 * "SchemaUID.registry_name"

 * "Promise"

 * "Promise.label"

 * "Promise.resolve()"

 * "Promise.get_arg()"

 * "Dependency"

 * "DependencyDAG"

 * "DependencyDAG.ordered()"

 * "Moved"

 * "Migrated"

 * "WriteStrategy"

 * "WriteStrategy.BATCHED_LINKS"

 * "WriteStrategy.ADD_VALUES"

  * Declarations

 * Declarations

 * Features

 * "FeatureType"

 * "FeatureType.uid"

 * "FeatureType.get()"

 * "FeatureType.stage()"

 * "Feature"

 * "Feature.uid"

 * "Feature.get()"

 * "Feature.stage()"

 * Schemas

 * "SchemaType"

 * "SchemaType.uid"

 * "SchemaType.get()"

 * "SchemaType.stage()"

 * "Schema"

 * "Schema.itype"

 * "Schema.dtype"

 * "Schema.uid"

 * "Schema.get()"

 * "Schema.stage()"

 * Records and sheets

 * "RecordType"

 * "RecordType.uid"

 * "RecordType.get()"

 * "RecordType.stage()"

 * "Sheet"

 * "Sheet.stage()"

 * "Record"

 * "Record.uid"

 * "Record.get()"

 * "Record.stage()"

  * Typed models and dtypes

 * Typed models and dtypes

 * Schema models

 * "SchemaModel"

 * "SchemaConfig"

 * Feature dtypes

 * "LaminDType"

 * "LaminDType.dtype"

 * "LaminDType.dtype_str"

 * "DType"

 * "ListDType"

 * "CatDType"

 * "DEFAULT_NAME_FIELD"

 * "RecordCat"

 * "RecordCat.name_field"

 * "RecordCat.schema__uid"

 * "RecordCat.is_type"

 * "ULabelCat"

 * "ULabelCat.name_field"

 * "ULabelCat.type__uid"

 * "ResolvedDType"

 * "ResolvedDType.dtype_str"

 * "get_dtype()"

 * "inline_cat_filters()"

 * Field declarations

 * "feature()"

  * Data migrations

 * Data migrations

 * Migration types

 * "DataMigration"

 * "DataMigration.targets"

 * "DataMigration.run()"

 * "MigrationReport"

 * "MigrationReport.kept"

 * "MigrationReport.matched"

 * "MigrationReport.mapped"

 * "MigrationReport.transformed"

 * "MigrationReport.nulled"

 * "MigrationReport.dropped"

 * "MigrationReport.updated"

 * "MigrationReport.relocated"

 * "MigrationReport.write_strategy"

 * "MigrationReport.note()"

 * "MigrationReport.summary()"

 * "MigrationError"

 * Fill and map values

 * "fill_nulls()"

 * "fill_missing()"

 * "map_values()"

 * "map_to_records()"

 * "map_to_str()"

 * Remove and revalidate data

 * "drop_values()"

 * "drop_rows()"

 * "revalidate_against()"

 * "revalidate_rows()"

 * "reexport_sheets()"

 * Accept schema changes

 * "accept_non_null()"

 * "accept_index_change()"

 * "accept_flexible_change()"

 * Handle existing metadata

 * "drop_member_values()"

 * "keep_member_values()"

 * "drop_nonmember_annotations()"

 * "keep_stale_exports()"

 * "keep_values()"

 * "keep_validated()"

 * "keep_rows()"

 * Migrate records

 * "move_rows()"

 * "adopt_children()"

 * "update_record()"

 * "drop_record()"

 * Fill values

 * "NULL"

 * "DEFAULT"

  * Custom migrations

 * Custom migrations

 * Migration contexts

 * "MigrationContext"

 * "MigrationContext.target_registry"

 * "MigrationContext.cat_filters"

 * "DeclarationTarget"

 * "DeclarationTarget.by_key"

 * "DeclarationTarget.describe()"

 * "MemberMigrationContext"

 * "MemberMigrationContext.accept_null()"

 * "MemberMigrationContext.missing()"

 * "MemberRemovalContext"

 * "MemberRemovalContext.keep()"

 * "MemberRemovalContext.carrying()"

 * "IndexChangeContext"

 * "FlexibleChangeContext"

 * "FlexibleChangeContext.nonmember_columns()"

 * "FeatureRemovalContext"

 * "RecordTypeRemovalContext"

 * "RecordTypeRemovalContext.rows()"

 * "SchemaRemovalContext"

 * "SheetExportContext"

 * "SheetExportContext.branch_factory"

 * "SheetExportContext.branch"

 * "SheetExportContext.write()"

 * "RecordUpdateContext"

 * "RecordRemovalContext"

 * "RecordRemovalContext.relocate_to"

 * "RecordRemovalContext.links()"

 * Migration helpers

 * "backfill_members()"

 * "clear_values()"

 * "clear_member_values()"

 * "clear_nonmember_annotations()"

 * "relocate_to_records()"

 * "relocate_to_str()"

 * "rewrite_values()"

  * Plan result types

  * Environment variables

* lamindb_setup.migrate

  * "migrate"

 * "migrate.create()"

 * "migrate.deploy()"

 * "migrate.squash()"

 * "migrate.show()"

 * "migrate.defined_migrations()"

 * "migrate.deployed_migrations()"

* lamindb_setup.settings

  * "settings"

* lamindb_setup.errors

  * "CurrentInstanceNotConfigured"

  * "ModuleWasntConfigured"

  * "StorageAlreadyManaged"

  * "StorageNotEmpty"

  * "InstanceLockedException"

  * "SettingsEnvFileOutdated"

  * "CannotSwitchDefaultInstance"

  * "InstanceNotFoundError"

  * "InstanceNotCreated"

  * "NoAccessTokenError"

  * "NoWriteAccess"

  * "NoReadAccess"

  * "ConnectWithinDevDirError"

  * "ApiKeyError"

  * "ApiKeyExpired"

  * "ApiKeyNotFound"

* lamindb_setup.types

  * "AnyPathStr"

  * "StorageType"

* lamindb_setup.django

  * "django()"

* lamindb_setup.core

  * Settings

 * "SetupSettings"

 * "SetupSettings.modules_warning"

 * "SetupSettings.modules"

 * "SetupSettings.settings_dir"

 * "SetupSettings.auto_connect"

 * "SetupSettings.dev_dir"

 * "SetupSettings.branch"

 * "SetupSettings.space"

 * "SetupSettings.is_connected"

 * "SetupSettings.is_configured"

 * "SetupSettings.private_django_api"

 * "SetupSettings.user"

 * "SetupSettings.instance"

 * "SetupSettings.storage"

 * "SetupSettings.cache_dir"

 * "SetupSettings.paths"

 * "SetupSettings.get_configured_space()"

 * "UserSettings"

 * "UserSettings.handle"

 * "UserSettings.email"

 * "UserSettings.api_key"

 * "UserSettings.password"

 * "UserSettings.access_token"

 * "UserSettings.uid"

 * "UserSettings.name"

 * "UserSettings.id"

 * "InstanceSettings"

 * "InstanceSettings.owner"

 * "InstanceSettings.name"

 * "InstanceSettings.keep_artifacts_local"

 * "InstanceSettings.storage"

 * "InstanceSettings.local_storage"

 * "InstanceSettings.slug"

 * "InstanceSettings.git_repo"

 * "InstanceSettings.api_url"

 * "InstanceSettings.ui_url"

 * "InstanceSettings.is_read_only_connection"

 * "InstanceSettings.available_spaces"

 * "InstanceSettings.uid"

 * "InstanceSettings.modules"

 * "InstanceSettings.db"

 * "InstanceSettings.dialect"

 * "InstanceSettings.vendor"

 * "InstanceSettings.is_remote"

 * "InstanceSettings.is_on_hub"

 * "InstanceSettings.is_managed_by_hub"

 * "StorageSettings"

 * "StorageSettings.uid"

 * "StorageSettings.instance_uid"

 * "StorageSettings.record"

 * "StorageSettings.hub_record"

 * "StorageSettings.root"

 * "StorageSettings.root_as_str"

 * "StorageSettings.cache_dir"

 * "StorageSettings.type_is_cloud"

 * "StorageSettings.host"

 * "StorageSettings.region"

 * "StorageSettings.type"

 * "StorageSettings.is_on_hub"

 * "StorageSettings.cloud_to_local()"

 * "StorageSettings.cloud_to_local_no_update()"

 * "StorageSettings.key_to_filepath()"

 * "StorageSettings.local_filepath()"

# Basic operations

lamindb_setup.login(user=None, *, api_key=None, **kwargs)

 Log into the hub.

 "login()" prompts for your API key unless you set it via the
 "LAMIN_API_KEY" environment variable or pass it as an argument.

 You can create your API key in your hub account settings at
 lamin.ai/settings.

 Note that the preferred method is to use the CLI command "lamin
 login": docs.lamin.ai/cli#login.

 Parameters:
| * **user** ("str" | "None", default: "None") -- User handle. |

| * **api_key** ("str" | "None", default: "None") -- API key. |

 Return type:
 "UserSettings"

 -[ Examples ]-

 Logging in the first time:

 import lamindb as ln

 ln.setup.login()  # prompts for API key

 After authenticating multiple users, you can switch between user
 profiles:

 ln.setup.login("myhandle")  # pass your user handle

lamindb_setup.logout()

 Log out the current user.

 This deletes the "~/.lamin/current_user.env" so that you'll no
 longer be automatically authenticated in the environment.

 It keeps a copy as "~/.lamin/user--<user_handle>.env" so you can
 easily switch between user profiles.

 See also: Logout via the CLI command "lamin logout", see here.

lamindb_setup.init(*, storage='./storage', name=None, db=None, modules=None, **kwargs)

 Init a LaminDB instance.

 Parameters:
 * **storage** (lamindb.base.types.AnyPathStr, default:
 "'./storage'") -- A local or remote folder ("'s3://...'" or
 "'gs://...'"). Defaults to "./storage".

| * **name** ("str" | "None", default: "None") -- Instance name. |
 If no storage location is passed, uses the current working
 directory name (like git). Otherwise uses the name of the
 storage location.

| * **db** ("PostgresDsn" | "None", default: "None") -- PostgreSQL |
 connection URI. Defaults to "None", which implies an SQLite
 file in the storage location.

| * **modules** ("str" | "None", default: "None") -- Comma- |
 separated string of schema modules.

 * ****kwargs** -- Keyword arguments for low-level control.

 Return type:
 "None"

 See also: Init an instance via the CLI, see here.

lamindb_setup.disconnect(mute=False, here=False)

 Clear default instance configuration.

 Returns "None" if succeeds, otherwise an exception is raised.

 Parameters:
 * **mute** ("bool", default: "False") -- If "True", mute logging
 output.

 * **here** ("bool", default: "False") -- If "True", disconnect
 local directory context by removing the nearest local marker
 and unsetting the mapped dev-dir.

 Return type:
 "None"

 See also:

 Clear default instance configuration via the CLI, see here.

lamindb_setup.delete(slug, force=False, require_empty=True)

 Delete a LaminDB instance.

 Parameters:
 * **slug** ("str") -- The instance slug
 "account_handle/instance_name" or URL. If the instance is
 owned by you, it suffices to pass the instance name.

 * **force** ("bool", default: "False") -- Whether to skip the
 confirmation prompt.

 * **require_empty** ("bool", default: "True") -- Whether to
 check if the instance is empty before deleting.

 Return type:
| "int" | "None" |

 See also: Delete an instance via the CLI, see here.

# Branching

lamindb_setup.switch(target, *, space=False, create=False)

 Switch to a branch or space, create if not exists.

 Parameters:
| * **target** (str | Branch) -- Branch target or space target to |
 switch to.

 * **space** (bool, default: "False") -- If True, switch space;
 otherwise switch branch.

 * **create** (bool, default: "False") -- If True and switching
 branch, create the branch if it does not exist.

lamindb_setup.merge(branch, *, target=None)

 Merge a source branch into a target branch.

 Return type:
 None