25

Are there any python libraries for data trees?

I mean a tree as a general data structure, not just an xml tree. (Like in this question, but in python.)

Community
  • 1
  • 1
uhbif19
  • 3,139
  • 3
  • 26
  • 48
  • 6
    I believe that you need to specify what kind of tree you are looking for. Or perhaps a simple tuple/list structure would suffice? `("node", [Children nodes])` – ase Mar 14 '10 at 11:39
  • 1
    Perhaps if you did a Google search and asked specific questions about the libraries you found, we could help more. As it is, we can only guess what you're looking for. – S.Lott Mar 14 '10 at 12:03

5 Answers5

21

I'm happy with treelib. It addresses my problem. Could use a bit more documentation though. But the code is clear.

Terrence Brannon
  • 4,760
  • 7
  • 42
  • 61
17

pypi, the Python Package Index, suggests tinytree, treedict, caxes, pyavl... these are just the top few after filtering away the many accidental hits (which point to specific tree such as XML ones, AST ones, etc, etc;-). If you clarify what you want to do with your trees it may be easier to suggest a specific package.

Abhijeet
  • 8,561
  • 5
  • 70
  • 76
Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
4

Although the ETE library seems to be originally developed to work with Phylogenetic trees, it implements many general features to work with any type of hierarchical tree structures, including programmatic tree drawing and visualization.

There is a comprehensive tutorial and a reference guide, in case you want to explore it.

Marc104
  • 41
  • 1
1

python-graph seems to be a fairly thorough and complete package, and can export DOT graphs for use with Graphviz.

Inactivist
  • 9,997
  • 6
  • 29
  • 41
-5

You probably want to look at cElementTree.

Teddy
  • 6,013
  • 3
  • 26
  • 38