============
This library provides a tree printer class for easy tree displaying
## Installation
``` sh
$ pip install treeprinter
```
## Basic usage
### Printer instance
``` python
from treeprinter import TreePrinter
class Tree(object):
def __init__(self, tag, children=None):
self.children = children or []
self.tag = tag
tree = Tree("animal", [
Tree("cat"),
Tree("dog", [Tree("chihuahua"), Tree("dalmatian")]),
Tree("wolf")])
printer = TreePrinter('children', 'tag')
printer.pprint(tree)
```
```
animal
|
---------------------------
| | |
cat dog wolf
|
----------
| |
chihuahua dalmatian
```
### Printer decorator
You could also get the same result by decorating your class like so to implement the \_\_str\_\_ method
``` python
@TreePrinter('children', 'tag')
class Tree(object):
def __init__(self, tag, children=None):
self.children = children or []
self.tag = tag
print(tree)
```
## Extensions
You can extend the library by implementing the base displayer
(see printers/json_printer.py)
``` python
from treeprinter import JsonPrinter
printer = JsonPrinter()
json = {
"fruits": ["Apple", "Banana", "Pear"],
"presidents": {
"France": ["Sarkozy", "Hollande"],
"USA": ["Trump", "Obama"]
},
"star": "Sun"
}
printer.pprint(json)
```
```
{}
|
--------------------------------------
| | |
{presidents} [fruits] star
| | |
---------------- -------------- Sun
| | | | |
[France] [USA] Apple Banana Pear
| |
--------- ------
| | | |
Sarkozy Hollande Trump Obama
```
Metadata
Release files for treeprinter 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| treeprinter-0.0.2.tar.gz | 7.1 kB | Without provenance | Details |
Release files / treeprinter-0.0.2.tar.gz
| Download URL | treeprinter-0.0.2.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
28c80ab15176ad79a64c9a87641fbe25bc991628bc722f8934ba845b74a422c3
|
|
BLAKE2b-256 checksum How to use checksums |
23acaf9d2a7e6f21923ffed0d3d9377dbdb1af4ff5b60fc95451046778767826
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for treeprinter 0.0.2
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.