cemir_print
A colorful printing library for Python that makes terminal messages readable and easy to tell apart.
cemir_print is a small library that prints Python data to the terminal, colored by type. It shows dictionaries and lists with their nested structure indented, and writes the data type next to every value. I wrote it in October 2023 and published it on PyPI as cemir-print.
Purpose
While debugging, when I printed a dictionary or a list with print(), it became hard to tell which value belonged to which key and what type each value was, especially in nested structures. For example, the string "35" and the number 35 look the same on screen. I made cemir_print to print data in a way that shows both its structure and its types.
How it works
The library's only function is ccprint. The function looks at the type of the data it is given. If the data is a dictionary, it prints each key in yellow. If the value is itself a dictionary or a list, it writes the type next to the key and calls itself again one level further indented. If the value is a simple type, it prints the value in that type's color, followed by the type name in parentheses. In lists, the index of each element is shown in yellow and the element in the color of its own type. In nested structures, each level starts one tab further in.
Colors are fixed per type. Strings appear in green, dictionaries in red, lists in cyan, integers in purple, floats in coral and booleans in a pink tone. When an unknown type is found, or an error happens while printing, the data is printed as it is with print().
Key features
- It shows the data type next to every value, so values that could be confused, such as a string and a number, are told apart right away.
- It indents nested dictionaries and lists, which makes the depth of the structure visible.
- For types it does not recognize, it falls back to normal printing instead of raising an error.
Technical stack
The code is a single Python file with no external dependencies. Colors come from ANSI escape codes, which are special character sequences that tell the terminal what color to show text in. The package was prepared with setuptools and is distributed under the MIT license.
Status
The library has not been updated since the releases published within a few days in October 2023. A similar colored printing function also exists under the name cprint in the cemirutils library, published in 2024.
Use cases
- It can be used to see structure and types together when looking into API responses and configuration dictionaries.
- It helps show people learning Python the difference between data types visually.
- Category
- Python libraries
- Year
- 2023
Technologies
- Python
- PyPI