Issues with Existing Formatting Tools
When working with data structures like lists or NumPy arrays in Python,
the standard print
or pprint
, or even external tools like rich
, often fail to provide a clear view of the entire structure,
especially when dealing with multi-dimensional arrays or deeply nested data, making it easy to lose track of which element corresponds to which.
Let's consider the following example as an illustration.
📋 Example Array 1
sample = [
{"user": {"id": 1, "name": "Alice", "scores": [95, 88, 76]}},
{"user": {"id": "002b", "name": "Bob", "scores": [72, 85, 90]}},
{"bug_user": {"id": [3], "name": "Charlie", "scores": [100, [50, 40], 70]}},
]
❓ Why does it become hard to read?
— The “Pitfalls” of Data Structures
Python's lists, dictionaries, and NumPy arrays are fine to work with for simple structures.
However, with slightly more complex nesting or
structures that spread across multiple directions,
it quickly becomes difficult to tell where each element is or what it corresponds to.
Typical reasons for poor readability:
- Different string lengths cause misalignment and line breaks
- Lists inside dictionaries and dictionaries inside lists...
- Logs that get deep in the vertical direction
- Data that spreads out horizontally, like tables or image data
- Irregular hierarchical structures
In other words, due to structural differences and variations in string lengths,
you end up with misaligned positions or line breaks for information that should be aligned.
👇 Does this look familiar for the data you commonly work with?
Try running the example array above with pprint
:
[{'user': {'id': 1, 'name': 'Alice', 'scores': [95, 88, 76]}},
{'user': {'id': '002b', 'name': 'Bob', 'scores': [72, 85, 90]}},
{'bug_user': {'id': [3], 'name': 'Charlie', 'scores': [100, [50, 40], 70]}}]
SetPrint: A Tool That Does Better Than pprint
While pprint
struggles with multi-dimensional arrays and deeply nested data, setprint
easily visualizes this for you.
Let's compare how setprint
handles the same data.
Using setprint
with Vertical (Y-direction) Expansion
keep_settings
['y', 'y', 'y', 'y', 'y']
---------------------------------------------------
►list
├── ◆dict
│ └── user :◆dict
│ ├─────── id : 1
│ ├─────── name : Alice
│ └─────── scores: ►list
│ ├─────── 95
│ ├─────── 88
│ └─────── 76
├── ◆dict
│ └── user :◆dict
│ ├─────── id : 002b
│ ├─────── name : Bob
│ └─────── scores: ►list
│ ├─────── 72
│ ├─────── 85
│ └─────── 90
└── ◆dict
└── bug_user:◆dict
├─────── id : ►list
│ └─────── 3
├─────── name :Charlie
└─────── scores: ►list
├─────── 100
├─────── ►list
│ ├── 50
│ └── 40
└─────── 70
---------------------------------------------------
🔥 The strengths of setprint
compared to pprint
- The differences in data types (number, string, list) for
id
are immediately clear - The differences between
user
andbug_user
stand out - Nested lists (like the second list inside
scores
) are clearly visible with connecting lines
Using X-direction (Horizontal) Expansion
keep_settings
['y', 'y', 'x', 'x', 'x']
-----------------------------------------------------------------------------------
►list
├── ◆dict
│ └── user :◆dict ───┬────────────┬────────────┐
│ id: 1 name: Alice scores:►list ─┬────┬─────────┐
│ 95 88 76
├── ◆dict
│ └── user :◆dict ───┬────────────┬────────────┐
│ id:002b name: Bob scores:►list ─┬────┬─────────┐
│ 72 85 90
└── ◆dict
└── bug_user:◆dict ───┬────────────┬────────────┐
id:►list ┐ name:Charlie scores:►list ─┬────┬─────────┐
3 100 ►list ┬──┐ 70
50 40
------------------------------------↑------------------------------------- ↑ ↑ ----
🧠 By including horizontal (X-direction) expansion, comparisons between arrays become possible
-
id
,name
, andscores
are aligned horizontally, making direct field comparisons easy - Misalignments or discrepancies are immediately noticeable
Aspect | Description |
---|---|
The contents of the user dictionary (id , name , scores ) are aligned horizontally
|
Visualizing field relationships in one line is easy to grasp |
The same keys (id , name , scores ) are aligned in a straight line
|
Comparing items is super easy |
The scores list is expanded horizontally |
Values like (95, 88, 76) are easy to compare in this arrangement |
It’s immediately clear that bug_user has a different structure for id (it's a list)
|
Type discrepancies are instantly visible |
Nested lists inside scores (50, 40) are naturally visible |
Nested anomalies are intuitively understood |
setprint
uses an advanced feature called Y/X Expansion Control.
This allows for high flexibility in visualizing structured data, such as logs or 2D arrays like images, as well as arrays containing such structures.
You can define the expected structure and visualize complex, multi-dimensional, and irregular data effortlessly.
Additionally,
depending on the settings, comparisons between colonies
can be visualized,
making it more effective than tools like pprint
or rich
for debugging and visualizing data with complex structures or irregularities.
If you feel that existing formatting tools are lacking,give setprint
a try.
Try SetPrint on Google Colab
Want to try setprint
yourself? Click the link below to run the example code directly in your browser without needing to install anything.
The next major update will be ver 1.0.0.
Upcoming features:
- Warnings and outputs for array abnormalities at different levels (Low🟢: Length mismatch, Medium🟡: Data type mismatch, High🟥: Dimensional mismatch)
- Number formatting and string quoting for alignment and display alignment (Left: Center: Right)
- Improvements in root connection lines for dictionary types
- Enhanced customizability for connection lines, Y-axis lines, and spacing between elements
As of May 2025, setprint
has been publicly available for 6 months, with the full version of expansion control nearing its first month.
The author and the library are still developing, so your feedback, bug reports, and suggestions for new features would be greatly appreciated!
Particularly, any comments or feedback on expansion control would be extremely helpful.