{"id":4043,"library":"hunter","title":"Hunter","description":"Hunter is a flexible code tracing toolkit for debugging, logging, and inspection, not for code coverage. It offers a simple Python API, a convenient terminal API, and a CLI tool. The library is currently at version 3.9.0 and is actively maintained with a regular release cadence.","status":"active","version":"3.9.0","language":"en","source_language":"en","source_url":"https://github.com/ionelmc/python-hunter","tags":["tracing","debugging","profiling","inspection","toolkit"],"install":[{"cmd":"pip install hunter","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"hunter","correct":"import hunter"},{"note":"Commonly accessed as hunter.CallPrinter after importing hunter directly.","symbol":"CallPrinter","correct":"from hunter import CallPrinter"},{"note":"Used for building complex filters. Commonly accessed as hunter.Q after importing hunter directly.","symbol":"Q","correct":"from hunter import Q"}],"quickstart":{"code":"import hunter\nimport os\n\ndef my_function():\n    return os.path.join('a', 'b')\n\n# Activate tracing for the 'os.path' module with CallPrinter action\nhunter.trace(module='os.path', action=hunter.CallPrinter)\n\nprint(f\"Result: {my_function()}\")\n\n# Deactivate tracing\nhunter.stop()\n\n# You can also use it with a context manager (preferred for local scope)\nwith hunter.trace(module='os.path', action=hunter.CallPrinter):\n    print(f\"Result from context: {os.path.join('x', 'y')}\")","lang":"python","description":"This example demonstrates how to activate Hunter to trace calls within the 'os.path' module using the `CallPrinter` action, both explicitly and via a context manager for localized tracing. Remember to call `hunter.stop()` when tracing is no longer needed to avoid overhead."},"warnings":[{"fix":"Explicitly specify `action=hunter.CallPrinter` or `action=hunter.CodePrinter` for desired output behavior.","message":"The default action for `hunter.trace()` changed in Hunter 2.0. Before 2.0, `CodePrinter` was the default; `CallPrinter` is now generally used or explicitly set for detailed output.","severity":"breaking","affected_versions":"<2.0"},{"fix":"Use the Python `~` operator with a `hunter.Q` object for negation (e.g., `hunter.trace(~hunter.Q(module='my_module'))`).","message":"Hunter does not provide a direct negation operator for filters. To negate a filter, you must negate a `Query` object, e.g., `~Q(module='re')`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you can reproduce the scenario while Hunter is actively tracing, or integrate it into your test suite for automated tracing during execution.","message":"Hunter is designed for live code tracing and does not inherently store execution data. It is not suitable for 'post-mortem' debugging if the problem cannot be reproduced while Hunter is active.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Filter by `module` with operators, or implement a custom filter function (a callable that receives an `Event` object) for more specific tracing needs.","message":"The library does not offer specialized filters for broader concepts like 'packages', or for granular details like 'function arguments' or 'return values' directly. Filtering is primarily done at the module level or requires custom filter functions.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to Python 3.9 or higher (as per current `requires_python`) or use an older `hunter` version compatible with Python 2.x (e.g., `<3.4.0`).","message":"Support for Python 2.7 was officially dropped in version 3.4.0. Users attempting to use Hunter with Python 2.x environments will encounter installation or runtime issues.","severity":"deprecated","affected_versions":">=3.4.0"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}