{"id":46826,"library":"xacro","title":"Xacro","description":"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.","status":"active","version":"2.1.1","language":"python","source_language":"en","source_url":"https://github.com/ros/xacro","tags":["xacro","ros","urdf","xml-macro","robot-description"],"install":[{"cmd":"pip install xacro","lang":"bash","label":"Standard install"}],"dependencies":[],"imports":[{"note":"In version 2+, the main entry point is process_file, not top-level execution with xacro.main().","wrong":"import xacro; xacro.process_file(...)","symbol":"process_file","correct":"from xacro import process_file"}],"quickstart":{"code":"from xacro import process_file\nfrom io import StringIO\n\n# Example URDF snippet with a macro\nxml_input = '''<?xml version=\"1.0\"?>\n<robot name=\"test\" xmlns:xacro=\"http://ros.org/wiki/xacro\">\n  <xacro:macro name=\"box\" params=\"name x y z\">\n    <link name=\"${name}\">\n      <visual>\n        <geometry>\n          <box size=\"${x} ${y} ${z}\"/>\n        </geometry>\n      </visual>\n    </link>\n  </xacro:macro>\n  <xacro:box name=\"base\" x=\"0.5\" y=\"0.5\" z=\"0.2\"/>\n</robot>'''\n\ndoc = process_file(StringIO(xml_input), mapping={'dummy': None})\nprint(doc.toprettyxml())","lang":"python","description":"Processes an XML string with xacro macros and outputs the expanded XML."},"warnings":[{"fix":"Use 'from xacro import process_file' and call it programmatically instead of importing xacro and calling 'xacro.main()'.","message":"In 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.","severity":"breaking","affected_versions":"<2.0 to >=2.0"},{"fix":"Use <xacro:include file=\"path/to/file.xacro\"/> instead of <xacro:include filename=\"...\"/>.","message":"The '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.","severity":"deprecated","affected_versions":">=2.0"},{"fix":"Use ${{...}} to escape a literal ${} or use single quotes around the value: e.g., <property value=\"'${not_a_var}'\" />.","message":"Xacro 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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'2.1.1':41 '3.8':45 'allow':24 'cadenc':47 'common':9 'compat':42 'creat':27 'current':38 'descript':22,63 'distribut':52 'express':37 'file':33 'general':53 'includ':31 'languag':6 'macro':5,30,60 'mathemat':36 'modular':19 'oper':14 'parameter':17 'python':44 'releas':46 'reusabl':28 'robot':13,21,62 'robot-descript':61 'ros':12,51,56 'stabl':54 'system':15 'tie':49 'urdf':20,57 'use':10,35 'version':39 'xacro':1,2,55 'xml':8,29,59 'xml-macro':58","created_at":"2026-06-07T13:01:49.006981+00:00","updated_at":"2026-06-07T13:01:49.006981+00:00","problems":[{"fix":"Use 'from xacro import process_file' and call process_file on your file or stream.","cause":"In xacro 2+, there is no 'main' function; the API changed to process_file.","error":"ImportError: cannot import name 'main' from 'xacro'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/ros/xacro","github":"https://github.com/ros/xacro","docs":null,"changelog":null,"pypi":null,"npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-29","last_verified":"2026-06-29","next_check":"2026-07-29","install_tag":null}}