Displays pie charts in your terminal. This is a direct python rewrite of the Ruby Gem TTY-Pie. Maybe someone else would find this usefull as well. It requires no external dependencies and supports ASCII and HEX color codes as well as automatic generation of random colors.
python -m pip install term-piechart
from term_piechart import Pie
requests = [
{"name": "GET", "value": 9983},
{"name": "POST", "value": 7005},
{"name": "DELETE", "value": 3323},
{"name": "PUT", "value": 2794},
{"name": "PATCH", "value": 1711},
]
pie = Pie(
requests,
radius=5,
autocolor=True,
autocolor_pastel_factor=0.7,
legend={"line": 0, "format": "{label} {name:<8} {percent:>5.2f}% [{value}]"},
)
More in examples
data
(default:[]
): A list of dicts with following elements representing the slicesname
: Name of the elementvalue
: Value of the elementfill
(default:•
): String to fill the slice withcolor
: Hexcode or ANSII Colorname
radius
(default:10
): Amount of columns/rows as the radius to change sizeautocolor
(default:False
): Can be enabled if there are no colors specified in thedata
dictautocolor_pastel_factor
(default:0
): Can be increased until 1fill
(default:•
): Overwrite the fill symboll for every elementlegend
(default:True
): Can be disabled viaFalse
or configured with a dict with those keys:line
(default:1
): Number of lines between legend elementsleft
(default:4
): Number of spaces between chart and left of legendformat
(default:{label} {name} {percent:.2f}
): Supports{value}
as well
aspect_ratio
(default:2
): Aspect ratio of the printed charttop
(default:None
): Amount of rows from top of the visible terminalleft
(default:None
): Amount of columns from the left of the visible terminal
term-piechart is a direct python derivate of:
- Original Ruby Library Piotr Murachs - TTY:Pie
- Generation of Random Colors Andrew Dewes - Distant Colors
There's a minimal tox.ini with a requirement on pyenv and un-def/tox-pyenv-redux. Zsh users can use this as a reference.
curl https://pyenv.run | bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
. ~/.zshrc
pyenv install -s 3.12 3.11 3.10 3.9 3.8
tox