lamindb.core.Context

class lamindb.core.Context

Bases: object

Run context.

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

Guide: Track notebooks & scripts

Examples

Is typically used via the global context object via ln.track() and ln.finish():

>>> import lamindb as ln
>>> ln.track()
>>> # do things
>>> ln.finish()

Attributes

property name: str | None

name argument for `context.transform.

property run: Run | None

Managed run of context.

property transform: Transform | None

Managed transform of context.

property uid: str | None

uid argument for context.transform.

property version: str | None

version argument for context.transform.

Methods

finish(ignore_non_consecutive=None)

Finish a tracked run.

  • 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 right before

  • saves a run report: run.report

Parameters:

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

Return type:

None

Examples

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

See also

lamin save script.py or lamin save notebook.ipynbdocs

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

Initiate a run with tracked data lineage.

  • 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:
  • transform (str | Transform | None, default: None) – A transform uid or record. If None, creates a uid.

  • 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.

Return type:

None

Examples

To create a transform uid for tracking a script or notebook, call:

>>> ln.track()

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

>>> ln.track("FPnfDtJz8qbE0000")  # replace with your uid