{"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":"python","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,"search_vec":"'0.12.2':55 'activ':48 'cadenc':61 'command':6,13 'complex':42 'consist':59 'current':52 'data':43 'debug':4,11,62 'design':30 'develop':64 'devtool':7 'diagnost':68 'enhanc':10 'especi':40 'file':20 'format':17 'function':23,39 'inform':24 'librari':46 'line':21 'log':63 'maintain':49 'miss':3 'name':27 'number':22 'offer':16 'output':18 'pretti':66 'print':5,12,38,67 'provid':8 'python':1,15 'readabl':34 'releas':60 'standard':37 'structur':44 'tool':65 'variabl':26 'version':53","created_at":"2026-04-11T09:13:24.428807+00:00","updated_at":"2026-04-16T06:18:53.446906+00:00","problems":[{"fix":"Run `pip install devtools` in your terminal to install the package.","cause":"The 'devtools' library is not installed in your active Python environment.","error":"ModuleNotFoundError: No module named 'devtools'"},{"fix":"Add `from devtools import debug` at the top of your Python file to make the function available.","cause":"The 'debug' function, the primary interface for devtools, has been used without being imported into the current scope.","error":"NameError: name 'debug' is not defined"},{"fix":"Change your import statement to `from devtools import debug` and then call `debug()` directly.","cause":"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.","error":"AttributeError: module 'devtools' has no attribute 'debug'"},{"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()`).","cause":"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.","error":"devtools no output"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.12.2","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/samuelcolvin/python-devtools","docs":"https://python-devtools.helpmanual.io","changelog":"https://github.com/samuelcolvin/python-devtools/releases","pypi":"https://pypi.org/project/devtools/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-28","install_tag":null}}