Skip to main content

Run Python scripts with temporary source-file hot patches applied before execution and restored afterward.

Project description

patchon

CI PyPI Python

patchon (pronounced patch-on) runs your Python code with temporary source patches applied before execution, then restores the original files afterward.

中文文档

What It Does

Use patchon when you want to temporarily change installed Python package code without manually editing site-packages and then cleaning up later.

Typical use cases:

  • Debug a library by adding prints or logging
  • Try a local hotfix before an upstream release lands
  • Inject instrumentation for profiling or tracing
  • Reproduce and test a package-level workaround safely

Install

Choose one of these user-facing install flows:

pip install patchon

Or install it as a tool with uv:

uv tool install patchon

After that, patchon is available on your shell just like python.

Quick Start

1. Create a config

patchon looks upward from the current directory for:

  1. pyproject.toml with a [tool.patchon] section
  2. patchon.yaml

Recommended pyproject.toml example:

[tool.patchon]
verbose = true
strict = true

[[tool.patchon.patches]]
package = "requests"
expected_version = "2.31.0"
patch_root = "./patches/requests"

You can also start from examples/patchon.yaml.example.

2. Create your patch files

Mirror the package's Python file layout under patch_root.

Example:

your-project/
├── pyproject.toml
└── patches/
    └── requests/
        └── sessions.py

If patch_root = "./patches/requests", then patchon will map:

patches/requests/sessions.py -> requests/sessions.py

patch_root is resolved relative to the config file, not the current shell directory.

3. Run your code with patchon

patchon myscript.py

Instead of:

python myscript.py

You can also use it with modules and -c commands:

patchon -m http.server 8000
patchon -c "import requests; print(requests.__version__)"
patchon server.py --port 8000 --debug

A Typical Workflow

  1. Find the package file you want to patch.
  2. Copy that .py file into your local patch directory.
  3. Edit the local copy.
  4. Run your command with patchon.
  5. Let patchon restore the original files when the run finishes.

Example:

python -c "import requests; print(requests.__file__)"
mkdir -p patches/requests
cp /path/to/site-packages/requests/sessions.py patches/requests/
patchon --dry-run myscript.py
patchon myscript.py

CLI Basics

Useful built-in commands:

patchon --help
patchon --version
patchon --check
patchon --print-config
patchon --dry-run myscript.py
patchon --cleanup-status
patchon --cleanup

patchon parses its own flags first, then forwards the remaining arguments to Python.

Safety Behavior

patchon is designed for temporary, reversible source patching:

  • Only patches .py files
  • Backs up files before modification
  • Restores files on normal exit
  • Can check package versions with expected_version
  • Warns when your patch tree looks suspicious
  • Tries to prevent concurrent patch sessions from colliding

Troubleshooting

No configuration found

Create pyproject.toml with [tool.patchon] or create patchon.yaml.

Version mismatch

Your installed package version does not match expected_version. Update the patch or remove the version pin if that check is not needed.

Files not restored

If the process was killed hard, run:

patchon --cleanup

If needed, reinstall the affected package:

pip install --force-reinstall package_name

More Docs

Development

If you want to hack on patchon itself, the deeper build and contributor docs live under docs/ and .github/.

License

MIT License. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

patchon-0.1.0-cp314-cp314-win_amd64.whl (243.1 kB view details)

Uploaded CPython 3.14Windows x86-64

