Name | harmonify-patcher JSON |
Version |
1.3.0
JSON |
| download |
home_page | None |
Summary | Method behavior modification at runtime, made easy. |
upload_time | 2025-07-19 09:32:16 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | MIT License
Copyright (c) 2025 ProgrammingLover71
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
|
keywords |
patcher
python
library
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Harmonify
Harmonify is a Python library that allows users to change the behavior of classes at runtime, with nothing more than a few function calls.
Inspired by Harmony (the *very* popular C# library that also allows runtime behavior modification), Harmonify is flexible and uses a simple system based on monkey-patching.
Like its C# equivalent, it can be used for:
* **Debugging:** Inject logging or checks into methods without changing them permanently.
* **Testing:** Isolate parts of your code by temporarily changing how certain methods behave.
* **Extending Libraries:** Add new features or modify behavior of classes from libraries you can't edit directly.
* **Experimentation:** Play around with how code runs in a non-destructive way.
## Features
* **Prefix Patching:** Run your custom code *before* the original method executes.
* **Postfix Patching:** Run your custom code *after* the original method executes, even allowing you to modify its return value.
* **Replace Patching:** Completely swap out the original method's logic with your own.
* **Create & Delete methods:** Add or remove methods from a class or a module, without changing the other ones.
* **Easy Unpatching:** Restore methods to their original state with a simple call.
* **Function patching:** Patch functions as easily as methods!
* **Code Injection & Injection undo-ing:** Add you own code inside any Python function or method and revert at any time.
* *Note:* Be careful with code injection. If you're a library developer and want your code to not be injectable, add a `no_inject` attribute and set it to `True`.
## Installation
Installing Harmonify is as easy as using `pip`:
```shell
pip install harmonify-patcher
```
After that, Harmonify will be available globally!
## Example Program
### my_library.py
```python
def sqrt(x: float) -> float:
return x ** (1 / 2)
def pow(x: float, n: int) -> float:
return x ** n
def get_version():
return "1.0"
```
### main.py
```python
import harmonify
import my_library
def new_get_ver():
return "Latest release"
print(my_library.get_version()) # 1.0
harmonify.patch_function(
target_module = my_library,
function_name = "get_version",
replace = new_get_ver
)
print(my_library.get_version()) # Latest release
```
# Changelog
## 1.2.3
* Added injection safeguards. These should be applied in the target library.
## 1.2.2
* Fixed a problem where the code would be injected *before* the target line.
Raw data
{
"_id": null,
"home_page": null,
"name": "harmonify-patcher",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "patcher, python, library",
"author": null,
"author_email": "Wind Rider <abcbcalol69@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/91/f0/7bbf488bf215abaaf8f77fa78e6d536480ada11eb19896793c3712119e6a/harmonify_patcher-1.3.0.tar.gz",
"platform": null,
"description": "# Harmonify\r\n\r\nHarmonify is a Python library that allows users to change the behavior of classes at runtime, with nothing more than a few function calls.\r\nInspired by Harmony (the *very* popular C# library that also allows runtime behavior modification), Harmonify is flexible and uses a simple system based on monkey-patching.\r\nLike its C# equivalent, it can be used for:\r\n* **Debugging:** Inject logging or checks into methods without changing them permanently.\r\n* **Testing:** Isolate parts of your code by temporarily changing how certain methods behave.\r\n* **Extending Libraries:** Add new features or modify behavior of classes from libraries you can't edit directly.\r\n* **Experimentation:** Play around with how code runs in a non-destructive way.\r\n\r\n## Features\r\n\r\n* **Prefix Patching:** Run your custom code *before* the original method executes.\r\n* **Postfix Patching:** Run your custom code *after* the original method executes, even allowing you to modify its return value.\r\n* **Replace Patching:** Completely swap out the original method's logic with your own.\r\n* **Create & Delete methods:** Add or remove methods from a class or a module, without changing the other ones.\r\n* **Easy Unpatching:** Restore methods to their original state with a simple call.\r\n* **Function patching:** Patch functions as easily as methods!\r\n* **Code Injection & Injection undo-ing:** Add you own code inside any Python function or method and revert at any time.\r\n * *Note:* Be careful with code injection. If you're a library developer and want your code to not be injectable, add a `no_inject` attribute and set it to `True`.\r\n\r\n## Installation\r\n\r\nInstalling Harmonify is as easy as using `pip`:\r\n\r\n```shell\r\npip install harmonify-patcher\r\n```\r\nAfter that, Harmonify will be available globally!\r\n\r\n## Example Program\r\n\r\n### my_library.py\r\n```python\r\ndef sqrt(x: float) -> float:\r\n return x ** (1 / 2)\r\n\r\ndef pow(x: float, n: int) -> float:\r\n return x ** n\r\n\r\ndef get_version():\r\n return \"1.0\"\r\n```\r\n\r\n### main.py\r\n```python\r\nimport harmonify\r\nimport my_library\r\n\r\ndef new_get_ver():\r\n return \"Latest release\"\r\n\r\nprint(my_library.get_version()) # 1.0\r\nharmonify.patch_function(\r\n target_module = my_library,\r\n function_name = \"get_version\",\r\n replace = new_get_ver\r\n)\r\nprint(my_library.get_version()) # Latest release\r\n```\r\n\r\n# Changelog\r\n\r\n## 1.2.3\r\n* Added injection safeguards. These should be applied in the target library.\r\n\r\n## 1.2.2\r\n* Fixed a problem where the code would be injected *before* the target line.\r\n",
"bugtrack_url": null,
"license": "MIT License\r\n \r\n Copyright (c) 2025 ProgrammingLover71\r\n \r\n Permission is hereby granted, free of charge, to any person obtaining a copy\r\n of this software and associated documentation files (the \"Software\"), to deal\r\n in the Software without restriction, including without limitation the rights\r\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n copies of the Software, and to permit persons to whom the Software is\r\n furnished to do so, subject to the following conditions:\r\n \r\n The above copyright notice and this permission notice shall be included in all\r\n copies or substantial portions of the Software.\r\n \r\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n SOFTWARE.\r\n ",
"summary": "Method behavior modification at runtime, made easy.",
"version": "1.3.0",
"project_urls": {
"Homepage": "https://github.com/ProgrammingLover71/Harmonify"
},
"split_keywords": [
"patcher",
" python",
" library"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "6290bd72d7fe60ba07c807164feb1cb58695855034825ecbc7686f7ba83e61ed",
"md5": "099327701b8aa2919c8a27b45c6a37c7",
"sha256": "d1739c785420ffff1ca1ec6d89c546131dac42e8024ee5be632f3ae5e5037139"
},
"downloads": -1,
"filename": "harmonify_patcher-1.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "099327701b8aa2919c8a27b45c6a37c7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 9761,
"upload_time": "2025-07-19T09:32:15",
"upload_time_iso_8601": "2025-07-19T09:32:15.657788Z",
"url": "https://files.pythonhosted.org/packages/62/90/bd72d7fe60ba07c807164feb1cb58695855034825ecbc7686f7ba83e61ed/harmonify_patcher-1.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "91f07bbf488bf215abaaf8f77fa78e6d536480ada11eb19896793c3712119e6a",
"md5": "476e4d5596c5ce0ece96f1f37eb34818",
"sha256": "b3f1d999ceb9287c6e68092ae6a140cb2d7f63f6269cdf41bd6c6455d93effd1"
},
"downloads": -1,
"filename": "harmonify_patcher-1.3.0.tar.gz",
"has_sig": false,
"md5_digest": "476e4d5596c5ce0ece96f1f37eb34818",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 9486,
"upload_time": "2025-07-19T09:32:16",
"upload_time_iso_8601": "2025-07-19T09:32:16.501551Z",
"url": "https://files.pythonhosted.org/packages/91/f0/7bbf488bf215abaaf8f77fa78e6d536480ada11eb19896793c3712119e6a/harmonify_patcher-1.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-19 09:32:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ProgrammingLover71",
"github_project": "Harmonify",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "harmonify-patcher"
}