PySnooper is a Python debugging tool often described as a 'poor man's debugger'. It allows developers to trace the execution of their code by automatically logging variable values, function calls, and execution lines to stdout or a file, without requiring traditional breakpoints or extensive manual print statements. The current stable version is 1.2.3. Recent GitHub activity indicates ongoing maintenance, including support for newer Python versions.
pip install pysnooperVerified import paths — ran on the pinned version, not inferred.
The primary way to use PySnooper is by applying the `@pysnooper.snoop()` decorator to a function you wish to inspect. This will log a detailed trace of execution, including variable changes and lines run. You can redirect output to a file and disable colored output for better readability in text editors. Alternatively, `pysnooper.snoop()` can be used as a context manager for specific code blocks.
Use PySnooper judiciously on specific functions or code blocks where debugging is focused. Avoid using it on performance-sensitive hot paths unless absolutely necessary for debugging.
Utilize PySnooper's configuration options such as `depth` to limit tracing depth, `watch` to monitor specific expressions, or `thread_info`/`process_info` to filter output. Consider redirecting verbose output to a separate log file.
To get plain text output in a file, pass `color=False` to the `snoop` decorator or context manager, e.g., `@pysnooper.snoop(output='my_log.log', color=False)`.
Ensure PySnooper is disabled or removed from production builds. It can be globally disabled at runtime by setting the environment variable `PYSNOOPER_DISABLED=1`, which allows you to toggle it without modifying code.
pip install pysnooper
Add parentheses to call the decorator, e.g., `@pysnooper.snoop()`, or ensure the `output` parameter is a valid file path string or a file-like object like `sys.stdout`.
Correct the capitalization to lowercase `snoop`: `@pysnooper.snoop()`
Add parentheses to call the `snoop` function when using it as a context manager: `with pysnooper.snoop():`
No dependency data recorded yet.