Install & Compatibility
Where this runs
tested against v0.0.13 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.014s · 18.9MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.016s · 19MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Devicetree
✓ from pydevicetree import Devicetree
Main class for representing an entire devicetree.
Node
✓ from pydevicetree import Node
Represents a single node in the tree.
PropertyValue
✓ from pydevicetree import PropertyValue
Base class for property values.
RegArray
✓ from pydevicetree import RegArray
Represents the 'reg' property array.
RangeArray
✓ from pydevicetree import RangeArray
Represents the 'ranges' property array.
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())
Errors
Common errors & fixes
pydevicetree.exceptions.ParseException: Expected <class 'pydevicetree.parser.Parser'>
Invalid DTS syntax or missing /dts-v1/; header.
fixCheck your DTS input for syntax errors and ensure it starts with '/dts-v1/;'.
AttributeError: 'str' object has no attribute 'value'
Trying to access .value on a property that is not a PropertyValue object (e.g., string property).
fixUse node.properties['propname'].value for PropertyValue; for plain strings, use node.properties['propname'] directly (it is already a string).
KeyError: 'compatible'
Accessing a property that does not exist on the node.
fixCheck if the property exists: if 'compatible' in node.properties: ...
ImportError: cannot import name 'Devicetree' from 'pydevicetree'
Installed an older version (<0.0.3) where Devicetree was not exposed at top level.
fixUpgrade to latest: pip install --upgrade pydevicetree
Upgrade
Version history
0.0.13latest on PyPI · released Jul 21, 2023
Audit
Dependencies
pyparsingrequiredUsed internally for parsing DTS text.