Skip to content

daniele-canavese/chroma

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo

chroma

Pretty printing for Python.

dani

python python python

OverviewInstallation and removalQuick startReferences

🗺️ 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 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.

I want to use it as a package

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.git

Conversely, chroma can be uninstalled with:

poetry remove chroma

I want to develop it

To create an environment for developing chroma, just run the command:

poetry install

To test chroma you can also launch all the test cases with:

poetry run pytest

Instead, to completely remove the development environment, execute:

poetry env remove --all

🔥 Quick start

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

Contributors

Languages