DEV Community

Cover image for Debugging : Why not pprint anymore? Introducing SetPrint: Structural Debugging for Real Data
mtur2007
mtur2007

Posted on • Edited on

Debugging : Why not pprint anymore? Introducing SetPrint: Structural Debugging for Real Data

When your data grows beyond a toy example, pprint starts to break.

You see cut-off arrays. Flattened hierarchies. Lost context.

And worst of all? Hidden bugs buried under “pretty” formatting.

That’s why I created SetPrint — a Python library that shows structure, not just values.


🔍 What this article covers

  • ✅ Side-by-side comparisons: pprint / setprint
  • ✅ Real-world examples: image data, confusion matrices
  • ✅ Benchmarks + 5 must-know tips for structured debugging

🧪 Quick Colab Demo

Want to see it in action? Try this demo notebook — no install needed.

(To use Colab, a Google account is required.)

🔗 Try this notebook on Google Colab


1. Visual Comparison — pprint vs setprint

data = {
    "users": [
        {"name": "Alice", "scores": np.array([95, 88, 76])},
        {"name": "Bob",   "scores": np.array([72, 85, 90])}
    ],
    "meta": {"created": "2025-04-23", "version": 1.2}
}
Enter fullscreen mode Exit fullscreen mode
== pprint ==
{'meta': {'created': '2025-04-23', 'version': 1.2},
 'users': [{'name': 'Alice', 'scores': array([95, 88, 76])},
           {'name': 'Bob', 'scores': array([72, 85, 90])}]}
Enter fullscreen mode Exit fullscreen mode
== setprint ==
keep_settings
['y', 'y', 'y', 'y']
--------------------------------------------------------

◆dict 
  ├── users:►list 
  │        ├───── -------.  ◆dict    
  │        │              ├─────────  name : Alice   
  │        │              └───────── scores:>ndarray 
  │        │                                ├─────── 95 
  │        │                                ├─────── 88 
  │        │                                └─────── 76 
  │        └───── -------.  ◆dict    
  │                       ├─────────  name :  Bob    
  │                       └───────── scores:>ndarray 
  │                                         ├─────── 72 
  │                                         ├─────── 85 
  │                                         └─────── 90 
  └── meta :◆dict 
           ├───── created:2025-04-23 
           └───── version:   1.2     

--------------------------------------------------------
Enter fullscreen mode Exit fullscreen mode

Even at a glance, the structure is crystal clear.


2. Image Arrays? No Problem

rgb = np.random.randint(0, 255, size=(3, 3, 3))
set_collection ( route='SLIM', y_axis=False, keep_settings={1: 'yf', 2: 'f'} )
Enter fullscreen mode Exit fullscreen mode
keep_settings
['yf', 'f', 'f']
-------------------------------------------------------------------------------------------------

>ndarray 
   ├──── >ndarray [ >ndarray [ 255  0   4  ] >ndarray [ 255 85   0  ] >ndarray [ 255 170  0  ] ] 
   ├──── >ndarray [ >ndarray [ 170 255  0  ] >ndarray [ 85  255  0  ] >ndarray [  0  255  4  ] ] 
   └──── >ndarray [ >ndarray [  0  170 255 ] >ndarray [  0  85  255 ] >ndarray [  4   0  255 ] ] 

-------------------------------------------------------------------------------------------------
Enter fullscreen mode Exit fullscreen mode

You don’t just see the values—you see the hierarchy.


3. Confusion Matrices as Text-Based Heatmaps

cm = np.array([[50, 2, 0, 0], [3, 45, 1, 0], [0, 4, 60, 5], [0, 0, 6, 70]])
set_collection ( route='SLIM', y_axis=False, keep_settings={1:'y', 2:'x'} )
Enter fullscreen mode Exit fullscreen mode
keep_settings
['y', 'x']
------------------------------

>ndarray 
   ├──── >ndarray ┬──┬──┬──┐
   │              50 2  0  0  
   ├──── >ndarray ┬──┬──┬──┐
   │              3  45 1  0  
   ├──── >ndarray ┬──┬──┬──┐
   │              0  4  60 5  
   └──── >ndarray ┬──┬──┬──┐
                  0  0  6  70 

------------------------------
Enter fullscreen mode Exit fullscreen mode

4. Benchmark: Visibility vs Speed

Library Runtime (ms) Structure Clarity
pprint 1.5 ★☆☆☆☆
rich.pretty 3.2 ★★☆☆☆
setprint 4.8 ★★★★★

A few ms extra for full visibility? Totally worth it.


5. 5 Must-Know Tips for Using SetPrint

  1. Use keep_settings = {1: 'x', 3: 'yf', 4: 'f'} for full control over dimensions
  2. Show vertical guides with y_axis=True
  3. Output is a list of lines → easy to write to file
  4. Handles mixed types: dict + list + ndarray? No problem
  5. Switch between styles like 'SLIM', 'BOLD', or even 'HALF'

6. One Function, Infinite Views

from setprint import SetPrint
list_data = SetPrint(data)

formatted = list_data.set_collection(
    keep_settings={1:'x', 2:'yf', 3:'f'},
    route='SLIM', y_axis=True
)

for line in formatted:
    print(line)
Enter fullscreen mode Exit fullscreen mode

🚀 Try it Now

pip install setprint
Enter fullscreen mode Exit fullscreen mode

🎯 If you found it useful, please consider giving a ⭐ on GitHub!
🐛 Bug reports, 💡 feature requests, and 📬 pull requests are all welcome!

📎 GitHub: mtur2007/SetPrint

📘 PyPI: setprint

🔍 Colab Demo: Try on Colab


🔗 Also available on Medium!

💬 I'd love to hear your feedback on either platform. ✨



If you’ve ever said “I just want to see the damn structure” — SetPrint is for you.

(Thank you for reading! This is my very first article introducing SetPrint to the international audience. I'd love to hear your feedback and thoughts.)

Neon image

Set up a Neon project in seconds and connect from a Python application

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Get started →

Top comments (0)

Neon image

Set up a Neon project in seconds and connect from a Python application

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Get started →

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, cherished by the supportive DEV Community. Coders of every background are encouraged to bring their perspectives and bolster our collective wisdom.

A sincere “thank you” often brightens someone’s day—share yours in the comments below!

On DEV, the act of sharing knowledge eases our journey and forges stronger community ties. Found value in this? A quick thank-you to the author can make a world of difference.

Okay