A Databricks notebook can help automate much of the wheel (whl) packaging and installation process, but it cannot fully eliminate the requirement of building the wheel artifact itself. However, you can create a notebook (or workflow) that covers most steps, from package building to deploying and installing the wheel onto your workspace or cluster, thereby minimizing manual intervention.

Key Capabilities

  • Building the wheel (whl) file automatically: With tools like setuptools, poetry, or uv, a notebook can run shell commands (%sh) or Magic commands to build the wheel directly from code stored within the Databricks workspace or fetched from a repository.

  • Uploading and installing the wheel: The notebook can upload the generated .whl to DBFS or a workspace path, then install it using %pip install /dbfs/path/to/your_package.whl or a similar command.

  • Automated configuration: Any additional setup, such as installing dependencies from a requirements.txt, can also be scripted within the same notebook.

Practical Limitations

  • You must still follow the basic structure of Python packaging: having a setup.py (or equivalent) and metadata files is necessary since these are required by the Python ecosystem to build wheels.

  • The initial setup (creating setup.py, organizing code, and writing build commands) happens once. Afterward, updating the wheel and deploying new versions can be fully automated in a notebook workflow.

Example Workflow

  1. Place your source code and setup files (e.g., setup.py, pyproject.toml) in a workspace or accessible location.

  2. Use a notebook cell to run the wheel build process:

    text
    %sh python setup.py bdist_wheel
  3. Use another cell to upload and install the newly built wheel:

    text
    %pip install /dbfs/path/to/dist/your_package.whl
  4. Optionally, automate the copying/upload of the wheel with the Databricks CLI or REST API.

This approach largely replaces manual building and uploading with a repeatable, notebook-driven process, streamlining your team's workflow.

In summary, while a notebook can't avoid the need for wheel-building prerequisites (setup files, code structure), it can effectively automate package creation, configuration, and installation to the point where manual intervention is minimal and repeatable updates become much easier.

View solution in original post