pydevicetree

raw JSON →
0.0.13 verified Fri May 01 auth: no python

A Python library for parsing and manipulating Devicetree Source v1 (DTS) files. Current version 0.0.13, released on 2026-01-12. Maintained primarily by SiFive; releases are infrequent with minor fixes and improvements.

pip install pydevicetree
error pydevicetree.exceptions.ParseException: Expected <class 'pydevicetree.parser.Parser'>
cause Invalid DTS syntax or missing /dts-v1/; header.
fix
Check your DTS input for syntax errors and ensure it starts with '/dts-v1/;'.
error AttributeError: 'str' object has no attribute 'value'
cause Trying to access .value on a property that is not a PropertyValue object (e.g., string property).
fix
Use node.properties['propname'].value for PropertyValue; for plain strings, use node.properties['propname'] directly (it is already a string).
error KeyError: 'compatible'
cause Accessing a property that does not exist on the node.
fix
Check if the property exists: if 'compatible' in node.properties: ...
error ImportError: cannot import name 'Devicetree' from 'pydevicetree'
cause Installed an older version (<0.0.3) where Devicetree was not exposed at top level.
fix
Upgrade to latest: pip install --upgrade pydevicetree
gotcha Property names in DTS are case-sensitive. Ensure exact case when accessing via node.properties dict.
fix Use the exact name as in the DTS source, e.g., node.properties['compatible'] not 'Compatible'.
gotcha The 'reg' property is returned as a RegArray object, not a raw list. Convert using .as_size_address_pairs() or .get_reg_tuple().
fix Use reg_array.as_size_address_pairs() to get list of (address, size) tuples.
breaking In v0.0.12, merging nodes now reparents children. If you manually assign child nodes to multiple parents, they may be moved unexpectedly.
fix Ensure each child node has only one parent, or use deep copies before merging.
gotcha The library only supports DTS v1. Using /dts-v1/; header is required; older styles are not parsed.
fix Ensure DTS input starts with '/dts-v1/;'.

Parse a DTS string, access properties, and manipulate nodes.

from pydevicetree import Devicetree, Node

# Parse a DTS file from string
dts_text = """/dts-v1/;
/ {
    compatible = "example,board";
    memory@80000000 {
        device_type = "memory";
        reg = <0x0 0x80000000 0x0 0x40000000>;
    };
};
"""
tree = Devicetree.from_dts(dts_text)
print(tree.root.compatible)        # 'example,board'
mem_node = tree.root.children['memory@80000000']
print(mem_node.reg)                # RegArray(...)

# Create and add a new node
new_node = Node('serial@10000000', parent=tree.root)
new_node.add_property('compatible', 'ns16550')
tree.root.add_child(new_node)
print(tree.to_dts())