Skip to main content

Opinionated Databricks Utilities

Project description

Opinionated Databricks Utilities (ODU)

PyPI version License: MIT Python 3.12+

ODU is a collection of opinionated utilities for working on the Databricks platform.

The Problem

When Databricks notebooks run as workflow tasks, the current working directory is a random location on the cluster — not the directory where your notebook lives. This breaks relative imports and pip install -r requirements.txt.

ODU solves this by providing utilities to:

  1. Locate your repository root from inside a running notebook.
  2. Add your src/ directory to sys.path.

Installation

pip install odu

Quick Start

Add these two cells at the top of every notebook that runs as a workflow task.

Cell 1 — Before restart:

import sys
from odu.bootstrap import repo_root_finder, add_src_path_to_sys_path

repo_root = repo_root_finder(dbutils)

# Install requirements and restart Python to make them effective
%pip install -r {repo_root}/requirements.txt
dbutils.library.restartPython()

Cell 2 — After restart:

import sys
from odu.bootstrap import repo_root_finder, add_src_path_to_sys_path

repo_root = repo_root_finder(dbutils)
add_src_path_to_sys_path(repo_root, sys)

# Now your src/ packages are importable
from my_package import my_module

Advanced Usage

# Get all repo paths as a dict
fs = repo_root_finder(dbutils, returns="all")
# {
#   "repo_root":                 "/Workspace/Repos/user/my-repo",
#   "notebook_path":             "/Workspace/Repos/user/my-repo/notebooks/my_nb",
#   "src_path":                  "/Workspace/Repos/user/my-repo/src",
#   "requirements_path":         "/Workspace/Repos/user/my-repo/requirements.txt",
#   "notebooks_dir_path":        "/Workspace/Repos/user/my-repo/notebooks",
#   "configs_path":              None,  # (doesn't exist)
#   "resources_path":            None,
#   "databricks_resources_path": None,
# }

add_src_path_to_sys_path(fs, sys)  # works with both str and dict

# Custom markers and matching strategy
repo_root = repo_root_finder(
    dbutils,
    match_strategy="at least k",
    k=2,
    markers=["src", "notebooks", "requirements.txt", "pyproject.toml"],
)

Documentation

Full documentation is available at the GitHub Pages site.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

odu-0.1.0.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

odu-0.1.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file odu-0.1.0.tar.gz.

File metadata

  • Download URL: odu-0.1.0.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for odu-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ee7d4430fd671acd44d2a5a9ff050bfb7950db662390b12f3a2be9120b029a20
MD5 18c177c1fac062420bedc4ba76b97cc1
BLAKE2b-256 eaba6becba22d45c7c9c36375a13852817a9c327672d519e895569237739d1d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for odu-0.1.0.tar.gz:

Publisher: main-release.yml on neolaw84/opinionated-databricks-utilities

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file odu-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: odu-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for odu-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 45f7f56c1feada49f00d1adf328f6b7dd2588d170ed5018da0bd1a4439decf36
MD5 4672b4d7e772e9c2f28bb46134d17be3
BLAKE2b-256 3f540f80b31928360006e70e6fcf3a72e64f442030ca1ca0e264e326492077fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for odu-0.1.0-py3-none-any.whl:

Publisher: main-release.yml on neolaw84/opinionated-databricks-utilities

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page