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

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logo

chroma

Pretty printing for Python.

dani   python   Codacy Badge

OverviewInstallation and removalGetting started

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:

  • nicely format tables where individual rows can be emphasized;
  • 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;
  • use progress bars with automatic ETAs.

Installation and removal

chroma can be easily installed via conda (or pipenv).

Development environment

If you want to create an environment for developing chroma, just run the command:

conda env create --file environment.yml

And to remove this environment launch:

conda remove --name chroma --all

Adding a dependency

If, instead, you want to use chroma in one of your projects, just add the following dependencies in your conda's environment.yaml:

  - pip
  - pip:
      - "--editable=git+https://ACCESS_TOKEN@github.com/daniele-canavese/chroma.git#egg=chroma"

Where ACCESS_TOKEN is you GitHub's access token.

Conversely, chroma can be uninstalled with:

conda uninstall chroma

Getting started

The most important function in chroma is pprint, which is used to pretty print anything. The Table instances obviously 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 of chroma. 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.