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 makes use of poetry to install its dependencies. If you are using a Debian-like OS you can install them via
the following commands:
sudo apt install python3 pipx
pipx install poetry
poetry self add poetry-plugin-shell # Optional, but useful.If you want to use chroma as a package in a poetry-managed project , you can install it with the following command:
poetry add git+https://github.com/daniele-canavese/chroma.gitConversely, chroma can be uninstalled with:
poetry remove chromaTo create an environment for developing chroma, just run the command:
poetry installTo test chroma you can also launch all the test cases with:
poetry run pytestInstead, to completely remove the development environment, execute:
poetry env remove --allThe 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.pyshows how to pretty print various text messages;examples/progress.pycontains some progress bar instances;examples/table.pypresents different ways of printing tables.
- [1]
rich