arbol -- Arborescent Printouts in Python
Project description
arbol -- Arborescent Printouts in Python
Do you have a script, a command line tool, or some workflow in Python that has lots of 'prints out',
and you can't make sense of it? Sounds familiar?
arbol organises your stdout prints in a hierarchy that follows the structure of your code.
Moreover, arbol measures the elpased time for each node of the tree and displays that conveniently.
Arbol means 'tree' in spanish.
Why not use a more traditional Python logging? We have made the choice of sticking to a oplain and simple scheme that matches the usage of 'print' statements
Installation
Simply use pip:
pip install arbol
Optional dependencies
If you want colors, install the ansicolors package:
pip install ansicolors
T make sure that yo get the colors on all platforms including Windows, install the colorama package:
pip install colorama
Note: both colorama and ansicolors are optional -- arbol will work fine without it installed.
Example
Here is a simple example:
from arbol.arbol import lprint, lsection, section, Arbol
# for colors, install the ansicolors package: 'pip install ansicolors',
# and for windows install the colorama package: 'pip install colorama'
# You can limit the tree depth:
Arbol.max_depth = 4
# use lprint instead of the standard print
lprint('Test')
# You can decorate functions:
@section('function')
def fun(x):
if x >= 0:
with lsection('recursive call to f'):
lprint(f"f(x)+1={fun(x-1)}")
# The context manager let's you start a 'section' i.e. a node in the tree
with lsection('a section'):
lprint('a line')
lprint('another line')
lprint('we are done')
with lsection('a subsection'):
lprint('another line')
lprint('we are done')
fun(2)
# You can deactivate the elapsed time measurement and printing:
Arbol.elapsed_time = False
fun(100)
lprint('demo is finished...')
# You can also turn off all output with one switch:
Arbol.enable_output = False
lprint('you will not see that')
Roadmap
Some ideas:
- More color styles to choose from
- Intercept stdout from C code so that printouts from libraries called from python are formatted too.
- Generate tree automatically by inspecting stack?
- Interoperability with logging package
Authors
Loic A. Royer (@loicaroyer) Ahmet Can Solak (@_ahmetcansolak)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file arbol-2020.11.1.tar.gz
.
File metadata
- Download URL: arbol-2020.11.1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77822cc2a2aa84ade3cae9ea0d97b0f4559b046cb72b2b4066fa0175049665b7 |
|
MD5 | 31ba1b97475e979dbf1dd954356dad3d |
|
BLAKE2b-256 | 3f9865d755fa900b77a5bf742c63aa2e2cb1e7738a26c205db85bf8677d8233b |
File details
Details for the file arbol-2020.11.1-py3-none-any.whl
.
File metadata
- Download URL: arbol-2020.11.1-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41329caf2f1817298f03b979adeb7ee047ebbe8f749f611b6cc93b8e6fc27b14 |
|
MD5 | 1871dd23706ad5f7d9e07f09a8ad13b5 |
|
BLAKE2b-256 | a50b0aaeac4828e370a8fcaa65924d3e0715a9f63a0d294a59424460408b0d22 |