Skip to main content

Patchception: A library to patch the Databricks patching of Python

Project description

dbx-patch

Build Documentation Docs with MkDocs uv linting: ruff ty prek security: bandit Semantic Versions Copier License

Patchception: A library to patch the Databricks patching of Python to enable editable package installs.

Features

  • ✅ Enables editable Python package installs (pip install -e .) in Databricks notebooks
  • ✅ Patches Databricks' custom import system to allow workspace directory imports
  • ✅ Automatic patch application via sitecustomize.py (recommended)
  • ✅ Manual patching via patch_dbx() for immediate use
  • ✅ Debug mode with DBX_PATCH_DEBUG environment variable for troubleshooting

Installation

With pip:

python -m pip install dbx-patch

With uv:

uv add dbx-patch

Quick Start

🚀 Recommended: One-Command Setup

The simplest way to get started - patches current session AND installs automatic patching:

from dbx_patch import patch_and_install
patch_and_install()
# Patches applied + sitecustomize.py installed
# Python will restart automatically in Databricks!

⚡ Manual Patching (Current Session Only)

If you only want to patch the current Python session without persistence:

from dbx_patch import patch_dbx
patch_dbx()
# Editable installs now work in this session!

🔧 Automatic Patching (Persistent)

For permanent solution that works across all Python restarts:

# Run ONCE per cluster (e.g., in init script or setup notebook)
from dbx_patch import install_sitecustomize
install_sitecustomize()
# Python will restart automatically in Databricks!
# After restart, patches are applied automatically on every Python startup
  • sys_path_init.py runs during Python interpreter initialization
  • Your notebook code runs after initialization completes
  • By the time you call patch_dbx(), the import system is already configured
  • Editable install paths have already been removed from sys.path
  • Import hooks are already installed and active

The Solution: sitecustomize.py

Python automatically imports sitecustomize.py during interpreter initialization, before any Databricks code runs:

  1. Python interpreter starts
  2. sitecustomize.py runs → ✅ Patches are applied early
  3. Databricks code tries to run → ✅ Already patched!
  4. Your notebook code runs → ✅ Editable installs work!
# ✅ This WORKS - patches applied at startup
from dbx_patch import install_sitecustomize
install_sitecustomize()  # Installs sitecustomize.py + auto-restarts Python

Implementation details:

  • sitecustomize.py patches sys_path_init before it runs
  • Import hooks are modified before they're installed
  • Editable install paths are preserved in sys.path
  • All patches are applied silently during startup

For detailed technical explanation, see Technical Implementation

Docs

uv run mkdocs build -f ./mkdocs.yml -d ./_build/

Update template

copier update --trust -A --vcs-ref=HEAD

Credits

This project was generated with 🚀 python project template.

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

dbx_patch-0.1.0.tar.gz (26.1 kB view details)

Uploaded Source

Built Distribution

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

dbx_patch-0.1.0-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dbx_patch-0.1.0.tar.gz
  • Upload date:
  • Size: 26.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for dbx_patch-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ff3119867d3d3498fadd01cd9c83f97cfcaefd8076e41a5dc0fdb52266c76151
MD5 8bf4a76c687e21109f74902eae443c8b
BLAKE2b-256 672bcc8f6b85a710b2ca36f2d6a89d54c65696d2dbaa6d237b66c052078e22f0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dbx_patch-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for dbx_patch-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0130fc1e442112dc838dd82aaa5a101a8d3e5622926bea7d793ae768a97a71b6
MD5 7cc01d8c0a2e0ca36637afef31c46f39
BLAKE2b-256 b1951b383168cb2ce76fc6bcfc7f52c8ca31d8d66ae063df0a0dc88df771b5a6

See more details on using hashes here.

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