xmacro
a simple XML macro tool
What it is and what it does
xmacro is a simplified XML macro language inspired by ROS's xacro, designed to preprocess URDF and SDF robot description files. It runs independently of ROS and can be installed via pip. The tool supports value macros (named constants substituted into XML), block macros (parameterized XML fragments), math expressions within substitution braces, file inclusion, and conditional blocks. It provides both a command-line interface and a Python API for integration into build or launch workflows.
The package includes two specialized variants: xmacro4sdf and xmacro4urdf, which add pre-defined geometry and inertia macros specific to each format, along with path resolution for model:// and package:// URIs. Macro nesting is supported up to 5 levels deep. The implementation uses Python's eval() for expression evaluation, which the documentation notes is unsafe for untrusted input.
Use it for:
- Reduce duplication in URDF robot descriptions by defining reusable inertia and geometry macros for common shapes
- Generate multiple SDF model variants from a single template by overriding macro values at parse time
- Preprocess robot description files in ROS 2 launch scripts using the Python API before deployment
- Conditionally include or exclude robot components based on macro parameters without manual file editing
- Include common macro definitions across multiple URDF or SDF files via the xmacro_include tag
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
xmacro is a command-line and Python tool for defining and expanding XML macros—named values, parameterized blocks, and conditional includes—to generate expanded XML files suitable for URDF and SDF robot description formats.
Yes, if you need XML macro expansion for URDF or SDF files and are comfortable with an abandoned package. The tool is simple, has no dependencies, and works well for its stated purpose. However, do not use it for untrusted or adversarial input due to eval()-based expression evaluation, and be aware that no security patches or feature updates will be released.
Install
xmacro on PyPI
pip
pip install xmacrouv
uv add xmacropoetry
poetry add xmacroInstalling xmacro
Before you install
Installation is straightforward via pip with no runtime dependencies. However, the package is abandoned—last release was in January 2022 and the repository received its final commit in September 2022, so no active maintenance or security updates should be expected.
License in practice
MIT license is permissive and places no restrictions on use, modification, or distribution in proprietary or open-source projects.
Quickstart
# Command-line usage
pip install xmacro
xmacro input.xml.xmacro > output.xml
# Python API usage
from xmacro.xmacro import XMLMacro
xmacro = XMLMacro()
xmacro.set_xml_file('input.xml.xmacro')
xmacro.generate()
xmacro.to_file('output.xml')
Verify before relying
- Whether the package works reliably with modern Python versions given its abandonment status
- Whether math expression evaluation via eval() poses security risks in untrusted input scenarios
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 1,669 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 77,532/month — #14,517 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: xmacro-1.2.1-py3-none-any.whl
Keywords: xml, macro, xacro, xmacro, sdformat, sdf, urdf
Tags
More Markup packages
PyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
markdown-it-pyA Python markdown parser that converts markdown…
permissive · top 100 on PyPI
beautifulsoup4Beautiful Soup parses HTML and XML documents…
permissive · top 100 on PyPI
et-xmlfileet_xmlfile writes large XML files with minimal…
permissive · top 1,000 on PyPI
tomlkitParses and edits TOML files while preserving…
permissive · top 1,000 on PyPI
docstring-parserParses Python docstrings in ReST, Google,…
permissive · top 1,000 on PyPI
xacroXacro is an XML macro language that lets you…
unclear · top 15,000 on PyPI
cmeel-urdfdomParses URDF (U-Robot Description Format) XML…
permissive · top 5,000 on PyPI
zope.talzope.tal implements the Template Attribute…
unclear · top 15,000 on PyPI
robot_descriptionsDownloads and caches open-source robot…
permissive · top 15,000 on PyPI
urdf-usd-converterConverts URDF robot description files into…
permissive · top 15,000 on PyPI
uri-templateExpands RFC 6570 URI Templates with variable…
permissive · top 1,000 on PyPI
junitparserParse, create, and manipulate JUnit/xUnit test…
permissive · top 5,000 on PyPI
defusedxmlDefusedxml hardens Python's standard XML…
permissive · top 1,000 on PyPI
yourdfpyLoads, manipulates, validates, and visualizes…
permissive · top 5,000 on PyPI
clvm-toolsCompiles a LISP-like smart-contract language…
permissive · top 15,000 on PyPI