Registry / devops / devicetree

devicetree

JSON →
library0.0.2pypypi✓ verified 86d ago

The `devicetree` library provides Python tools for parsing and manipulating devicetree files, commonly used in embedded systems. It supports both binary (.dtb) and source (.dts) formats. The current version is 0.0.2, indicating early development, and releases are not on a fixed cadence.

pip install devicetree
INSTALL
IMPORT
SIG · DEVICETREE
D
devicetree
devopspythonv0.0.2
Install
1.7s avg
Import
25ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.2 · 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
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.027s · 20.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.7s · import 0.024s · 21MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DT
from devicetree.dtlib import DT
from devicetree import DT
The main class for loading and manipulating device trees. It resides in the `dtlib` submodule, not directly under the top-level `devicetree` package.
DTSource
from devicetree.dtlib import DTSource
A specialized class for loading device trees specifically from .dts (source) files, offering more source-level details. The `DT` class can also handle .dts files.

This quickstart demonstrates how to load a device tree from a temporary .dts file, access its root node, retrieve properties, and find specific child nodes by path or compatible string. It includes cleanup of the temporary file.

import os import devicetree # Create a dummy DTS file for demonstration dts_content = """ /dts-v1/; / { compatible = "acme,board-v1"; cpus { cpu@0 { compatible = "arm,cortex-m4"; reg = <0>; }; }; gpio@10000 { compatible = "gpio-controller"; reg = <0x10000 0x100>; #gpio-cells = <2>; }; }; """ dts_path = "example.dts" with open(dts_path, "w") as f: f.write(dts_content) try: # Load the device tree from the DTS file dt = devicetree.dtlib.DT(dts_path) print(f"\n--- Device Tree Content ---") print(f"Root node name: {dt.name}") # Accessing properties of the root node compatible_prop = dt.get_prop('compatible') if compatible_prop: # get_prop returns DTProperty or None print(f"Root compatible: {compatible_prop.value}") # Finding a specific node by path cpu_node = dt.get_node("/cpus/cpu@0") if cpu_node: print(f"CPU Node path: {cpu_node.path}") cpu_compatible = cpu_node.get_prop('compatible') if cpu_compatible: print(f"CPU Node compatible: {cpu_compatible.value}") # Finding a node by compatible string gpio_node = dt.get_node_by_compatible("gpio-controller") if gpio_node: print(f"GPIO Controller found at: {gpio_node.path}") except Exception as e: print(f"An error occurred during device tree processing: {e}") finally: # Clean up the dummy file if os.path.exists(dts_path): os.remove(dts_path) print(f"\nCleaned up {dts_path}")
Debug
Known issues
gotchaThe library is currently at version 0.0.2, indicating early development. The API surface may be unstable and subject to breaking changes in minor releases.
fix
Always pin to exact versions (e.g., `devicetree==0.0.2`) and review release notes carefully when upgrading. For new projects, consider using the latest available version.
affects: <1.0.0
gotchaWhen parsing DTS files that use `#include` directives (e.g., to include `.dtsi` files), ensure that the include paths are correctly configured or that included files are accessible relative to the primary DTS file.
fix
Verify that all `.dtsi` files are in the same directory as the main `.dts` file or explicitly manage include paths if the library offers such options (check `DT` or `DTSource` constructor arguments).
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'devicetree.dtlib'
Attempting to import `dtlib` directly, or misimporting symbols like `DT` from the `devicetree` top-level package instead of its submodule.
fix
Ensure you are importing specific symbols from the `devicetree.dtlib` submodule, e.g., `from devicetree.dtlib import DT`.
FileNotFoundError: [Errno 2] No such file or directory: 'your_device_tree.dts'
The path provided to the `DT` constructor (for a DTB or DTS file) does not exist, is misspelled, or is inaccessible from where the Python script is executed.
fix
Double-check the file path and ensure the device tree file (`.dtb` or `.dts`) is present at the specified location and has correct read permissions.
devicetree.dtlib.DTError: failed to load DT from 'malformed.dts'
The provided device tree file is syntactically malformed, corrupted, or uses an unsupported format/feature that the parser cannot handle.
fix
Verify the integrity and correctness of your `.dts` or `.dtb` file. Use standard devicetree compilers (`dtc`) or validators to check its syntax and structure. Ensure it complies with the Devicetree Specification.
Upgrade
Version history
0.0.2latest on PyPI · released Apr 27, 2022
Audit
Dependencies
pyyamlrequiredRequired for parsing YAML-formatted device tree bindings or related configuration files.
pyelftoolsrequiredUsed for parsing ELF files, which may contain embedded device tree blobs or related symbol information.
Agent activity
17 hits · last 30 days
node
16
OpenAI (training)
1
Resources
devicetree — pip install devicetree · libregistry