Skip to main content

patch-package-py

A Python package patching tool that allows you to make and apply patches to third-party packages in your virtual environment.

Installation

uv add patch-package-py

Agent skill

This repository includes an agent skill for AI agents that support agent skills.

Usage

The tool provides three main commands via the p12y CLI:

1. Create a patch workspace

p12y patch <package_name>

This command:

  • Resolves the package from an environment path
    • if omitted, it detects from the current directory (/.venv)
  • 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>]

2. Commit changes and create patch file

p12y commit <edit_path> [--skip-restore]

After editing the package files, use this command to:

  • Generate a git diff of your changes
  • Create a .patch file in the patches/ 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/requests

Use --skip-restore to write the patch file and apply it to the current target environment directly.

3. Apply patches

p12y apply [-e <environment-path>]

This command:

  • Looks for .patch files in the patches/ directory
  • Applies them to the packages in the environment path
    • if omitted, it detects from the current directory (/.venv)
  • Reports success/failure for each patch

Workflow

  1. Prepare for patching: Run p12y patch <package_name> to set up a workspace
  2. Make your changes: Edit the files in the provided path
  3. Create the patch: Run p12y commit <path> to generate the patch file
  4. Apply patches: Run p12y apply in your project to apply all patches

How it works

  • Uses uv for fast virtual environment creation and package installation
  • Leverages git for tracking changes and generating diffs
  • Reinstalls the target package during commit before 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

Using with Poetry

  • Detect the environment path using poetry env info --path.
  • Use the -e / --env-path option for patch and apply.
  • commit reuses the environment path recorded by patch -e.
p12y patch requests -e "$(poetry env info --path)"
p12y commit <edit_path>
p12y apply -e "$(poetry env info --path)"

Requirements

  • Python ≥ 3.9
  • uv package manager
  • git version control system
  • patch utility (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.

License

MIT

Metadata

Release files for patch-package-py 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for patch-package-py 0.2.1
File Size Uploaded
patch_package_py-0.2.1.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for patch-package-py 0.2.1
File Interpreter ABI Platform
patch_package_py-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.3 kB

Release files / patch_package_py-0.2.1.tar.gz

Download URL patch_package_py-0.2.1.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a5addd8c4c897bf7795496f3148d4470f84a4abbebdcab06cea2213a4303de67
BLAKE2b-256 checksum
How to use checksums
ce6c1a15f563b8506b5fe4edbcd70836d4c481704518aeb5bc5c79602656083e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 31, 2026.

Transparency log

Release files / patch_package_py-0.2.1-py3-none-any.whl

Download URL patch_package_py-0.2.1-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
135054c5eb112377c67adcbd7e4502007c24a94d2cd98b5a6fa119fe60ae693e
BLAKE2b-256 checksum
How to use checksums
876c8cd23d431ee1a3ccbfa2ac9ced565c9df1b91fe51119b1b008e6588131ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 31, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page