Registry / devops / xacro
library2.1.1pypypi✓ verified 88d ago

Xacro is a macro language for XML, commonly used in ROS (Robot Operating System) to parameterize and modularize URDF robot descriptions. It allows you to create reusable XML macros, include other files, and use mathematical expressions. Current version is 2.1.1, compatible with Python >=3.8. Release cadence is tied to ROS distributions, generally stable.

pip install xacro
INSTALL
IMPORT
SIG · XACRO
X
xacro
devopspythonv2.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

process_file
✓ from xacro import process_file
✗ import xacro; xacro.process_file(...)
In version 2+, the main entry point is process_file, not top-level execution with xacro.main().

Processes an XML string with xacro macros and outputs the expanded XML.

from xacro import process_file from io import StringIO # Example URDF snippet with a macro xml_input = '''<?xml version="1.0"?> <robot name="test" xmlns:xacro="http://ros.org/wiki/xacro"> <xacro:macro name="box" params="name x y z"> <link name="${name}"> <visual> <geometry> <box size="${x} ${y} ${z}"/> </geometry> </visual> </link> </xacro:macro> <xacro:box name="base" x="0.5" y="0.5" z="0.2"/> </robot>''' doc = process_file(StringIO(xml_input), mapping={'dummy': None}) print(doc.toprettyxml())
Debug
Known issues
breakingIn version 2.0, the API changed from command-line-only to a proper Python module. The old 'xacro' script no longer works as a direct import.
fix
Use 'from xacro import process_file' and call it programmatically instead of importing xacro and calling 'xacro.main()'.
affects: <2.0 to >=2.0
deprecatedThe 'xacro:include' tag with 'filename' attribute is deprecated in favor of 'xacro:include' with 'file' attribute to avoid name clashes with Python's built-in.
fix
Use <xacro:include file="path/to/file.xacro"/> instead of <xacro:include filename="..."/>.
affects: >=2.0
gotchaXacro uses Python expressions in ${} blocks. If you have a literal string that looks like a variable (e.g., ${...}), it must be escaped or quoted, otherwise it will raise a NameError.
fix
Use ${{...}} to escape a literal ${} or use single quotes around the value: e.g., <property value="'${not_a_var}'" />.
affects: all
Errors
Common errors & fixes
ImportError: cannot import name 'main' from 'xacro'
In xacro 2+, there is no 'main' function; the API changed to process_file.
fix
Use 'from xacro import process_file' and call process_file on your file or stream.
Upgrade
Version history
2.1.1latest on PyPI · released Aug 28, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
24 hits · last 30 days
node
20
Resources
xacro — pip install xacro · libregistry