Skip to main content
tree_output
===========

[![Build Status](https://travis-ci.org/ewiger/tree_output.svg?branch=master)](https://travis-ci.org/ewiger/tree_output)


Python library to simplify building of tree output with command-line interfaces.

Supported output format options are:

- json
- ascii
- ansi
- null

examples
--------


```python
tree_output = HierarchicalOutput.factory('ansi')
import colorama

tree_output.emit('foo')
tree_output.add_level()
tree_output.emit('foO')
tree_output.add_level()
tree_output.emit('bar')

tree_output.add_level()
for num in range(10):
tree_output.emit(num)
tree_output.emit(10, closed=True)
tree_output.remove_level()

tree_output.emit('baz', closed=True)
tree_output.emit('foo2')


```

this will draw a colorful ANSI output like this

```
.
├── foo
│   ├── foO
│   │   ├── bar
│   │   │   ├── 0
│   │   │   ├── 1
│   │   │   ├── 2
│   │   │   ├── 3
│   │   │   ├── 4
│   │   │   ├── 5
│   │   │   ├── 6
│   │   │   ├── 7
│   │   │   ├── 8
│   │   │   ├── 9
│   │   │   └── 10
│   └── baz
├── foo2

```

logging
-------

Another option is to integrate with logging and pass hierarchical meta instructions via optional **extra** argument, e.g.

```python
houtput = HierarchicalOutput.factory(format='json')
#houtput = HierarchicalOutput.factory(format='ansi')
handler = HierarchicalOutputHandler(houtput=houtput)
logger = logging.getLogger('foo')
logging.root.addHandler(handler)
# Emission.
logger.info('foo')
logger.info('bar', extra={'add_hlevel': True})
logger.info('foo2')
logger.info('bar', extra={'add_hlevel': True})
logger.info('foo2')
logger.info('Numbers', extra={'add_hlevel': True})
for num in range(10):
logger.warn(num)
logger.warn('end of numbers', extra={'hclosed': True})
logger.debug('level up', extra={'remove_hclosed': True})
```

produces

```json
["foo", [
"bar", "foo2", ["
bar", "foo2", [
"Numbers",
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"end of numbers"
],
"level up"]
]
]
```

tests
-----

For tests we use *nose*, i.e. usage would be:

```bash
cd tests && nosetests
```

Metadata

Release files for tree_output 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tree_output 0.1.4
File Size Uploaded Provenance
tree_output-0.1.4.tar.gz 4.4 kB Without provenance Details

Release files / tree_output-0.1.4.tar.gz

Download URL tree_output-0.1.4.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
af7e43811a1f3b577ec43adc75720a5fb9bad05b76b97eecf583cc4a51aba0e7
BLAKE2b-256 checksum
How to use checksums
af5f9fe4327b99796f12e5a418e6698b301a1eae8c2c28dbeff41827419ef5ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for tree_output 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page