lamindb.core.storage .md

Storage API.

Array accessors

class lamindb.core.storage.AnnDataAccessor(connection, storage, filename, artifact=None)

Cloud-backed AnnData.

property closed
close()

Closes the connection.

add_column(where, col_name, col)

Add a new column to .obs or .var of the underlying AnnData object.

class lamindb.core.storage.SpatialDataAccessor(storage, name, artifact=None)

Cloud-backed SpatialData.

For now only allows to access tables.

class lamindb.core.storage.BackedAccessor(connection, storage)

h5py.File or zarr.Group accessor.

LanceDB tables

class lamindb.core.storage.LanceAccessor(artifact)

Read and revise a .lance artifact.

Reached through lance. open() returns the LanceDB table at the version pinned on that artifact. add() and add_columns() write to the table and save a new artifact version. The artifact you called them on stays pinned to the Lance version from before the write.

open(*, version=None)

Open this artifact as one LanceDB table.

Returns a lancedb.table.LanceTable. When this artifact version has a pinned Lance version and that version is not the directory’s latest, the table is checked out at the pin. Pass version to check out a specific Lance version instead.

Writes on the returned table change the Lance directory and leave this artifact’s pin unchanged. add() and add_columns() write and save a new artifact version.

On S3, AWS credentials are read from the artifact path when the table is opened. A refreshable session is snapshotted at that moment.

Parameters:

version (int | None, default: None) – Lance version to check out. Defaults to the version pinned when this artifact version was written.

Return type:

LanceTable

add(data, *, run=None)

Append rows and save a new artifact version.

Calls LanceTable.add(data, mode="append") on this artifact’s directory, then registers a new artifact version of that same directory. The previous version stays pinned to the Lance version from before the append. lance.open() checks out that version.

The directory is shared across these artifact versions, as with a .tiledbsoma store. from_dataframe() still writes a new directory. Writes stay on Lance’s default branch. Coupling LaminDB branches to Lance branches is not supported and not needed for isolation: a version saved on another LaminDB branch is not visible on main.

Parameters:
  • data (Any) – Rows to append. Any object accepted by LanceTable.add.

  • run (Run | None, default: None) – The run that creates the new artifact version.

Return type:

Artifact

Examples

Append rows and keep the previous Lance version readable:

revised = artifact.lance.add(new_rows)
artifact.lance.open().count_rows()
revised.lance.open().count_rows()
add_columns(transforms=None, *, computed=None, run=None)

Add columns and save a new artifact version.

Calls LanceTable.add_columns on this artifact’s directory, then registers a new artifact version of that same directory. The previous version stays pinned to the Lance version from before the write, so opening it still returns the previous schema.

Support for validating columns will be added soon. Use from_dataframe() to validate columns for now.

Parameters:
  • transforms (Any, default: None) – Column definitions accepted by LanceTable.add_columns. A dict maps a new column name to a SQL expression evaluated on each existing row. A pyarrow field, list of fields, or schema adds columns filled with nulls.

  • computed (dict[str, str] | None, default: None) – SQL expressions for maintained computed columns.

  • run (Run | None, default: None) – The run that creates the new artifact version.

Return type:

Artifact

Examples

Add a column computed from existing rows:

revised = artifact.lance.add_columns({"score": "n_genes * 2"})