jupyter_notebook_binary

Rules

jupyter_notebook_binary

load("@rules_jupyter//jupyter:jupyter_notebook_binary.bzl", "jupyter_notebook_binary")

jupyter_notebook_binary(name, data, cwd_mode, env, env_inherit, exporter_args, notebook, out_dir,
                        reports)

An executable rule that runs a Jupyter notebook and optionally generates reports.

Unlike jupyter_notebook_test, this rule creates an executable target for use with bazel run. Outputs (executed notebook and reports) are written to a configurable output directory, defaulting to the caller's working directory (BUILD_WORKING_DIRECTORY).

Example:

jupyter_notebook(
    name = "my_notebook",
    src = "notebook.py",
    deps = ["@pip_deps//polars"],
)

jupyter_notebook_binary(
    name = "run_notebook",
    notebook = ":my_notebook",
    reports = ["html"],
)

Then run: bazel run :run_notebook or bazel run :run_notebook -- --my-flag value

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
dataAdditional data files required by the notebook (e.g., input data files, images, configuration files).List of labelsoptional[]
cwd_modeThe working directory mode for notebook execution. If not specified, uses the toolchain's default_cwd. execution_root sets the working directory to the workspace root, while notebook_root sets it to the notebook's parent directory. This affects how relative paths in the notebook are resolved.Stringoptional""
envEnvironment variables to set when executing the notebook. Values support location expansion (e.g., $(location :target)).Dictionary: String -> Stringoptional{}
env_inheritSpecifies additional environment variables to inherit from the external environment.List of stringsoptional[]
exporter_argsTraitlets-style flags forwarded to nbconvert exporters (e.g. --WebPDFExporter.exclude_input=true).List of stringsoptional[]
notebookThe notebook to execute. Must be a jupyter_notebook target.Labelrequired
out_dirDirectory to write output files to. If not specified, outputs are written to a subdirectory named after the target under the caller's working directory (e.g., bazel run :run_notebook writes to ./run_notebook/). Absolute paths (e.g., /tmp) are used as-is; relative paths are resolved against the caller's working directory.Stringoptional""
reportsList of report types to generate after successful notebook execution. Valid values: 'html', 'markdown', 'latex', 'webpdf'.List of stringsoptional[]