Hunter
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.
Warnings
- breaking 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.
- gotcha 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')`.
- gotcha 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.
- gotcha 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.
- deprecated 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.
Install
-
pip install hunter
Imports
- hunter
import hunter
- CallPrinter
from hunter import CallPrinter
- Q
from hunter import Q
Quickstart
import hunter
import os
def my_function():
return os.path.join('a', 'b')
# Activate tracing for the 'os.path' module with CallPrinter action
hunter.trace(module='os.path', action=hunter.CallPrinter)
print(f"Result: {my_function()}")
# Deactivate tracing
hunter.stop()
# You can also use it with a context manager (preferred for local scope)
with hunter.trace(module='os.path', action=hunter.CallPrinter):
print(f"Result from context: {os.path.join('x', 'y')}")