Python binarytree library for tree visualization
Aug 18, 2025
Working with binary trees has two major annoyances:
- building them
- printing them
I found this library, binarytree that maps pretty close to my definition of a node:
=
=
=
but, it also lets me build trees, or represent existing trees.
Represent existing trees
For a typical sample tree, there’s no more of a need to mess around with tabs and spaces, and labour to make this understandable.
>>>
>>>
>>> =
>>>
>>>
__1______
/ \
__2 __3
/ \ /
4 5 6
\ / \
7 8 9
Creating a random tree
>>>
>>>
>>> =
>>>
____14___
/ \
9 _3__
/ \ / \
4 0 11 6
\ / \
5 7 8
Counterpoint: You’re probably not going to be able to use it in interviews. Here’s a link to a video with pragmatic suggestions for that scenario.