{"id":24314,"library":"pydevicetree","title":"pydevicetree","description":"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.","status":"active","version":"0.0.13","language":"python","source_language":"en","source_url":"https://github.com/sifive/pydevicetree","tags":["devicetree","dts","embedded","hardware","parsing"],"install":[{"cmd":"pip install pydevicetree","lang":"bash","label":"Default install"}],"dependencies":[{"reason":"Used internally for parsing DTS text.","package":"pyparsing","optional":false}],"imports":[{"note":"Main class for representing an entire devicetree.","symbol":"Devicetree","correct":"from pydevicetree import Devicetree"},{"note":"Represents a single node in the tree.","symbol":"Node","correct":"from pydevicetree import Node"},{"note":"Base class for property values.","symbol":"PropertyValue","correct":"from pydevicetree import PropertyValue"},{"note":"Represents the 'reg' property array.","symbol":"RegArray","correct":"from pydevicetree import RegArray"},{"note":"Represents the 'ranges' property array.","symbol":"RangeArray","correct":"from pydevicetree import RangeArray"}],"quickstart":{"code":"from pydevicetree import Devicetree, Node\n\n# Parse a DTS file from string\ndts_text = \"\"\"/dts-v1/;\n/ {\n    compatible = \"example,board\";\n    memory@80000000 {\n        device_type = \"memory\";\n        reg = <0x0 0x80000000 0x0 0x40000000>;\n    };\n};\n\"\"\"\ntree = Devicetree.from_dts(dts_text)\nprint(tree.root.compatible)        # 'example,board'\nmem_node = tree.root.children['memory@80000000']\nprint(mem_node.reg)                # RegArray(...)\n\n# Create and add a new node\nnew_node = Node('serial@10000000', parent=tree.root)\nnew_node.add_property('compatible', 'ns16550')\ntree.root.add_child(new_node)\nprint(tree.to_dts())\n","lang":"python","description":"Parse a DTS string, access properties, and manipulate nodes."},"warnings":[{"fix":"Use the exact name as in the DTS source, e.g., node.properties['compatible'] not 'Compatible'.","message":"Property names in DTS are case-sensitive. Ensure exact case when accessing via node.properties dict.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Use reg_array.as_size_address_pairs() to get list of (address, size) tuples.","message":"The 'reg' property is returned as a RegArray object, not a raw list. Convert using .as_size_address_pairs() or .get_reg_tuple().","severity":"gotcha","affected_versions":">=0.0.6"},{"fix":"Ensure each child node has only one parent, or use deep copies before merging.","message":"In v0.0.12, merging nodes now reparents children. If you manually assign child nodes to multiple parents, they may be moved unexpectedly.","severity":"breaking","affected_versions":">=0.0.12"},{"fix":"Ensure DTS input starts with '/dts-v1/;'.","message":"The library only supports DTS v1. Using /dts-v1/; header is required; older styles are not parsed.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Check your DTS input for syntax errors and ensure it starts with '/dts-v1/;'.","cause":"Invalid DTS syntax or missing /dts-v1/; header.","error":"pydevicetree.exceptions.ParseException: Expected <class 'pydevicetree.parser.Parser'>"},{"fix":"Use node.properties['propname'].value for PropertyValue; for plain strings, use node.properties['propname'] directly (it is already a string).","cause":"Trying to access .value on a property that is not a PropertyValue object (e.g., string property).","error":"AttributeError: 'str' object has no attribute 'value'"},{"fix":"Check if the property exists: if 'compatible' in node.properties: ...","cause":"Accessing a property that does not exist on the node.","error":"KeyError: 'compatible'"},{"fix":"Upgrade to latest: pip install --upgrade pydevicetree","cause":"Installed an older version (<0.0.3) where Devicetree was not exposed at top level.","error":"ImportError: cannot import name 'Devicetree' from 'pydevicetree'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}