Registry / testing / devtools

devtools

JSON →
library0.12.2pypypi✓ verified 25d ago

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 devtools
INSTALL
IMPORT
SIG · DEVTOOLS
D
devtools
testingpythonv0.12.2
Install
2.4s avg
Import
10ms
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.12.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.010s · 27.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.4s · import 0.010s · 28MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

debug
from devtools import debug
debug() # without import, unless 'debug.install()' was run
The primary way to use the debug function. While `debug.install()` can add `debug` to builtins, it requires manual configuration of `sitecustomize.py`.

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.

from devtools import debug def example_function(a, b): result = a * b debug(a, b, result) return result my_list = [1, 2, {'key': 'value', 'nested': [3, 4]}] debug(my_list) example_function(10, 5) class MyClass: def __init__(self, name): self.name = name self.data = {'id': 123, 'status': 'active'} obj = MyClass('TestObject') debug(obj.name, obj.data)
Debug
Known issues
breaking`Pygments` became a mandatory dependency in `v0.12.0` (August 2023). Environments that previously used `devtools` without `Pygments` installed (and thus without syntax highlighting) will now require `Pygments` for successful installation.
fix
Ensure `pygments` is included in your project's dependencies: `pip install devtools pygments`.
affects: >=0.12.0
gotchaThe `debug()` function returns its arguments. If a single non-keyword argument is passed, it returns that argument. If multiple arguments are passed (positional or keyword), they are returned as a tuple (with a dictionary for kwargs). This differs from `print()` which always returns `None`.
fix
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`.
affects: >=0.7.0
gotchaThe `debug.install()` method, intended to add `debug` to `__builtins__` for usage without explicit import, does not directly modify your Python environment. Instead, it prints instructions for you to manually create or edit a `sitecustomize.py` file.
fix
Run `python -m devtools install` and follow the printed instructions to configure `sitecustomize.py` if you wish to use `debug()` without importing it.
affects: >=0.9.0
breakingPython-devtools does not currently support Python 3.13, which can lead to unexpected behavior or errors if used with this version.
fix
Avoid using `devtools` with Python 3.13. Check the official documentation for updates on 3.13 compatibility.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'devtools'
The 'devtools' library is not installed in your active Python environment.
fix
Run `pip install devtools` in your terminal to install the package.
NameError: name 'debug' is not defined
The 'debug' function, the primary interface for devtools, has been used without being imported into the current scope.
fix
Add `from devtools import debug` at the top of your Python file to make the function available.
AttributeError: module 'devtools' has no attribute 'debug'
You likely imported the 'devtools' module using `import devtools` and then tried to call `devtools.debug()`. The 'debug' function is designed to be imported directly from the module.
fix
Change your import statement to `from devtools import debug` and then call `debug()` directly.
devtools no output
If `debug()` calls are not producing any output, it might be due to your IDE's console configuration, output buffering, or `sys.stdout` being redirected, preventing the formatted output from being displayed.
fix
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()`).
Upgrade
Version history
0.12.2latest on PyPI · released Sep 3, 2023
Audit
Dependencies
executingrequiredUsed internally for finding and printing debug arguments, required since v0.7.0.
asttokensrequiredUsed internally for finding and printing debug arguments, required since v0.7.0.
pygmentsrequiredRequired for syntax highlighting of output, made a mandatory dependency in v0.12.0.
Agent activity
13 hits · last 30 days
node
12
Resources
devtools — pip install devtools · libregistry