## lamindb.Transform

| class lamindb.Transform(key: str | None = None, kind: TransformKind | None = None, version: str | None = None, description: str | None = None, reference: str | None = None, reference_type: str | None = None, source_code: str | None = None, revises: Transform | None = None, skip_hash_lookup: bool = False, branch: Branch | None = None, space: Space | None = None) |
class lamindb.Transform(*db_args)

 Bases: "SQLRecord", "IsVersioned", "TracksRun"

 Data transformations such as scripts, notebooks, functions, or
 pipelines.

 If you execute a transform, you generate a run ("Run").

 Parameters:
| * **key** -- "str | None = None" A filepath-like key. |

| * **kind** -- "TransformKind | None = "pipeline"" See |
 "TransformKind".

| * **version** -- "str | None = None" A version string. |

| * **description** -- "str | None = None" A description. |

| * **reference** -- "str | None = None" A reference, e.g., a URL. |

| * **reference_type** -- "str | None = None" A reference type, |
 e.g., 'url'.

| * **source_code** -- "str | None = None" Source code of the |
 transform.

| * **revises** -- "Transform | None = None" An old version of the |
 transform.

 * **skip_hash_lookup** -- "bool = False" Skip the hash lookup so
 that a new transform is created even if a transform with the
 same hash already exists.

| * **branch** -- "Branch | None = None" A branch. If "None", uses |
 the current branch.

| * **space** -- "Space | None = None" A space. If "None", uses |
 the current space.

 See also:

 "track()"
 Track a script or notebook run.

 "Run"
 Executions of transforms.

 "from_git()"
 Create a transform from a git repository, e.g., for a Nextflow
 pipeline.

# Examples

 Create a transform by running "ln.track()" in a notebook or a
 script:

 ln.track()

 Create a transform for a standalone function that acts as its own
 workflow:

 @ln.flow()
 def my_workflow():
 print("Hello, world!")

 Create a transform for a step in a workflow:

 @ln.step()
 def my_step():
 print("One step!")

 Create a transform from a local script or notebook path:

 transform = ln.Transform.from_path("scripts/my_workflow.py").save()

 Create a transform from a file in a git repository:

 transform = ln.Transform.from_git(
 url="https://github.com/openproblems-bio/task_batch_integration",
 path="main.nf",
 ).save()

 Create a transform for a pipeline:

 transform = ln.Transform(key="Cell Ranger", version="7.2.0", kind="pipeline").save()

 Create a transform by saving a Python or shell script or a notebook
 via the CLI:

 lamin save my_script.py
 lamin save my_script.sh
 lamin save my_notebook.ipynb

# Notes

 -[ Can I sync transforms to git? ]-

 If you set the environment variable "LAMINDB_SYNC_GIT_REPO" or set
 "ln.settings.sync_git_repo", a script-like transform is synced to
 its hashed state in a git repository upon calling "ln.track()":

 ln.settings.sync_git_repo = "https://github.com/laminlabs/lamindb"
 ln.track()

 If the hash isn't found in the git repository, an error is thrown.

 You can also create transforms that map pipelines via
 "Transform.from_git()".

 -[ Is this consistent with the OpenLineage specification? ]-

 Yes. In OpenLineage a "transform" would be called a "job" and a
 "run" a "run".

# Guides

 * Track notebooks, scripts & workflows

 * Redun

 * Nextflow

 * Snakemake

 property latest_run: Run

 The latest run of this transform.

 uid: str

 Universal id.

 key: str

 A name or "/"-separated path-like string.

 All transforms with the same key are part of the same version
 family.

| description: str | None |

 A description.

 kind: TransformKind

 A string indicating the kind of transform (default
 ""pipeline"").

 One of ""pipeline"", ""notebook"", ""script"", or ""function"".

| source_code: str | None |

 Source code of the transform.

| hash: str | None |

 Hash of the source code.

| reference: str | None |

 Reference for the transform, e.g., a URL.

| reference_type: str | None |

 Reference type of the transform, e.g., 'url'.

| environment: Artifact | None |

 An environment for executing the transform.