patchon-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (363.7 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

patchon-0.1.0-cp314-cp314-macosx_11_0_arm64.whl (324.5 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

patchon-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl (336.8 kB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

patchon-0.1.0-cp313-cp313-win_amd64.whl (243.1 kB view details)

Uploaded CPython 3.13Windows x86-64

patchon-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (363.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

patchon-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (324.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

patchon-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl (336.8 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

patchon-0.1.0-cp312-cp312-win_amd64.whl (243.4 kB view details)

Uploaded CPython 3.12Windows x86-64

patchon-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (364.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

patchon-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (324.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

patchon-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl (337.1 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

patchon-0.1.0-cp311-cp311-win_amd64.whl (243.2 kB view details)

Uploaded CPython 3.11Windows x86-64

patchon-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (365.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

patchon-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (325.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

patchon-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl (337.9 kB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

File details

Details for the file patchon-0.1.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: patchon-0.1.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 243.1 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for patchon-0.1.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 6950ba06690af55062d3406ce463cee720c7b4a490c65dd8140b55c1ba302c83
MD5 c1c2c7ed15e3caae6149612c55fb16d8
BLAKE2b-256 13d684979d3d513a39ed896120021b49cc750c2542565153081745c2398a0934

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchon-0.1.0-cp314-cp314-win_amd64.whl:

Publisher: publish.yml on cskujou/patchon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file patchon-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for patchon-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 20abdc379ff3c035b59d60d7ae78866ed08041f3e7464f72fc304168ce505053
MD5 185a8de5e583911fb7b285ac6ac7a0b1
BLAKE2b-256 f1c050fbceae4649b87151bccc7871e106c817c30189532947fc9c585a9d8c6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchon-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on cskujou/patchon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file patchon-0.1.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for patchon-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e91baf53e2ffbe354c0b8efb220b41a340cb48944b3086301859958119ef0cc2
MD5 9f329577a1ea07162f2b878d83f43b46
BLAKE2b-256 0c14dabd4df4d930a9ecf7240e1b5499df49a2545e6a9dcafbbc1374feba865f

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchon-0.1.0-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: publish.yml on cskujou/patchon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file patchon-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for patchon-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 207047acbcac3197b4932e6e6e78decfa35c0af1059ff116b4d57f36a131dd55
MD5 91783e1e566411d9b3fb5131a2987c7b
BLAKE2b-256 c22387c4f2ddf59dcc13ca760b8240663c91d834682b5c7150fc6a8845bb61b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchon-0.1.0-cp314-cp314-macosx_10_12_x86_64.whl:

Publisher: publish.yml on cskujou/patchon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file patchon-0.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: patchon-0.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 243.1 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for patchon-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c3abc453597cfd9d685e21a9c3900103bfa934bced39f0803564bbf85c50563a
MD5 81693e01952e613b259dd7d1f2d35381
BLAKE2b-256 d08b2bc0206420fff39da08209765ebff0f1c7c72678408b73cc924299c249d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchon-0.1.0-cp313-cp313-win_amd64.whl:

Publisher: publish.yml on cskujou/patchon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file patchon-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for patchon-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ab1d25af4201fd4cf3466d5e5066bc7c42d27869dc5859dbd3708bb264fdf134
MD5 861f02e1f0af733dd83dab98405dfd3a
BLAKE2b-256 f9b8afd772814a9e3ce39de116b885fe8f0b2dfa3a801d0c6852e94fb94dc948

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchon-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on cskujou/patchon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file patchon-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for patchon-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9c6e2815a5ae56d44b36509344de13808560ebeadf606ff64d0e3ee5d73836ac
MD5 9d41b88e5e8e3b9d99188779482f52ef
BLAKE2b-256 78378a882d926e8b86d2756cc725a2dde6601bc2af5a5f4027ffc64f74887aeb

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchon-0.1.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish.yml on cskujou/patchon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file patchon-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for patchon-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5079db295bee413a6a555239056b9a974e7079d5881044478b0c7700ac3a95fa
MD5 9cd5b9a7a3ac8cc0f04562912fa3f730
BLAKE2b-256 f89be1629e8c71b2f4b8955fa1c7a5aafbea86be705a737726520a26be810765

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchon-0.1.0-cp313-cp313-macosx_10_12_x86_64.whl:

Publisher: publish.yml on cskujou/patchon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file patchon-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: patchon-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 243.4 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for patchon-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 221edd960ff5718ab55a0028a6af33a954086a044f7995d00eedfd9535f24155
MD5 9072dfe1859a7e3ea1ba0365e22efffd
BLAKE2b-256 5ca9c8d7c987c0133f10ea681a6b71c79e2dfb0ef8ad860ad649f3d3b71ac08d

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchon-0.1.0-cp312-cp312-win_amd64.whl:

Publisher: publish.yml on cskujou/patchon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file patchon-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for patchon-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 99b36f3e6661f824e080be21971afac6d1a44292bd7ef57e61feee8ccfd857c0
MD5 a40aa4f2ab90e23d02ad87bf82192f02
BLAKE2b-256 1b61d46902bd1e925f00aa4d667c9097db5b5646c6f106cb2ec4bff81a5bbcd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchon-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on cskujou/patchon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file patchon-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for patchon-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6c3f3035813826617d1052e5baefd568a67b4e8cf8944802a2c22e3af0086377
MD5 0d5f972ade7cfc276f11865df75c5187
BLAKE2b-256 99db7cdb6bfd09923c76c35004b9776509d154f07274f93bc64f4b9b3e1fadda

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchon-0.1.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish.yml on cskujou/patchon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file patchon-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for patchon-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 888ec63a15faa2417b44ad2a3d0e5bf98513c45760dd66ed43b4c883f49ea005
MD5 faa3ed3bf5a55c2f296e18e397258c1b
BLAKE2b-256 6ddc8921eeb6527500f69ca0570fd1ef5acad6086a5cc65f0622b9a0a9912fd8

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchon-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl:

Publisher: publish.yml on cskujou/patchon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file patchon-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: patchon-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 243.2 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for patchon-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2e8af49fbbee0929c44d1f8bc64b0d6c197912a4d7fb5f2e468e484e1f7af59e
MD5 79ec169ebfcd5386b3032379cb2769ed
BLAKE2b-256 d7ee35511ff6c586cebc973ba3372222524aa6eaa0fd23eae352d9d1e1dab02b

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchon-0.1.0-cp311-cp311-win_amd64.whl:

Publisher: publish.yml on cskujou/patchon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file patchon-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for patchon-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 82d53796ee0281161fbdf88362a7f337198ad9e03fce1149ece84b4292c1b2f8
MD5 6a32c2241810f809803b3c00cc8a01ec
BLAKE2b-256 5826d26f8d9e36ff8e4711c5546c114e05026c1fc7ab14d3c990ce6ec983a8ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchon-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on cskujou/patchon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file patchon-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for patchon-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 16e671cebf483b6e75d37df285c608db0b03916d3545db5bb68de592a0e0b64b
MD5 e53f678f3ebdd80338f108e1a001dbd9
BLAKE2b-256 fc0dcfb7bb80f3918572773b9105496fc84dc71b380f3a91c9c17b216b7fe5d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchon-0.1.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: publish.yml on cskujou/patchon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file patchon-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for patchon-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 680c7d73fd4f7888e9757e59cce3080904f2f77ce4a91aa96ff3e761e8456d02
MD5 d30ef36645b1c92762556ab3db6c2ee6
BLAKE2b-256 4005d307f570ad494fd826b775dabdd51f48cf1707562acdab0a4f1822e73c11

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchon-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl:

Publisher: publish.yml on cskujou/patchon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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