{"id":7731,"library":"snoop","title":"Snoop","description":"Snoop is a powerful Python library that provides detailed insights into code execution with minimal effort. It serves as a more featureful and refined alternative to traditional print debugging and PySnooper, incorporating its own version of 'icecream' for enhanced output. Currently at version 0.6.0, the library is actively maintained and designed for easy use in tracing function calls, variable values, and overall code flow.","status":"active","version":"0.6.0","language":"en","source_language":"en","source_url":"https://github.com/alexmojaki/snoop","tags":["debugging","developer tools","tracing","print debugging","diagnostics","observability"],"install":[{"cmd":"pip install snoop","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for the @spy decorator, which combines snoop with the birdseye debugger for enhanced visual debugging.","package":"birdseye","optional":true}],"imports":[{"symbol":"snoop","correct":"from snoop import snoop"},{"note":"The pp object is typically imported directly from the snoop package.","wrong":"import snoop.pp","symbol":"pp","correct":"from snoop import pp"},{"note":"The spy decorator is imported directly from the top-level snoop package, not a submodule. Requires 'birdseye' package to be installed.","wrong":"from snoop.spy import spy","symbol":"spy","correct":"from snoop import spy"},{"note":"Global configuration for snoop is done via the 'install' function, not a 'configure' method on the main snoop object.","wrong":"snoop.configure()","symbol":"install","correct":"from snoop import install"}],"quickstart":{"code":"from snoop import snoop\n\n@snoop\ndef calculate_total(prices, tax_rate):\n    total = sum(prices)\n    tax = total * tax_rate\n    final_total = total + tax\n    return final_total\n\nprices_list = [10, 20, 30]\nrate = 0.08\nresult = calculate_total(prices_list, rate)\nprint(f\"Final Total: {result}\")\n","lang":"python","description":"Demonstrates the basic usage of the `@snoop` decorator to automatically trace the execution and display variable values within a function. The output is sent to `stderr` by default."},"warnings":[{"fix":"Consult the snoop documentation for correct argument names and usage. For global configuration, use `snoop.install(out=..., prefix=..., columns=...)`.","message":"Snoop's API differs from PySnooper. Specifically, arguments like 'output', 'thread_info', 'prefix', and 'overwrite' are passed to `snoop.install()` or handled as `snoop` decorator arguments with different names (e.g., 'out' instead of 'output', 'columns' for thread info).","severity":"breaking","affected_versions":"All versions since 0.1.0 (initial release) compared to PySnooper"},{"fix":"Use `@snoop` for general debugging. Only use `@spy` when the enhanced visual debugging of `birdseye` is strictly necessary and performance is not a primary concern. Ensure 'birdseye' is installed separately via `pip install birdseye`.","message":"The `@spy` decorator (which integrates with `birdseye`) incurs a significant performance overhead and should be used cautiously, especially in functions with many loop iterations or performance-critical sections.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Redirect output using `snoop.install(out=sys.stdout)` to print to standard output, or `snoop.install(out='path/to/log.txt', overwrite=True)` to write to a file.","message":"By default, `snoop` outputs its trace to `sys.stderr`. If you are running scripts where `stderr` is not visible or captured, you might not see any output.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your project is running on Python 3.8 or newer.","message":"Snoop is explicitly designed for Python >=3.8. Attempting to use it with older Python versions (e.g., Python 2.7) will result in syntax errors or `ModuleNotFoundError`.","severity":"gotcha","affected_versions":"<=3.7"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Add `from snoop import snoop` at the top of your file. Alternatively, for global availability, use `from snoop import install` and call `install()` (e.g., `install(builtins=True)` to make `snoop` directly available).","cause":"The `snoop` decorator or function was used without being imported first.","error":"NameError: name 'snoop' is not defined"},{"fix":"Install the `birdseye` dependency: `pip install birdseye`.","cause":"The `@spy` decorator was used, but the `birdseye` library, which it depends on, is not installed.","error":"ModuleNotFoundError: No module named 'birdseye'"},{"fix":"For global output configuration, use `from snoop import install` and then `install(out='your_file.log')`. The `@snoop` decorator itself does not take an `out` argument directly.","cause":"You are attempting to use PySnooper's `output` argument with `snoop`, which uses a different parameter name (`out`) and context for global configuration.","error":"TypeError: snoop() got an unexpected keyword argument 'output'"},{"fix":"Explicitly direct snoop's output to `sys.stdout` or a file using `from snoop import install` and then `install(out=sys.stdout)` or `install(out='debug.log', overwrite=True)`.","cause":"Snoop's output defaults to `sys.stderr`. In some environments or execution contexts (e.g., IDEs, certain CI/CD pipelines), `stderr` might not be directly displayed or captured where you expect.","error":"No snoop output appears in the console."}]}