python-devtools
Python's missing debug print command, plus pretty formatting, timing, and pytest helpers.
Repository Health
Technical Analysis
python-devtools (imported as devtools) provides a smarter replacement for Python’s print when debugging. Its debug() function prints the file, line, and variable name alongside the value, applies rich syntax-highlighted pretty formatting, and detects the type of each expression, turning ad-hoc print debugging into something genuinely readable.
Beyond debug(), the package bundles a suite of developer utilities: a pretty-printer, an execution timer, ANSI color helpers, and a pytest plugin featuring insert_assert for automatically generating test assertions. It is fully type-annotated and works across supported Python 3 versions.
What You Get
- A
debug()function that prints file, line, variable name, value, and type - Rich, syntax-highlighted pretty formatting of nested and complex data structures
- A
Timerutility for quick execution timing during development - A pytest plugin with
insert_assertto auto-generate assertions from runtime values - Full type annotations (
py.typed) and a small, focused dependency set
Common Use Cases
- Replacing scattered print statements with informative, self-labeling debug output
- Pretty-printing deeply nested dictionaries, lists, and objects while exploring data
- Auto-generating and updating test assertions in pytest via insert_assert
Under The Hood
Architecture - The devtools package centers on debug.py, which builds a Debug object that inspects the calling frame using executing and asttokens to recover the exact source expression passed to debug(). Formatting is handled by prettier.py (with Pygments-based highlighting via ansi.py), timing by timer.py, and pytest integration by pytest_plugin.py; a __main__.py allows module-level invocation.
Tech Stack - Pure Python (>=3.7), built with hatchling, depending on executing (for locating the call expression), asttokens (AST source mapping), and Pygments (syntax highlighting). Documentation is built with MkDocs.
Code Quality - The project is production-stable with a comprehensive pytest suite (test_main.py, test_prettier.py, test_expr_render.py, test_insert_assert.py, and more), codecov coverage tracking, and CI on GitHub Actions. The code is fully typed and ships py.typed.
API Design - The headline API is a single, memorable debug() call that just works as a drop-in for print, with no configuration required. Additional tools (Timer, the pytest plugin) follow small, discoverable interfaces, and the hosted documentation site keeps the learning curve minimal.