| plan: Artifact | None |

 An optional plan for executing this transform.

 updated_at: datetime

 Time of last update to record.

 ulabels: RelatedManager[ULabel]

 "ULabel" annotations of this transform ← "transforms".

 linked_in_records: RelatedManager[Record]

 This transform is linked in these records as a value ←
 "linked_transforms".

 predecessors: RelatedManager[Transform]

 Preceding transforms ← "successors".

 runs: RelatedManager[Run]

 Runs of this transform ← "transform".

 successors: RelatedManager[Transform]

 Subsequent transforms ← "predecessors".

 Allows defining succeeding transforms. Is *not* necessary for
 data lineage, which is tracked automatically whenever an
 artifact or collection serves as an input for a run.

 records: RelatedManager[Record]

 Records that annotate this transform ← "transforms".

 references: RelatedManager[Reference]

 Linked references ← "transforms".

 projects: RelatedManager[Project]

 Linked projects ← "transforms".

 ablocks: RelatedManager[TransformBlock]

 Attached blocks ← "transform".

 classmethod from_path(path, key=None, kind=None, version=None, description=None, skip_hash_lookup=False)

 Create a transform from a local file path.

 Parameters:
| * **path** ("str" | "Path") -- Path to a local script or |
 notebook file.

| * **key** ("str" | "None", default: "None") -- Optional key |
 for the transform.

 * **kind** ("Literal"["'pipeline'", "'notebook'", "'script'",
| "'function'"] | "None", default: "None") -- Optional kind |
 override. If omitted, inferred from file suffix.

| * **version** ("str" | "None", default: "None") -- Optional |
 version tag.

| * **description** ("str" | "None", default: "None") -- |
 Optional description for the transform.

 * **skip_hash_lookup** ("bool", default: "False") -- Skip
 hash-based lookup.

 Return type:
 "Transform"

 -[ Notes ]-

 Kind inference defaults to ""script"" and uses ""notebook"" for
 ".ipynb", ".Rmd", and ".qmd" files.

 classmethod from_git(url, path, key=None, version=None, entrypoint=None, branch=None, description=None, skip_hash_lookup=False)

 Create a transform from a path in a git repository.

 Parameters:
 * **url** ("str") -- URL of the git repository.

 * **path** ("str") -- Path to the file within the repository.

| * **key** ("str" | "None", default: "None") -- Optional key |
 for the transform.

| * **version** ("str" | "None", default: "None") -- Optional |
 version tag to checkout in the repository.

| * **entrypoint** ("str" | "None", default: "None") -- One or |
 several optional comma-separated entrypoints for the
 transform.

| * **branch** ("str" | "None", default: "None") -- Optional |
 branch to checkout.

| * **description** ("str" | "None", default: "None") -- |
 Optional description for the transform.

 * **skip_hash_lookup** ("bool", default: "False") -- Skip the
 hash lookup so that a new transform is created even if a
 transform with the same hash already exists.

 Return type:
 "Transform"

 -[ Examples ]-

 Create from a Nextflow repo and auto-infer the commit hash from
 its latest version:

 transform = ln.Transform.from_git(
 url="https://github.com/openproblems-bio/task_batch_integration",
 path="main.nf"
 ).save()

 Create from a Nextflow repo and checkout a specific version:

 transform = ln.Transform.from_git(
 url="https://github.com/openproblems-bio/task_batch_integration",
 path="main.nf",
 version="v2.0.0"
 ).save()
 assert transform.version_tag == "v2.0.0"

 Create a *sliding transform* from a Nextflow repo's "dev"
 branch. Unlike a regular transform, a sliding transform doesn't
 pin a specific source code state, but adapts to whatever the
 referenced state on the branch is:

 transform = ln.Transform.from_git(
 url="https://github.com/openproblems-bio/task_batch_integration",
 path="main.nf",
 branch="dev",
 version="dev",
 ).save()

 -[ Notes ]-

 A regular transform pins a specific source code state through
 its commit hash:

 transform.source_code
 #> repo: https://github.com/openproblems-bio/task_batch_integration
 #> path: main.nf
 #> commit: 68eb2ecc52990617dbb6d1bb5c7158d9893796bb

 A sliding transform infers the source code state from a branch:

 transform.source_code
 #> repo: https://github.com/openproblems-bio/task_batch_integration
 #> path: main.nf
 #> branch: dev

 If an entrypoint is provided, it is added to the source code
 below the path, e.g.:

 transform.source_code
 #> repo: https://github.com/openproblems-bio/task_batch_integration
 #> path: main.nf
 #> entrypoint: myentrypoint
 #> commit: 68eb2ecc52990617dbb6d1bb5c7158d9893796bb

 Note that you can pass a comma-separated list of entrypoints to
 the "entrypoint" argument.

 view_lineage(with_successors=False, distance=5)

 View lineage of transforms.

 Note that this only accounts for manually defined predecessors
 and successors.

 Auto-generate lineage through inputs and outputs of runs is not
 included.