{"id":5419,"library":"pysnooper","title":"PySnooper","description":"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.","status":"active","version":"1.2.3","language":"en","source_language":"en","source_url":"https://github.com/cool-RR/PySnooper","tags":["debugging","tracing","developer tools","diagnostics"],"install":[{"cmd":"pip install pysnooper","lang":"bash","label":"Install PySnooper"}],"dependencies":[],"imports":[{"symbol":"snoop","correct":"import pysnooper\n\n@pysnooper.snoop()\ndef my_function():\n    pass"}],"quickstart":{"code":"import pysnooper\nimport os\n\n# To demonstrate file output, create a dummy log file path\nlog_file_path = os.path.join(os.getcwd(), 'pysnooper_output.log')\n\n@pysnooper.snoop(output=log_file_path, color=False)\ndef number_to_bits(number):\n    if number == 0:\n        return [0]\n    bits = []\n    while number:\n        number, remainder = divmod(number, 2)\n        bits.insert(0, remainder)\n    return bits\n\nresult = number_to_bits(6)\nprint(f\"Result for 6: {result}\")\n\n# You can also use it as a context manager for a block of code\ndef main_logic():\n    a = 10\n    b = 20\n    with pysnooper.snoop(output=log_file_path, color=False):\n        temp = a + b\n        final = temp * 2\n    print(f\"Final value in main_logic: {final}\")\n\nmain_logic()\n\n# Cleanup (optional, for a runnable example)\n# import os\n# if os.path.exists(log_file_path):\n#     os.remove(log_file_path)\n","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"PySnooper can introduce noticeable performance overhead, especially in performance-critical sections or with extensive loops/execution. This is due to the detailed logging and introspection it performs.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"For complex functions, deep call stacks, or extensive loops, PySnooper's output can become extremely verbose and difficult to parse. This might make it harder to find the relevant debugging information amidst a large volume of logs.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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)`.","message":"When redirecting PySnooper's output to a file, the default colored output (ANSI escape codes) can make the log file unreadable in standard text editors. These escape codes are meant for terminal display.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"PySnooper is designed for debugging and is not suitable for production environments. Leaving it enabled can expose internal state, negatively impact performance, and fill disk space with logs. It also adds a dependency that is only useful during development.","severity":"breaking","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}