{"id":8847,"library":"autosar-data","title":"Autosar-Data Python Library","description":"The `autosar-data` library provides tools to read, write, and modify AUTOSAR ARXML data using Python. It offers an object-oriented API for interacting with AUTOSAR workspaces, packages, and elements, simplifying development with ARXML files. The current version is 0.15.0, and it follows an infrequent but impactful release cadence, often introducing breaking changes related to API and Python version support between minor versions.","status":"active","version":"0.15.0","language":"en","source_language":"en","source_url":"https://github.com/DanielT/autosar-data-py","tags":["autosar","arxml","automotive","xml","data-processing"],"install":[{"cmd":"pip install autosar-data","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"Workspace","correct":"from autosar_data import Workspace"},{"symbol":"create_container","correct":"from autosar_data.element import create_container"},{"symbol":"AutosarData","correct":"from autosar_data import AutosarData"}],"quickstart":{"code":"from autosar_data import Workspace\nfrom autosar_data.element import create_container\nimport os\n\n# Create an empty workspace\nworkspace = Workspace.create_empty()\n\n# Add a package structure\npackages = workspace.find_or_create_package('/MyProject/Packages')\n\n# Add a container element to the package\ncontainer = create_container('ECU_CONFIGURATION', parent=packages)\ncontainer.create_text_element('SHORT-NAME', 'MyEcuConfig')\ncontainer.create_text_element('TYPE', 'ECU_EXTRACT')\n\n# Add a sub-element to the container\nsub_element = create_container('PARAMETERS', parent=container)\nsub_element.create_text_element('VALUE', '123')\n\n# Print the ARXML content to console\narxml_string = workspace.to_string()\nprint(\"Generated ARXML content:\")\nprint(arxml_string)\n\n# Example of loading from a file (requires a dummy file for execution)\n# Create a dummy ARXML file for demonstration\ndummy_arxml_path = 'dummy_example.arxml'\nwith open(dummy_arxml_path, 'w') as f:\n    f.write(arxml_string)\n\ntry:\n    # Load the workspace from the dummy file\n    # Note: Workspace.from_file returns (workspace, errors) since v0.11.0\n    loaded_workspace, errors = Workspace.from_file(dummy_arxml_path)\n\n    if errors:\n        print(f\"\\nErrors found during loading: {errors}\")\n    else:\n        print(f\"\\nSuccessfully loaded workspace from {dummy_arxml_path}.\")\n        # Access a value from the loaded workspace\n        loaded_value_element = loaded_workspace.find('/MyProject/Packages/ECU_CONFIGURATION/PARAMETERS/VALUE')\n        if loaded_value_element:\n            print(f\"Loaded value: {loaded_value_element.text_content}\")\n\nexcept FileNotFoundError:\n    print(f\"Error: File not found at {dummy_arxml_path}\")\nfinally:\n    # Clean up the dummy file\n    if os.path.exists(dummy_arxml_path):\n        os.remove(dummy_arxml_path)","lang":"python","description":"This quickstart demonstrates how to create an empty AUTOSAR workspace, add a package structure, create container and text elements, and then print the resulting ARXML content to a string. It also includes an example of how to load an ARXML file and access its content, highlighting the return value change for loading methods."},"warnings":[{"fix":"Upgrade your Python environment to version 3.11 or higher. If you need to use Python 3.9/3.10, pin `autosar-data` to a version older than 0.15.0 (e.g., `pip install autosar-data<0.15`).","message":"Starting with version 0.15.0, `autosar-data` dropped support for Python 3.9 and 3.10. It now requires Python 3.11 or newer.","severity":"breaking","affected_versions":">=0.15.0"},{"fix":"Update your code to unpack the returned tuple: `workspace, errors = Workspace.from_file('file.arxml')`. Remember to check the `errors` list for parsing issues.","message":"Since version 0.11.0, the methods `Workspace.from_file()` and `Workspace.from_string()` return a tuple `(workspace, errors)` instead of just the `workspace` object. Old code expecting only the workspace will raise a `TypeError`.","severity":"breaking","affected_versions":">=0.11.0"},{"fix":"Replace `AutosarData.parse_string(...)` with `AutosarData.from_string(...)`. Note that `from_string` also returns a `(workspace, errors)` tuple.","message":"In version 0.14.0, the method `AutosarData.parse_string()` was renamed to `AutosarData.from_string()`. Using the old name will result in an `AttributeError`.","severity":"breaking","affected_versions":">=0.14.0"},{"fix":"Always ensure your input ARXML files are well-formed XML and conform to the expected AUTOSAR schema. Use XML validation tools if encountering persistent parsing issues.","message":"The library can be strict with ARXML file structure and content according to the AUTOSAR standard. Malformed or non-compliant ARXML files may lead to parsing errors or unexpected behavior during loading.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Change the assignment to unpack the tuple: `workspace, errors = Workspace.from_file('path/to/file.arxml')`.","cause":"Attempting to assign the result of `Workspace.from_file()` or `Workspace.from_string()` to a single variable (`workspace = ...`) after version 0.11.0, when these methods started returning a tuple `(workspace, errors)`.","error":"TypeError: cannot unpack non-iterable Workspace object"},{"fix":"Replace `parse_string` with `from_string`: `workspace, errors = AutosarData.from_string('<ARXML>...</ARXML>')`.","cause":"Trying to call the `parse_string` method on an `AutosarData` (or `Workspace`) object after version 0.14.0, where it was renamed.","error":"AttributeError: 'Workspace' object has no attribute 'parse_string'"},{"fix":"Verify that the file path is correct and accessible. Ensure the file exists and that the current working directory or the absolute path is properly specified.","cause":"The ARXML file specified in `Workspace.from_file()` does not exist at the provided path or the path is incorrect.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'your_file.arxml'"}]}