{"id":7948,"library":"autowrapt","title":"Autowrapt","description":"Autowrapt is a Python library designed to provide a bootstrap mechanism for applying monkey patches to applications without requiring direct modification of the application's source code. It achieves this by working in conjunction with the `wrapt` module and leveraging setuptools entry points, activated via the `AUTOWRAPT_BOOTSTRAP` environment variable. The current version is 1.0, released in 2015, and it functions as a stable utility in maintenance mode, with its core dependency `wrapt` being actively maintained.","status":"maintenance","version":"1.0","language":"en","source_language":"en","source_url":"https://github.com/GrahamDumpleton/autowrapt","tags":["monkey-patching","bootstrap","wrappers","setuptools","environment-variables"],"install":[{"cmd":"pip install autowrapt","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Autowrapt depends on `wrapt` for its underlying transparent object proxy and monkey patching capabilities.","package":"wrapt","optional":false}],"imports":[{"note":"Autowrapt's primary function is activated via the AUTOWRAPT_BOOTSTRAP environment variable, not by direct import into user application code. Internally, `autowrapt.bootstrap` contains the core logic.","symbol":"autowrapt.bootstrap","correct":"N/A (activated via env var)"}],"quickstart":{"code":"import this","lang":"python","description":"Autowrapt applies patches via environment variables and setuptools entry points. To quickly test, first define a patch in a module (e.g., `my_patch.py` with `def add_zen_line(module): print('The wrapt package is absolutely amazing and you should use it.')`). Then, in a `setup.py` in the same directory, register this as an entry point: `entry_points={'autowrapt.examples': ['my_patch = my_patch:add_zen_line']}`. Install your package in editable mode (`pip install -e .`). Finally, run your Python script with the `AUTOWRAPT_BOOTSTRAP` environment variable set to activate your patch. This example demonstrates patching Python's `this` module to add an extra line to the Zen of Python."},"warnings":[{"fix":"Always install `autowrapt` using `pip` (e.g., `pip install autowrapt` or `pip install -e .` for development).","message":"Incorrect installation method can prevent autowrapt from working. Using `python setup.py install` or `easy_install` can cause the critical `.pth` file to be installed incorrectly (e.g., inside an egg directory), preventing activation.","severity":"breaking","affected_versions":"All versions"},{"fix":"Thoroughly test patched applications. Be aware of the 'ordering problem' where other code might import a module before the patch can be applied. Consider explicit patching with `wrapt` if implicit global patching is not strictly necessary. For security, be cautious about installing packages that leverage `.pth` files.","message":"Monkey patching, especially using `.pth` files, is a powerful technique that runs code early in the Python interpreter's startup. This can introduce hard-to-debug issues related to import order, unexpected side effects, and security concerns as code runs implicitly.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review the GitHub repository for any open issues or discussions related to compatibility with modern Python versions (e.g., Python 3.9+). Consider whether its specific approach is still the best fit for current project needs or if manual `wrapt` usage or other patching techniques are more appropriate.","message":"The `autowrapt` project itself has not been updated since 2015 (version 1.0). While its core dependency `wrapt` is actively maintained, `autowrapt` may not fully leverage the latest features or address edge cases in newer Python versions or `wrapt` versions beyond what was available in 2015.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure `autowrapt` was installed with `pip`. Verify that the `AUTOWRAPT_BOOTSTRAP` environment variable exactly matches the `setuptools` entry point name for your patch. Check the timing of module imports in your application; autowrapt aims to run early, but explicit `from module import function` statements before bootstrap can prevent patches from taking effect on those specific references.","cause":"The most common causes are an incorrect installation of `autowrapt` (not using pip), a misspelled or incorrect entry point name in the `AUTOWRAPT_BOOTSTRAP` environment variable, or the target module being imported before `autowrapt`'s bootstrap mechanism can activate.","error":"Monkey patch specified in AUTOWRAPT_BOOTSTRAP is not applied or has no effect."},{"fix":"Reinstall `autowrapt` using `pip` (`pip install autowrapt`). Avoid `python setup.py install` or `easy_install`. Confirm that `autowrapt-init.pth` exists in your Python's `site-packages` directory.","cause":"This error can occur if the `autowrapt-init.pth` file is not correctly placed or processed by the Python interpreter, which is often a symptom of `autowrapt` not being installed via `pip`.","error":"Error: 'No module named autowrapt.bootstrap' or similar during Python interpreter startup."}]}