Skip to content

Pretty printing for Python

License

Notifications You must be signed in to change notification settings

daniele-canavese/chroma

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo

chroma

Pretty printing for Python.

dani

python python python

OverviewInstallation and removalGetting startedReferences

🗺️ Overview

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.

🏗️ Installation and removal

chroma is managed via poetry.

Usage

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

Development

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

🧭 Getting started

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.

🗂️️ References

[1] rich, a Python library for rich text and beautiful formatting in the terminal