Codefind is a Python library (current version 0.1.7) designed for advanced code introspection, allowing users to find and manipulate code objects and their referents. It can locate code objects by filename and qualified name, identify all functions sharing a specific code object, and even modify the code of functions. This utility is notably used by the `jurigged` project for dynamic code updates. It maintains an active development status with regular, though not strictly scheduled, patch releases.
pip install codefindVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use `find_code` to locate code objects, `get_functions` to retrieve all functions associated with a given code object (useful for closures), and `conform` to dynamically replace a function's underlying code with another's. The `__file__` and `__module__` arguments are crucial for `find_code` to correctly locate code within the current execution context.
Always provide the `filename` or `module` argument to `find_code` for precise targeting of code objects within specific contexts.
Pin `codefind` to a specific version (e.g., `pip install codefind==0.1.7`) in your `requirements.txt` or `pyproject.toml` to avoid unexpected breakage. Review the GitHub repository's commit history and issue tracker for upcoming changes before upgrading.
Use code modification features like `conform` with extreme caution and thorough testing. Understand the implications of changing code at runtime and consider alternatives if stability is paramount. Limit the scope and lifetime of such modifications.
Install the library using pip: `pip install codefind`
Ensure you are providing sufficient and correct arguments (e.g., `filename=__file__` or `module=__module__` for local code) to `codefind.find_code()` to help it precisely locate the desired code object. Always check if the result of `find_code()` is not `None` before using it.
Pin `codefind` to a specific version (e.g., `pip install codefind==0.1.7`) in your project's dependencies to prevent unexpected breakage. Review the library's GitHub repository or release notes for changes if you need to upgrade, and update your code to use the new function names.
No dependency data recorded yet.