
PySnooper
A Python decorator that logs which lines run and how local variables change, instead of print statements.
- Stars
- 16.6k
- Forks
- 972
- Licence
- MIT
- Language
- Python
- Last update
- 5 months ago
- Type
- Library
What it is
PySnooper is a small Python library for debugging. You add a single decorator line to a function, and it prints a step-by-step log showing which lines ran, when they ran, and when local variables changed. It can also wrap just part of a function in a with block, and the output can go to stderr or a log file.
- Add @pysnooper.snoop() to a function to see its line-by-line execution and variable changes
- Wrap a section of code in a with pysnooper.snoop(): block to trace only that part
- Send the trace to a log file by passing a path to snoop()
- Use depth=2 to also trace functions that the decorated function calls
Great for
- Developers who want quick insight into a function without setting up a full debugger
- People debugging code in a large existing codebase where setup is inconvenient
- Beginners who are used to print-based debugging and want a more structured trace
- Anyone wanting to see values of expressions like attributes or dict lookups via the watch option
Not ideal for
- People who need breakpoints, stepping, or interactive inspection; PySnooper only produces a log
- Teams debugging performance-sensitive code, since the README does not describe its overhead and tracing adds output
- Non-Python projects, since it only works with Python code
How to get it
- 1
Install with a package manager
You'll need: Python
Install with pip
pip install pysnooper - 2
Run it
- Install the package with pip install pysnooper
- Import pysnooper in your script
- Add @pysnooper.snoop() above the function you want to trace
- Run the script and read the trace on stderr
- 3
Get the most out of it
- Pass a file path to @pysnooper.snoop() to keep traces out of the terminal
- Use watch=(...) to log values of expressions that are not local variables
- Use depth=2 to include traces from functions called by your function
- See ADVANCED_USAGE.md in the repository for further options
Downloads
Strengths
- Requires only one decorator line, with no separate debugger setup
- Shows when each local variable changes, not just its value at one moment
- Output can be redirected to a file, stream, or callable
Trade-offs
- It is a logging tool, so it cannot pause execution or step through code interactively
- The README is brief about performance impact and limitations, so details are in ADVANCED_USAGE.md which was not provided
- Output can be verbose for large functions
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| PySnooper (this) | 16.6k | Library | beginner | 5 months ago | Developers who want quick insight into a function without setting up a full debugger |
| icecream | 10.1k | Library | beginner | 17 days ago | Python developers who add print() statements to debug code |
| debug | 11.5k | Library | beginner | 23 days ago | Node.js developers who want named, toggleable log output instead of plain console.log calls |
| logrus | 25.8k | Library | beginner | 1 months ago | Go developers with existing code that already uses Logrus |
| zap | 24.7k | Library | beginner | 2 months ago | Go developers building services that log heavily |
| loguru | 24.2k | Library | beginner | 12 days ago | Python developers who want logging without much setup |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.