Skip to content

Notebook

laktory.models.resources.databricks.Notebook ¤

Bases: RenderableFileMixin, NotebookBase

Databricks Notebook

Examples:

import io

from laktory import models

notebook_yaml = '''
source: ./notebooks/dlt/dlt_laktory_pl.py
dirpath: notebooks/dlt/
access_controls:
- group_name: role-engineers
  permission_level: CAN_RUN
'''
notebook = models.resources.databricks.Notebook.model_validate_yaml(
    io.StringIO(notebook_yaml)
)
print(notebook.path)
# > /.laktory/notebooks/dlt/dlt_laktory_pl.py
References
BASE DESCRIPTION
content_base64

The base64-encoded notebook source code. Conflicts with source. Use of content_base64 is discouraged, as it's increasing memory footprint of Terraform state and should only be used in exceptional circumstances, like creating a notebook with configuration properties for a data pipeline

TYPE: str | None | VariableType DEFAULT: None

format

TYPE: str | None | VariableType DEFAULT: None

language

(required with content_base64) One of SCALA, PYTHON, SQL, R

TYPE: str | None | VariableType DEFAULT: None

md5

TYPE: str | None | VariableType DEFAULT: None

object_id

Unique identifier for a NOTEBOOK

TYPE: int | None | VariableType DEFAULT: None

object_type

TYPE: str | None | VariableType DEFAULT: None

LAKTORY DESCRIPTION
access_controls

List of notebook access controls

TYPE: list[AccessControl | VariableType] | VariableType DEFAULT: []

dirpath

Workspace directory inside rootpath in which the notebook is deployed. Used only if path is not specified.

TYPE: str | VariableType DEFAULT: None

path_

Workspace filepath for the notebook. Overwrite rootpath and dirpath.

TYPE: str | VariableType DEFAULT: None

render_vars

If True, resolve ${vars.x} / ${{ expr }} placeholders in this file's content before upload. Resolved content is staged under settings.build_root; the staged copy is (re)written whenever Stack.build() runs (which preview, deploy, destroy and build all trigger).

TYPE: bool DEFAULT: False

source_

Path to notebook in source code format on local filesystem. Conflicts with content_base64

TYPE: str | VariableType DEFAULT: None

METHOD DESCRIPTION
build

Render ${vars.x}/${{ expr }} placeholders in the notebook

check_staged

Raise a clear error if this resource is configured for variable

ATTRIBUTE DESCRIPTION
additional_core_resources
  • permissions

TYPE: list

filename

Notebook file name

TYPE: str

additional_core_resources property ¤

  • permissions

filename property ¤

Notebook file name

build(vars=None) ¤

Render ${vars.x}/${{ expr }} placeholders in the notebook content and stage the result under settings.build_root, if render_vars is True. No-op otherwise.

Source code in laktory/models/resources/databricks/notebook.py
112
113
114
115
116
117
118
119
def build(self, vars: dict = None):
    """
    Render `${vars.x}`/`${{ expr }}` placeholders in the notebook
    content and stage the result under `settings.build_root`, if
    `render_vars` is `True`. No-op otherwise.
    """
    if self.render_vars:
        self._render_to_staged_path(self.source_, self.source, vars=vars)

check_staged() ¤

Raise a clear error if this resource is configured for variable rendering but its staged copy hasn't been written yet (i.e. .build() hasn't run). Guards against programmatic use that bypasses Stack.build() (the normal CLI flow always calls it before dumping resources).

Source code in laktory/models/resources/databricks/_renderablefile.py
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def check_staged(self):
    """
    Raise a clear error if this resource is configured for variable
    rendering but its staged copy hasn't been written yet (i.e.
    `.build()` hasn't run). Guards against programmatic use that
    bypasses `Stack.build()` (the normal CLI flow always calls it
    before dumping resources).
    """
    if not self.render_vars:
        return
    staged = self._rendered_field_value
    if staged and not Path(staged).exists():
        raise RuntimeError(
            f"'{staged}' has not been rendered yet. Run `laktory build` "
            "(or `preview`/`deploy`, which trigger it automatically) "
            "before this resource is used."
        )

laktory.models.resources.databricks.notebook.NotebookLookup ¤

Bases: ResourceLookup

PARAMETER DESCRIPTION
format

Notebook format to export. Either SOURCE, HTML, JUPYTER, or DBC

TYPE: str | VariableType DEFAULT: 'SOURCE'

path

Notebook path on the workspace

TYPE: str | VariableType