<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Best practice for using multiple local Python packages in notebooks within a Declarative Automat in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/best-practice-for-using-multiple-local-python-packages-in/m-p/178516#M57547</link>
    <description>&lt;P&gt;thanks for the clarification.&lt;/P&gt;&lt;P&gt;I conclude (after beta is over): use pyproject.toml + project environment: Then artifacts section shouldn't be necessary any more (?)&lt;/P&gt;&lt;P&gt;I assume, that there are no caching issues (as environments are usually cached)&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Dec 2026 19:31:55 GMT</pubDate>
    <dc:creator>a_user12</dc:creator>
    <dc:date>2026-12-02T19:31:55Z</dc:date>
    <item>
      <title>Best practice for using multiple local Python packages in notebooks within a Declarative Automation</title>
      <link>https://community.databricks.com/t5/data-engineering/best-practice-for-using-multiple-local-python-packages-in/m-p/178414#M57541</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm looking for a best practice on how to share several Python packages with notebooks in a Databricks bundle on serverless compute.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Setup&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;bundle-root/
├── databricks.yml
├── pyproject.toml
├── uv.lock
├── resources/
├── notebooks/
│ └── main.ipynb
└── src/
├── my_project/
│ └── foo/__init__.py
├── common/__init__.py
└── ingestion/__init__.py&lt;/LI-CODE&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;After `databricks bundle deploy`, on serverless I get `ModuleNotFoundError: No module named 'my_project'`, because the bundle root / `src` is not on `sys.path`.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Options I see&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;2. **One pyproject.toml → one wheel with all packages:**&lt;BR /&gt;a) Use the Beta `project_environment` (&lt;A href="https://docs.databricks.com/aws/en/compute/serverless/dependencies#configure-a-project-environment-with-pyprojecttoml" target="_blank"&gt;https://docs.databricks.com/aws/en/compute/serverless/dependencies#configure-a-project-environment-with-pyprojecttoml&lt;/A&gt;), which needs the "Project-Scoped Shared Compute" preview, environment version 5+, an up-to-date `uv.lock` and CLI 1.21.0+.&lt;BR /&gt;b) Build the wheel as a bundle artifact and `%pip install` it in the notebook (or via `environments` for wheel tasks).&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Questions&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;- What is your recommended / production-proven approach for this?&lt;BR /&gt;- For option 2b: how do you reference the deployed wheel from a notebook task without hardcoding the workspace path?&lt;BR /&gt;- For option 2a: i build one wheel cotaining with all packages: is that fine?&lt;BR /&gt;- How do you keep interactive development in the workspace fast (no rebuild/redeploy after every code change)?&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2026 07:31:43 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/best-practice-for-using-multiple-local-python-packages-in/m-p/178414#M57541</guid>
      <dc:creator>a_user12</dc:creator>
      <dc:date>2026-12-02T07:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: Best practice for using multiple local Python packages in notebooks within a Declarative Automat</title>
      <link>https://community.databricks.com/t5/data-engineering/best-practice-for-using-multiple-local-python-packages-in/m-p/178428#M57542</link>
      <description>&lt;DIV id="message-list_1796204160.840349" aria-setsize="-1"&gt;
&lt;DIV aria-roledescription="message"&gt;
&lt;DIV draggable="false"&gt;
&lt;DIV&gt;Hey a_user12, I tested this with a layout like yours (three packages under &lt;CODE&gt;src/&lt;/CODE&gt; plus a third-party dependency) on serverless, on both AWS and Azure, with environment versions 4 and 5.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Recommended: build one wheel and attach it to the notebook task through a job environment&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;CODE&gt;pyproject.toml&lt;/CODE&gt;: one wheel can contain all three packages:&lt;/DIV&gt;
&lt;DIV&gt;&lt;LI-CODE lang="python"&gt;[project]
name = "my_project"
version = "0.1.0"
dependencies = ["tabulate"]   # your third-party deps go here

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["src/my_project", "src/common", "src/ingestion"]&lt;/LI-CODE&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;CODE&gt;databricks.yml&lt;/CODE&gt;:&lt;/DIV&gt;
&lt;DIV&gt;&lt;LI-CODE lang="python"&gt;artifacts:
  default:
    type: whl
    build: uv build --wheel
    path: .&lt;/LI-CODE&gt;&lt;/DIV&gt;
&lt;DIV&gt;Job:&lt;/DIV&gt;
&lt;DIV&gt;&lt;LI-CODE lang="python"&gt;tasks:
  - task_key: main
    notebook_task:
      notebook_path: ../notebooks/main.ipynb
    environment_key: default

environments:
  - environment_key: default
    spec:
      environment_version: "5"
      dependencies:
        - ../dist/*.whl​&lt;/LI-CODE&gt;&lt;BR /&gt;&lt;CODE&gt;bundle deploy&lt;/CODE&gt; builds the wheel, uploads it and resolves the path, so you never hardcode a workspace location. In the notebook, &lt;CODE&gt;my_project.foo&lt;/CODE&gt;, &lt;CODE&gt;common&lt;/CODE&gt; and &lt;CODE&gt;ingestion&lt;/CODE&gt; all import as top-level packages, and the third-party deps get installed from &lt;CODE&gt;pyproject.toml&lt;/CODE&gt;.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Alternative: try to install it from inside the notebook&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;Add this to &lt;CODE&gt;databricks.yml&lt;/CODE&gt;. You need it because &lt;CODE&gt;dist/&lt;/CODE&gt; is usually gitignored and sync skips it otherwise:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;LI-CODE lang="python"&gt;sync:
  include:
    - dist/*.whl&lt;/LI-CODE&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Pass &lt;CODE&gt;bundle_root: ${workspace.file_path}&lt;/CODE&gt; to the task as a parameter, then run:&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;LI-CODE lang="python"&gt;import glob
whl = sorted(glob.glob(f"{dbutils.widgets.get('bundle_root')}/dist/*.whl"))[-1]
%pip install {whl}&lt;/LI-CODE&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;That works too, but the environment approach has fewer moving parts. Use this one if your workspace rejects the job environment with "A task environment can not be provided for notebook task". Older workspaces returned that error.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Your specific questions&lt;/STRONG&gt;&lt;BR aria-hidden="true" /&gt;• &lt;STRONG&gt;One wheel with several packages:&lt;/STRONG&gt; yes, that's fine. It's the hatchling config above.&lt;BR aria-hidden="true" /&gt;• &lt;STRONG&gt;Referencing the deployed wheel:&lt;/STRONG&gt; with the environment approach you don't reference it at all, because the bundle does it for you.&lt;BR aria-hidden="true" /&gt;• &lt;CODE&gt;&lt;STRONG&gt;project_environment&lt;/STRONG&gt;&lt;/CODE&gt;&lt;STRONG&gt;:&lt;/STRONG&gt; it's still Beta and needs a workspace preview. The wheel approach works without it, and moving over later is a small config change.&lt;BR aria-hidden="true" /&gt;• &lt;CODE&gt;&lt;STRONG&gt;sys.path&lt;/STRONG&gt;&lt;/CODE&gt;&lt;STRONG&gt;:&lt;/STRONG&gt; it does find your own &lt;CODE&gt;src&lt;/CODE&gt; code, and the official &lt;CODE&gt;default-python&lt;/CODE&gt; bundle template uses it in its sample notebook. But it doesn't install third-party dependencies, which is where it failed in my test.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Dev loop&lt;/STRONG&gt;&lt;BR aria-hidden="true" /&gt;What worked for me in the workspace: keep the job environment (so the wheel provides your third-party deps), and at the top of the notebook put your live source in front of the installed copy:&lt;/DIV&gt;
&lt;DIV&gt;&lt;LI-CODE lang="markup"&gt;import sys, os
sys.path.insert(0, os.path.abspath("../src"))&lt;/LI-CODE&gt;&lt;/DIV&gt;
&lt;DIV&gt;Then run &lt;CODE&gt;databricks bundle sync --watch&lt;/CODE&gt; locally while you edit, and &lt;CODE&gt;importlib.reload(module)&lt;/CODE&gt; in the notebook to pick up changes. No rebuild needed. When you want to test the real job setup, &lt;CODE&gt;bundle deploy&lt;/CODE&gt; to your dev target takes a few seconds.&lt;BR /&gt;&lt;BR /&gt;One thing that does &lt;I&gt;not&lt;/I&gt; work: &lt;CODE&gt;%pip install -e&lt;/CODE&gt; on the bundle folder. The deps install, but serverless doesn't put the editable path on &lt;CODE&gt;sys.path&lt;/CODE&gt;, so your own packages still fail to import.&lt;BR /&gt;&lt;BR /&gt;Developing locally with Databricks Connect against your &lt;CODE&gt;uv sync&lt;/CODE&gt; env is also an option, but I didn't verify it end to end with this layout.&lt;BR /&gt;&lt;BR /&gt;Hope that helps!&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 02 Dec 2026 09:56:29 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/best-practice-for-using-multiple-local-python-packages-in/m-p/178428#M57542</guid>
      <dc:creator>Avi3</dc:creator>
      <dc:date>2026-12-02T09:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: Best practice for using multiple local Python packages in notebooks within a Declarative Automat</title>
      <link>https://community.databricks.com/t5/data-engineering/best-practice-for-using-multiple-local-python-packages-in/m-p/178443#M57543</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/110209"&gt;@a_user12&lt;/a&gt;, I took a look at both internal and external documentation and here is what I found.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/274556"&gt;@Avi3&lt;/a&gt; has already given you a solid, tested answer. I agree with it and only have a few things to add from the docs.&lt;/P&gt;
&lt;P&gt;Why the import breaks after deploy: locally, uv sync installs your project into the venv, so my_project, common and ingestion are all importable. On Databricks, a notebook only gets its own working directory added to sys.path automatically (on DBR 11.3 LTS and above). src/ isn't on the path, and nothing has installed the packages yet, so you get ModuleNotFoundError: No module named 'my_project'.&lt;/P&gt;
&lt;P&gt;Answers to your questions:&lt;/P&gt;
&lt;P&gt;1. Production approach. Go with what &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/274556"&gt;@Avi3&lt;/a&gt; described. Build one wheel with a uv build --wheel artifact, then attach it to the notebook task through a job environment (environments → spec.dependencies: - ../dist/*.whl, with environment_key set on the task). The bundle resolves and uploads the path, so you never hardcode a workspace location. Your third-party dependencies come in through pyproject.toml. Your current layout already follows the recommended pattern: logic in src/ modules, with notebooks as thin orchestration on top.&lt;/P&gt;
&lt;P&gt;2. Notebook tasks and job environments. The serverless docs say notebook tasks default to the notebook's own environment, and you can override that with a job-level environment. environment_key is only required for Python script, wheel and dbt tasks, but it's allowed on notebook tasks. So the %pip install fallback should only be needed if your workspace rejects that configuration.&lt;/P&gt;
&lt;P&gt;3. One wheel with several top-level packages. That's fine. Your [tool.hatch.build.targets.wheel] packages = ["src/my_project", "src/common", "src/ingestion"] is the standard Hatchling way to do it. Split into separate wheels only if the packages need independent versions or release cycles.&lt;/P&gt;
&lt;P&gt;4. project_environment. This points the task straight at pyproject.toml and uv.lock. It's still Beta and needs an admin to enable the preview, plus environment version 5+ and CLI 1.21.0+. One detail: the project itself only gets installed when uv.lock is current. If it isn't, only the dependencies are installed and you'd hit the same import error. Until it's GA, the wheel approach is the safer default.&lt;/P&gt;
&lt;P&gt;5. Fast interactive development. Keep the job environment so third-party dependencies are present. Then point the notebook at the synced src folder and run databricks bundle sync --watch locally. There are two gotchas:&lt;BR /&gt;- Workspace paths appended to sys.path have the lowest library precedence, so the installed wheel would win. Use sys.path.insert(0, ...) instead of append so your live source takes priority.&lt;BR /&gt;- Instead of calling importlib.reload by hand, you can turn on autoreload (%load_ext autoreload then %autoreload 2), which re-imports changed modules before each cell runs. It doesn't push code to Spark executors, so UDF code still needs a fresh session.&lt;/P&gt;
&lt;P&gt;Keep the sys.path override in dev only. Production runs should rely on the installed wheel.&lt;/P&gt;
&lt;P&gt;References&lt;BR /&gt;Serverless environment, job task environments: &lt;A href="https://docs.databricks.com/aws/en/compute/serverless/dependencies#configure-the-environment-by-task-type" target="_blank"&gt;https://docs.databricks.com/aws/en/compute/serverless/dependencies#configure-the-environment-by-task-type&lt;/A&gt;&lt;BR /&gt;Project environment with pyproject.toml (Beta): &lt;A href="https://docs.databricks.com/aws/en/compute/serverless/dependencies#configure-a-project-environment-with-pyprojecttoml" target="_blank"&gt;https://docs.databricks.com/aws/en/compute/serverless/dependencies#configure-a-project-environment-with-pyprojecttoml&lt;/A&gt;&lt;BR /&gt;Bundle library dependencies (uv build artifact): &lt;A href="https://docs.databricks.com/aws/en/dev-tools/bundles/library-dependencies" target="_blank"&gt;https://docs.databricks.com/aws/en/dev-tools/bundles/library-dependencies&lt;/A&gt;&lt;BR /&gt;Bundle task settings (environment_key): &lt;A href="https://docs.databricks.com/aws/en/dev-tools/bundles/job-task-types" target="_blank"&gt;https://docs.databricks.com/aws/en/dev-tools/bundles/job-task-types&lt;/A&gt;&lt;BR /&gt;Python library precedence: &lt;A href="https://docs.databricks.com/aws/en/libraries#python-library-precedence" target="_blank"&gt;https://docs.databricks.com/aws/en/libraries#python-library-precedence&lt;/A&gt;&lt;BR /&gt;Python modules, sys.path and autoreload: &lt;A href="https://docs.databricks.com/aws/en/files/workspace-modules" target="_blank"&gt;https://docs.databricks.com/aws/en/files/workspace-modules&lt;/A&gt;&lt;BR /&gt;Developer best practices (src layout, thin notebooks): &lt;A href="https://docs.databricks.com/aws/en/developers/best-practices/" target="_blank"&gt;https://docs.databricks.com/aws/en/developers/best-practices/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;If you found this answer helpful please check off "Accept as Solutions" so that others can have confidence in the answer.&lt;/P&gt;
&lt;P&gt;Cheers, Lou.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2026 10:35:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/best-practice-for-using-multiple-local-python-packages-in/m-p/178443#M57543</guid>
      <dc:creator>Louis_Frolio</dc:creator>
      <dc:date>2026-12-02T10:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Best practice for using multiple local Python packages in notebooks within a Declarative Automat</title>
      <link>https://community.databricks.com/t5/data-engineering/best-practice-for-using-multiple-local-python-packages-in/m-p/178516#M57547</link>
      <description>&lt;P&gt;thanks for the clarification.&lt;/P&gt;&lt;P&gt;I conclude (after beta is over): use pyproject.toml + project environment: Then artifacts section shouldn't be necessary any more (?)&lt;/P&gt;&lt;P&gt;I assume, that there are no caching issues (as environments are usually cached)&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2026 19:31:55 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/best-practice-for-using-multiple-local-python-packages-in/m-p/178516#M57547</guid>
      <dc:creator>a_user12</dc:creator>
      <dc:date>2026-12-02T19:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: Best practice for using multiple local Python packages in notebooks within a Declarative Automat</title>
      <link>https://community.databricks.com/t5/data-engineering/best-practice-for-using-multiple-local-python-packages-in/m-p/178517#M57548</link>
      <description>&lt;P&gt;Thanks for clarifying.&lt;/P&gt;&lt;P&gt;Regarding 5: I think the main benefit of the serverless folder is, that everything (vs-code, web-ui and jobs) are configured via pyproject.toml. So I think, when using serverless folders no on-top configuration (sys.path modification) is necessary right?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Dec 2026 19:27:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/best-practice-for-using-multiple-local-python-packages-in/m-p/178517#M57548</guid>
      <dc:creator>a_user12</dc:creator>
      <dc:date>2026-12-02T19:27:45Z</dc:date>
    </item>
  </channel>
</rss>

