Pretty printing for Python.
Overview • Installation and removal • Getting started • References
chroma
is a Python package for pretty printing various data with a built-in
support for colors and emojis. It is actually a wrapper around rich
[1], a
pretty printing library.
In particular, it allows you to:
- pretty print text messages with automatic highlighting of many data types such as number, strings and URLs;
- select a severity level to accentuate important information;
- nicely format tables where individual rows can be emphasized;
- use progress bars with automatic ETAs.
chroma
is managed via poetry
.
chroma
can be installed in a poetry
environment with the following command:
poetry add git+https://github.com/daniele-canavese/chroma.git
Conversely, chroma
can be uninstalled with:
poetry remove chroma
To create an environment for developing chroma
, just run the command:
poetry install
poetry shell
To remove all the development environments, execute:
poetry env remove --all
The most important function in chroma
is pprint
, which is used to pretty
print anything and can be used as a substitute to the traditional
Python's print
.
The Table
class instances represent tabular data and can be fed to pprint
as
well. In addition, the ProgressBar
class is an iterable that automatically
display a progress bar.
The examples
folder contains many commented usage examples; in particular:
examples/printing.py
shows how to pretty print various text messages;examples/progress.py
contains some progress bar instances;examples/table.py
presents different ways of printing tables.
[1] rich
, a Python library for rich text
and beautiful formatting in the terminal