lamindb.core.Context

class lamindb.core.Context

Bases: object

Run context.

Enables convenient data lineage tracking by managing a transform & run upon track() & finish().

Examples

Is typically used via context:

>>> import lamindb as ln
>>> ln.context.track()
>>> # do things while tracking data lineage
>>> ln.context.finish()

Attributes

property name: str | None

name to create transform.

property run: Run | None

Run of context.

property transform: Transform | None

Transform of context.

property uid: str | None

uid to create transform.

property version: str | None

version to create transform.

Methods

finish(ignore_non_consecutive=None)

Mark the run context as finished.

  • writes a timestamp: run.finished_at

  • saves the source code: transform.source_code

When called in the last cell of a notebook:

  • prompts for user input if not consecutively executed

  • requires to save the notebook in your editor

  • saves a run report: run.report

Parameters:

ignore_non_consecutive (bool | None, default: None) – Whether to ignore if a notebook was non-consecutively executed.

Return type:

None

Examples

>>> import lamindb as ln
>>> ln.context.track()
>>> # do things while tracking data lineage
>>> ln.context.finish()

See also

lamin save script.py or lamin save notebook.ipynbdocs

track(*, params=None, new_run=None, path=None, transform=None)

Starts data lineage tracking for a run.

  • sets transform & run by creating or loading Transform & Run records

  • saves compute environment as a requirements.txt file: run.environment

If sync_git_repo is set, checks whether a script-like transform exists in a git repository and links it.

Parameters:
  • params (dict | None, default: None) – A dictionary of parameters to track for the run.

  • new_run (bool | None, default: None) – If False, loads latest run of transform (default notebook), if True, creates new run (default pipeline).

  • path (str | None, default: None) – Filepath of notebook or script. Only needed if it can’t be automatically detected.

  • transform (Transform | None, default: None) – Useful to track an abstract pipeline.

Return type:

None

Examples

To track the run of a notebook or script, call:

>>> import lamindb as ln
>>> ln.context.track()