{"id":2923,"library":"devtools","title":"Python's Missing Debug Print Command","description":"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.","status":"active","version":"0.12.2","language":"en","source_language":"en","source_url":"https://github.com/samuelcolvin/python-devtools","tags":["debug","logging","development tools","pretty print","diagnostics"],"install":[{"cmd":"pip install devtools","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used internally for finding and printing debug arguments, required since v0.7.0.","package":"executing","optional":false},{"reason":"Used internally for finding and printing debug arguments, required since v0.7.0.","package":"asttokens","optional":false},{"reason":"Required for syntax highlighting of output, made a mandatory dependency in v0.12.0.","package":"pygments","optional":false}],"imports":[{"note":"The primary way to use the debug function. While `debug.install()` can add `debug` to builtins, it requires manual configuration of `sitecustomize.py`.","wrong":"debug() # without import, unless 'debug.install()' was run","symbol":"debug","correct":"from devtools import debug"}],"quickstart":{"code":"from devtools import debug\n\ndef example_function(a, b):\n    result = a * b\n    debug(a, b, result)\n    return result\n\nmy_list = [1, 2, {'key': 'value', 'nested': [3, 4]}]\ndebug(my_list)\n\nexample_function(10, 5)\n\nclass MyClass:\n    def __init__(self, name):\n        self.name = name\n        self.data = {'id': 123, 'status': 'active'}\n\nobj = MyClass('TestObject')\ndebug(obj.name, obj.data)\n","lang":"python","description":"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."},"warnings":[{"fix":"Ensure `pygments` is included in your project's dependencies: `pip install devtools pygments`.","message":"`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.","severity":"breaking","affected_versions":">=0.12.0"},{"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`.","message":"The `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`.","severity":"gotcha","affected_versions":">=0.7.0"},{"fix":"Run `python -m devtools install` and follow the printed instructions to configure `sitecustomize.py` if you wish to use `debug()` without importing it.","message":"The `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.","severity":"gotcha","affected_versions":">=0.9.0"},{"fix":"Avoid using `devtools` with Python 3.13. Check the official documentation for updates on 3.13 compatibility.","message":"Python-devtools does not currently support Python 3.13, which can lead to unexpected behavior or errors if used with this version.","severity":"breaking","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}