--- id: dm-tree version: "0.1.10" license: Apache 2.0 license_treatment: permissive maintenance: active --- # dm-tree — Tree is a library for working with nested data structures. License: permissive · Maintenance: active · Downloads: 5.7M/mo ## 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 above — 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 pip install dm-tree uv add dm-tree 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_current - Install friction: medium - Maintenance: active - Downloads: 5.7M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags nested data structure traversal, tree flattening and mapping, recursive structure manipulation, leaf-wise function application, nested dict and list handling, tree utilities library, structure-preserving map, nested-structures, tree-traversal, machine-learning [View on SkillFed](https://skillfed.io/packages/dm-tree) · [View on PyPI](https://pypi.org/project/dm-tree/)