{"name":"PySnooper: Effortless Python Debugging Without Print Statements","description":"PySnooper is a powerful, yet simple, debugging tool for Python that eliminates the need for manual `print` statements. By adding a single decorator, developers can get a detailed, play-by-play log of function execution, including line-by-line tracing and variable value changes. It's designed for quick integration into any codebase without extensive setup.","github":"https://github.com/cool-RR/PySnooper","url":"https://osrepos.com/repo/cool-rr-pysnooper","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/cool-rr-pysnooper","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/cool-rr-pysnooper.md","json":"https://osrepos.com/repo/cool-rr-pysnooper.json","topics":["python","debug","debugger","introspection","logging","development","tooling"],"keywords":["python","debug","debugger","introspection","logging","development","tooling"],"stars":null,"summary":"PySnooper is a powerful, yet simple, debugging tool for Python that eliminates the need for manual `print` statements. By adding a single decorator, developers can get a detailed, play-by-play log of function execution, including line-by-line tracing and variable value changes. It's designed for quick integration into any codebase without extensive setup.","content":"## Introduction\n\nPySnooper is an incredibly useful Python debugging tool that aims to completely replace the common practice of using `print` statements for debugging. Often described as \"a poor man's debugger\" or \"like `set -x` for Python, but fancier,\" PySnooper provides a detailed, play-by-play log of your function's execution. It shows which lines ran, when they ran, and precisely when local variables changed their values.\n\nThe primary advantage of PySnooper is its simplicity. Instead of carefully crafting numerous `print` lines, you just add a single decorator, `@pysnooper.snoop()`, to the function you're interested in. This makes it exceptionally easy to integrate into any existing codebase, even large and complex ones, without requiring any setup or configuration.\n\n## Installation\n\nInstalling PySnooper is straightforward using pip:\n\nconsole\n$ pip install pysnooper\n\n\nOther installation options include Conda, Arch Linux, and Fedora Linux, as detailed in the official repository.\n\n## Examples\n\nLet's see PySnooper in action. Here's an example of a function that converts a number to binary, with the `@pysnooper.snoop()` decorator applied:\n\npython\nimport pysnooper\n\n@pysnooper.snoop()\ndef number_to_bits(number):\n    if number:\n        bits = []\n        while number:\n            number, remainder = divmod(number, 2)\n            bits.insert(0, remainder)\n        return bits\n    else:\n        return [0]\n\nnumber_to_bits(6)\n\n\nWhen `number_to_bits(6)` is called, PySnooper outputs a detailed log to stderr, showing each line executed, the values of variables at each step, and the elapsed time.\n\nIf you only need to trace a specific part of a function, you can use PySnooper within a `with` block:\n\npython\nimport pysnooper\nimport random\n\ndef foo():\n    lst = []\n    for i in range(10):\n        lst.append(random.randrange(1, 1000))\n\n    with pysnooper.snoop():\n        lower = min(lst)\n        upper = max(lst)\n        mid = (lower + upper) / 2\n        print(lower, mid, upper)\n\nfoo()\n\n\nThis will generate a similar detailed log, but only for the code block wrapped by `with pysnooper.snoop()`.\n\n## Why Use PySnooper\n\nPySnooper stands out for its ease of use and powerful features:\n\n*   **Zero Setup**: Simply add the decorator or use a `with` block. No complex configuration files or debugger interfaces are needed.\n*   **Detailed Tracing**: Get a clear view of line execution order and variable changes.\n*   **Output Redirection**: Redirect the snoop output to a file, stream, or callable instead of stderr, for example: `@pysnooper.snoop('/my/log/file.log')`.\n*   **Watch Expressions**: Monitor specific expressions that are not local variables, such as `foo.bar` or `self.x[\"whatever\"]`, using `@pysnooper.snoop(watch=('foo.bar',))`.\n*   **Call Depth**: Trace into functions called by your snooped function using `depth`, for example: `@pysnooper.snoop(depth=2)`.\n\nFor more advanced options and detailed usage, refer to the official documentation.\n\n## Links\n\n*   **GitHub Repository**: [https://github.com/cool-RR/PySnooper](https://github.com/cool-RR/PySnooper){:target=\"_blank\"}\n*   **Advanced Usage Documentation**: [https://github.com/cool-RR/PySnooper/blob/master/ADVANCED_USAGE.md](https://github.com/cool-RR/PySnooper/blob/master/ADVANCED_USAGE.md){:target=\"_blank\"}","metrics":{"detailViews":9,"githubClicks":13},"dates":{"published":null,"modified":"2026-04-20T00:56:17.000Z"}}