cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Best practice for using multiple local Python packages in notebooks within a Declarative Automation

a_user12
Contributor

Hi all,

I'm looking for a best practice on how to share several Python packages with notebooks in a Databricks bundle on serverless compute.

Setup

bundle-root/
├── databricks.yml
├── pyproject.toml
├── uv.lock
├── resources/
├── notebooks/
│ └── main.ipynb
└── src/
├── my_project/
│ └── foo/__init__.py
├── common/__init__.py
└── ingestion/__init__.py

Locally everything works: `uv sync` installs the project in editable mode (hatchling, `packages = ["src/my_project", "src/common", "src/ingestion"]`) and `from my_project.foo.utils import bar` works in the notebook.

After `databricks bundle deploy`, on serverless I get `ModuleNotFoundError: No module named 'my_project'`, because the bundle root / `src` is not on `sys.path`.

Options I see

1. **Plain source + sys.path:** Add `src` to `sys.path` at the top of every notebook. Works, but feels hacky, depends on the notebook location, and doesn't handle third-party dependencies.

2. **One pyproject.toml → one wheel with all packages:**
a) Use the Beta `project_environment` (https://docs.databricks.com/aws/en/compute/serverless/dependencies#configure-a-project-environment-w...), which needs the "Project-Scoped Shared Compute" preview, environment version 5+, an up-to-date `uv.lock` and CLI 1.21.0+.
b) Build the wheel as a bundle artifact and `%pip install` it in the notebook (or via `environments` for wheel tasks).

Questions

- What is your recommended / production-proven approach for this?
- For option 2b: how do you reference the deployed wheel from a notebook task without hardcoding the workspace path?
- For option 2a: i build one wheel cotaining with all packages: is that fine?
- How do you keep interactive development in the workspace fast (no rebuild/redeploy after every code change)?

Thanks a lot!

0 REPLIES 0