skillfed

dm-tree

Tree is a library for working with nested data structures.

dm-tree v0.1.10 5.7M downloads/30d#2,050 on PyPI1,022
Permissive license Apache 2.0 Active released

What it is and what it does

dm-tree is a library for manipulating nested data structures—dictionaries, lists, tuples, and their combinations—by applying operations uniformly to leaf values while preserving the overall container structure. It generalizes Python's built-in `map` function from flat sequences to arbitrarily nested hierarchies. The core operations are `flatten` (convert a nested structure to a flat list), `map_structure` (apply a function to each leaf), and traversal utilities. The implementation is backed by optimized C++ code designed for performance-critical applications like machine learning pipelines that process large nested tensors or parameter trees.

The package depends on absl-py, attrs, numpy, and wrapt, and targets modern Python (3.10+). It is actively maintained, with recent releases and no known security vulnerabilities. The library is particularly useful in machine learning frameworks where nested structures of tensors or parameters are common, though it applies to any domain working with complex hierarchical data.

Use it for:

  • Flatten nested parameter dictionaries in machine learning models for batch processing or serialization.
  • Apply transformations uniformly across all leaves of a nested tensor structure while preserving hierarchy.
  • Traverse and validate deeply nested configuration or data structures in data pipelines.
  • Convert between nested and flat representations when interfacing with APIs that expect one or the other.
  • Implement recursive operations on tree-like data without manual recursion boilerplate.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides utilities for working with nested data structures—flattening, mapping functions across leaves, and traversing trees while preserving structure—backed by an optimized C++ implementation.

Yes. dm-tree is actively maintained, has no security vulnerabilities, carries a permissive Apache 2.0 license, and solves a genuine problem in working with nested structures. The medium install friction (compiled wheels) is well-mitigated by broad platform coverage and modern Python support. Install it if your code regularly manipulates nested dicts, lists, or mixed hierarchies—especially in machine learning or data processing contexts.

Install

dm-tree on PyPI

pip

pip install dm-tree

uv

uv add dm-tree

poetry

poetry add dm-tree

Installing dm-tree

Before you install

Medium install friction due to compiled C++ components requiring platform-specific wheels; however, wheels are available for modern Python versions (3.10–3.14) across macOS, Linux (x86_64 and aarch64), and Windows, and the package is actively maintained with a recent release.

License in practice

Licensed under Apache 2.0 (permissive), allowing free use, modification, and distribution in both open-source and commercial projects with minimal restrictions.

Quickstart

pip install dm-tree

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

Requires Python 3.10 or later; installation pulls in absl-py, attrs, numpy, and wrapt as runtime dependencies.

Verify before relying

  • Whether the C++ backend provides measurable performance gains for typical use cases versus pure Python alternatives.
  • API stability guarantees or backward-compatibility policy given the Beta development status.

Package facts

License Apache 2.0 (permissive)
Python support supports the current Python release (>=3.10)
Install friction medium — platform-specific wheel
Runtime dependencies 4 — absl-py, attrs, numpy, wrapt
Maintenance actively maintained — 136 days since the last release
Last repo commit
First released
Downloads 5,699,060/month — #2,050 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: dm_tree-0.1.10-cp310-cp310-macosx_10_9_universal2.whl; dm_tree-0.1.10-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; dm_tree-0.1.10-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; dm_tree-0.1.10-cp310-cp310-win_amd64.whl; dm_tree-0.1.10-cp311-cp311-macosx_10_9_universal2.whl; dm_tree-0.1.10-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; dm_tree-0.1.10-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; dm_tree-0.1.10-cp311-cp311-win_amd64.whl; dm_tree-0.1.10-cp312-cp312-macosx_10_13_universal2.whl; dm_tree-0.1.10-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; dm_tree-0.1.10-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; dm_tree-0.1.10-cp312-cp312-win_amd64.whl; dm_tree-0.1.10-cp313-cp313-macosx_10_13_universal2.whl; dm_tree-0.1.10-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; dm_tree-0.1.10-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; dm_tree-0.1.10-cp313-cp313t-macosx_10_13_universal2.whl; dm_tree-0.1.10-cp313-cp313t-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; dm_tree-0.1.10-cp313-cp313t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; dm_tree-0.1.10-cp313-cp313-win_amd64.whl; dm_tree-0.1.10-cp314-cp314-macosx_10_15_universal2.whl

Keywords: tree, nest, flatten

Development Status :: 4 - BetaIntended Audience :: DevelopersIntended Audience :: Science/ResearchLicense :: OSI Approved :: Apache Software LicenseProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Scientific/Engineering :: MathematicsTopic :: Software Development :: Libraries

Tags

nested data structure traversaltree flattening and mappingrecursive structure manipulationleaf-wise function applicationnested dict and list handlingtree utilities librarystructure-preserving map
nested-structurestree-traversalmachine-learning

More Libraries packages