A Python package patching tool that allows you to make and apply patches to third-party packages in your virtual environment.
uv add patch-package-pyThis repository includes an agent skill for AI agents that support agent skills.
The tool provides three main commands via the p12y CLI:
p12y patch <package_name>This command:
- Resolves the package from an environment path
- if omitted, it detects from the current directory (
/.venv)
- if omitted, it detects from the current directory (
- Creates a temporary virtual environment
- Installs the same version of the package without dependencies
- Sets up a git repository for tracking changes
- Provides a path where you can edit the package files
Example:
p12y patch requests [-e <environment-path>]p12y commit <edit_path> [--skip-restore]After editing the package files, use this command to:
- Generate a git diff of your changes
- Create a
.patchfile in thepatches/directory - Reinstall the original package in the target environment
- Apply the new patch to the target environment
Example:
p12y commit /tmp/patch-requests-2.28.1-abc123/venv/lib/python3.11/site-packages/requestsUse --skip-restore to write the patch file and apply it to the current target
environment directly.
p12y apply [-e <environment-path>]This command:
- Looks for
.patchfiles in thepatches/directory - Applies them to the packages in the environment path
- if omitted, it detects from the current directory (
/.venv)
- if omitted, it detects from the current directory (
- Reports success/failure for each patch
- Prepare for patching: Run
p12y patch <package_name>to set up a workspace - Make your changes: Edit the files in the provided path
- Create the patch: Run
p12y commit <path>to generate the patch file - Apply patches: Run
p12y applyin your project to apply all patches
- Uses
uvfor fast virtual environment creation and package installation - Leverages git for tracking changes and generating diffs
- Reinstalls the target package during
commitbefore applying the newly generated patch - Stores patch files in a
patches/directory in your project root - Patch files are named using the format:
<package-name>+<version>.patch
- Detect the environment path using
poetry env info --path. - Use the
-e/--env-pathoption forpatchandapply. commitreuses the environment path recorded bypatch -e.
p12y patch requests -e "$(poetry env info --path)"
p12y commit <edit_path>
p12y apply -e "$(poetry env info --path)"- Python ≥ 3.9
uvpackage managergitversion control systempatchutility (typically pre-installed on Unix-like systems)- for windows you can install
- using chocolatey:
choco install patch - using winget
winget install --id=GnuWin32.Patch -e - or it might be packed with cygwin.
- using chocolatey:
- for windows you can install
MIT