devtools provides an enhanced debug print command for Python, offering formatted output with file, line number, function information, and variable names. It's designed to be more readable than the standard `print()` function, especially for complex data structures. The library is actively maintained, with its current version being 0.12.2, and has a consistent release cadence.
pip install devtoolsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the core `debug()` function to print variables, expressions, and complex data structures with enhanced formatting, including file, line number, and function context. It shows usage with simple variables, lists, function arguments, and class attributes.
Ensure `pygments` is included in your project's dependencies: `pip install devtools pygments`.
Be mindful when using `debug()` in expressions or assignments, as its return value might be unexpectedly captured. Example: `val = debug(my_var)` will assign `my_var` to `val`.
Run `python -m devtools install` and follow the printed instructions to configure `sitecustomize.py` if you wish to use `debug()` without importing it.
Avoid using `devtools` with Python 3.13. Check the official documentation for updates on 3.13 compatibility.
Run `pip install devtools` in your terminal to install the package.
Add `from devtools import debug` at the top of your Python file to make the function available.
Change your import statement to `from devtools import debug` and then call `debug()` directly.
Ensure your IDE's console is correctly configured to show standard output, try running the script directly from a terminal, or explicitly flush `sys.stdout` after `debug()` calls (e.g., `import sys; sys.stdout.flush()`).