Skip to main content

TypedTree by Brett Kromkamp

Contextualise, a knowledge management application that I am currently developing, allows the user to visualise their topics of interest (that is, nodes) and the relationships between those topics (that is, references to other nodes) using a network graph visualisation. To that effect, TypedTree makes it straightforward to not only enable the visualisation of the actual (network) graph itself but also to enhance the visualisation with information related to the type of each node and the references to other nodes, respectively.

TypedTree is based on an earlier implementation of mine: Python tree implementation.

Installation

TypedTree officially supports Python 3.7–3.10. To install TypedTree, simply:

$ pip install --upgrade typed-tree

Install the Development Version

If you have Git installed on your system, it is possible to install the development version of TypedTree.

Before installing the development version, you may need to uninstall the standard version of TypedTree using pip:

$ pip uninstall typed-tree

Then do:

$ git clone https://github.com/brettkromkamp/typed-tree
$ cd typed-tree
$ pip install -e .

The pip install -e . command allows you to follow the development branch as it changes by creating links in the right places and installing the command line scripts to the appropriate locations.

Then, if you want to update TypedTree at any time, in the same directory do:

$ git pull

Example

from typedtree import TraversalMode
from typedtree import Tree

tree = Tree()

# A node without a parent pointer is by definition the root node
tree.add_node('Elon Musk', node_type='person')

tree.add_node('Lyndon Rive', parent_pointer='Elon Musk', node_type='person', edge_type='family')
tree.add_node('SpaceX', parent_pointer='Elon Musk', node_type='company', edge_type='founder')
tree.add_node('Tesla', parent_pointer='Elon Musk', node_type='company', edge_type='founder')
tree.add_node('Solar City', parent_pointer='Lyndon Rive', node_type='company', edge_type='co-founder')
tree.add_node('Solar Energy Services', parent_pointer='Solar City', node_type='product', edge_type='service')
tree.add_node('Falcon 9', parent_pointer='SpaceX', node_type='rocket', edge_type='technology')
tree.add_node('Falcon Heavy', parent_pointer='SpaceX', node_type='rocket', edge_type='technology')
tree.add_node('Dragon', parent_pointer='SpaceX', node_type='space-ship', edge_type='technology')
tree.add_node('Model S', parent_pointer='Tesla', node_type='car', edge_type='product')
tree.add_node('Model X', parent_pointer='Tesla', node_type='car', edge_type='product')
tree.add_node('Model Y', parent_pointer='Tesla', node_type='car', edge_type='product')
tree.add_node('Roadster', parent_pointer='Tesla', node_type='car', edge_type='product')

print('\n***** TREE STRUCTURE *****')
tree.display('Elon Musk')

print('\n***** DEPTH-FIRST ITERATION *****')
for node in tree.traverse('Elon Musk'):
    print(f"{node.identifier} [{node.type or '*Undefined*'}]")

print('\n***** BREADTH-FIRST ITERATION *****')
for node in tree.traverse('Elon Musk', mode=TraversalMode.BREADTH):
    print(f"{node.identifier} [{node.type or '*Undefined*'}]")

Output

***** TREE STRUCTURE *****
Elon Musk [person] - (*Undefined*)
        Lyndon Rive [person] - (family)
            Solar City [company] - (co-founder)
                Solar Energy Services [product] - (service)
        SpaceX [company] - (founder)
            Falcon 9 [rocket] - (technology)
            Falcon Heavy [rocket] - (technology)
            Dragon [space-ship] - (technology)
        Tesla [company] - (founder)
            Model S [car] - (product)
            Model X [car] - (product)
            Model Y [car] - (product)
            Roadster [car] - (product)

***** DEPTH-FIRST ITERATION *****
Elon Musk [person]
Lyndon Rive [person]
Solar City [company]
Solar Energy Services [product]
SpaceX [company]
Falcon 9 [rocket]
Falcon Heavy [rocket]
Dragon [space-ship]
Tesla [company]
Model S [car]
Model X [car]
Model Y [car]
Roadster [car]

***** BREADTH-FIRST ITERATION *****
Elon Musk [person]
Lyndon Rive [person]
SpaceX [company]
Tesla [company]
Solar City [company]
Falcon 9 [rocket]
Falcon Heavy [rocket]
Dragon [space-ship]
Model S [car]
Model X [car]
Model Y [car]
Roadster [car]
Solar Energy Services [product]

How to Contribute

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
  2. Fork the repository on GitHub to start making your changes to the master branch (or branch off of it).
  3. Write a test which shows that the bug was fixed or that the feature works as expected.
  4. Send a pull request and bug the maintainer until it gets merged and published.

Metadata

Release files for typed-tree 1.0.8

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

Source distribution (sdist)

Source distribution for typed-tree 1.0.8
File Size Uploaded Provenance Actions
typed-tree-1.0.8.tar.gz 5.2 kB Without provenance Details for typed-tree-1.0.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for typed-tree 1.0.8
File Interpreter ABI Platform Actions
typed_tree-1.0.8-py3-none-any.whl Python 3 none any Details for typed_tree-1.0.8-py3-none-any.whl

Total release size: 11.4 kB

Release files / typed-tree-1.0.8.tar.gz

Download URL typed-tree-1.0.8.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
aa3515c21f038802c69ee0883f8f60572774b42d5311d42ac0b4d98430801725
BLAKE2b-256 checksum
How to use checksums
6aef25d7ec8542d6eb174dfe63ab286f83af68a807916d8ee73c9a876a47846d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.0

Release files / typed_tree-1.0.8-py3-none-any.whl

Download URL typed_tree-1.0.8-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b51d31f1b85a09e674d15e692143ce1ffac936878f190f20ac88d2a479e14b8
BLAKE2b-256 checksum
How to use checksums
3c9ac834100a0efd246718dcfdfcbfb37a1cb8bad27265af42536e8fc65356f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.0

Security for typed-tree 1.0.8

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