{"library":"patchy","title":"Patchy","description":"Patchy is a Python library that allows patching the inner source code of Python functions at runtime. Unlike traditional monkey patching, which replaces function objects, Patchy modifies the function's `__code__` attribute, ensuring that all references to the function (even those imported elsewhere) reflect the new behavior. It achieves this by using the standard `patch` command-line utility to apply diffs to the function's source code. The current version is 2.10.0, and it generally follows a release cadence tied to bug fixes and feature enhancements, compatible with Python 3.9 to 3.14.","language":"python","status":"active","last_verified":"Fri May 15","install":{"commands":["pip install patchy"],"cli":{"name":"patchy","version":"sh: 1: patchy: not found"}},"imports":["import patchy\n\ndef my_func():\n    return 1\n\npatchy.patch(my_func, \"\"\"\\\ndef my_func():\n-    return 1\n+    return 9001\n\"\"\")"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import patchy\n\ndef sample():\n    return 1\n\nprint(f\"Original output: {sample()}\")\n\n# Apply a patch to change the function's behavior\npatchy.patch(\n    sample,\n    \"\"\"\\\ndef sample():\n-    return 1\n+    return 9001\n\"\"\",\n)\n\nprint(f\"Patched output: {sample()}\")","lang":"python","description":"This example demonstrates how to use `patchy.patch()` to modify the runtime behavior of a Python function by applying a standard diff format string. The `patch` function takes the target function (or its dotted path as a string) and the patch text.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-15","installed_version":"2.10.0","pypi_latest":"2.10.0","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":1.5,"avg_import_s":0.06,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"patchy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.04,"mem_mb":2.2,"disk_size":"17.8M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"patchy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.4,"import_time_s":0.03,"mem_mb":2.2,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"patchy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.08,"mem_mb":2.8,"disk_size":"19.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"patchy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.6,"import_time_s":0.07,"mem_mb":2.8,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"patchy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.07,"mem_mb":2.7,"disk_size":"11.5M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"patchy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.4,"import_time_s":0.07,"mem_mb":2.7,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"patchy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.07,"mem_mb":2.9,"disk_size":"11.3M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"patchy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.4,"import_time_s":0.07,"mem_mb":2.7,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"patchy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.04,"mem_mb":2.2,"disk_size":"17.3M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"patchy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.7,"import_time_s":0.04,"mem_mb":2.2,"disk_size":"18M"}]}}