Skip to main content

Tree is a library for working with nested data structures.

Project description


tree is a library for working with nested data structures. In a way, tree generalizes the builtin map function which only supports flat sequences, and allows to apply a function to each "leaf" preserving the overall structure.

>>> import tree
>>> structure = [[1], [[[2, 3]]], [4]]
>>> tree.flatten(structure)
[1, 2, 3, 4]
>>> tree.map_structure(lambda v: v**2, structure)
[[1], [[[4, 9]]], [16]]

tree is backed by an optimized C++ implementation suitable for use in demanding applications, such as machine learning models.


From PyPI:

$ pip install dm-tree

Directly from github using pip:

$ pip install git+git://

Build from source:

$ python install


If you are having issues, please let us know by filing an issue on our issue tracker.


The project is licensed under the Apache 2.0 license.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dm-tree-0.1.7.tar.gz (35.1 kB view hashes)

Uploaded source

Built Distributions

dm_tree-0.1.7-cp310-cp310-win_amd64.whl (90.9 kB view hashes)

Uploaded cp310

dm_tree-0.1.7-cp310-cp310-macosx_11_0_arm64.whl (105.0 kB view hashes)

Uploaded cp310

dm_tree-0.1.7-cp39-cp39-win_amd64.whl (90.3 kB view hashes)

Uploaded cp39

dm_tree-0.1.7-cp39-cp39-macosx_11_0_arm64.whl (105.0 kB view hashes)

Uploaded cp39

dm_tree-0.1.7-cp38-cp38-win_amd64.whl (91.0 kB view hashes)

Uploaded cp38

dm_tree-0.1.7-cp38-cp38-macosx_11_0_arm64.whl (105.2 kB view hashes)

Uploaded cp38

dm_tree-0.1.7-cp37-cp37m-win_amd64.whl (91.2 kB view hashes)

Uploaded cp37

dm_tree-0.1.7-cp36-cp36m-win_amd64.whl (91.3 kB view hashes)

Uploaded cp36

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page