Skip to content

Repository files navigation

Build Actions Status

Autosar Modelling Tool

AutosarFactory provides APIs to read/create/modify AUTOSAR compliant arxml files. The folder autosarfactory contains the autosarfactory implementation with respect to the schema corresponding to the latest AUTOSAR release. Please check the folder autosar_releases for previous AUTOSAR releases

How to use

  • Clone the repository.

  • Manually install the package.

    $ python setup.py install

use python3 if you have both python2 and python3 installed.

  • Import the package autosarfactory to your python script.
  • And, finally have fun with modelling AUTOSAR.

Reading file

#Read a list of files
files = ['component.arxml', 'datatypes.arxml']
root, status = autosarfactory.read(files)

#Read a list of folders
folders = ['folder1', 'folder2']
root, status = autosarfactory.read(folders)

The read method processes the input files/folders and return the root node(with merged info of all the files). If folder is provided, the method does a deep search for the arxml files and reads in all the files in the folder. The status gives an info if the file/folder reading was successful.

Creating new file

newPack = autosarfactory.new_file('newFile.arxml', defaultArPackage = 'NewPack')

Creates a new arxml file with the given package name and returns the ARPackage object.

  • If package name is not provided, default package name 'RootPackage' is used.
  • The method raises FileExistsError if the given file already exist. To avoid this, please pass the argument overWrite as True.

Accessing attributes and references

Model elements have get_<attribute/reference> methods to access existing attribute and reference value.

For multi-references, the method returns a list of values

Modifying attributes/references

All the elements have set_<attribute/reference>methods to modify the attribute or reference value.

For multi-references, there also exists methods add_<reference>, remove_<reference>

Adding new model elements

All the parent classes have new_<element> methods to create an element.

rootPack = autosarfactory.new_file('newFile.arxml', defaultArPackage = 'RootPack')
newPack = rootPack.new_ARPackage('NewPack')
#new applicaton component
asw1 = newPack.new_ApplicationSwComponentType('asw1')
asw1.new_PPortPrototype('outPort')

#new senderRecever interface
srIf = newPack.new_SenderReceiverInterface('srif1')
srIf.new_DataElement('de1')

Accessing elements by path

Once the file is read by the tool, its possible to access elements by path.

files = ['component.arxml', 'datatypes.arxml']
autosarfactory.read(files)
swc = autosarfactory.get_node('/Swcs/asw1')
uint8DataType = autosarfactory.get_node('/DataTypes/baseTypes/uint8')

Saving options

Save

The tool provides save method to save the changes made to the model.

files = ['component.arxml', 'datatypes.arxml']
autosarfactory.read(files)

rootPack = autosarfactory.new_file('newFile.arxml', defaultArPackage = 'RootPack')
newPack = rootPack.new_ARPackage('NewPack')

#new applicaton component
newcomp = newPack.new_ApplicationSwComponentType('newcomponent')
newcomp.new_PPortPrototype('outPort')

#new senderRecever interface
srIf = newPack.new_SenderReceiverInterface('srif1')
srIf.new_DataElement('de1')

#save changes
autosarfactory.save(['newFile.arxml'])

The save method accepts a list of file which needs to be saved. If no argument is provided, all the files(input, newly created) will be saved.

SaveAs

The tool provides saveAs method to save the changes made to the model into a single arxml file.

files = ['component.arxml', 'datatypes.arxml']
autosarfactory.read(files)

rootPack = autosarfactory.new_file('newFile.arxml', defaultArPackage = 'RootPack')
newPack = rootPack.new_ARPackage('NewPack')

#new applicaton component
newcomp = newPack.new_ApplicationSwComponentType('newcomponent')
newcomp.new_PPortPrototype('outPort')

#new senderRecever interface
srIf = newPack.new_SenderReceiverInterface('srif1')
srIf.new_DataElement('de1')

#save changes
autosarfactory.saveAs('mergedFile.arxml')

Export element

The tool provides export_to_file method to export a specific element to a file including it's AR-Package hierarchy. This is only supported for CollectableElements(which means AP-Package as well as all PackageableElements which includes ApplicationSwComponentType, SR interface, Signals etc etc- precisely any elements which directly fall under an AR-Package)

  • option1(using export function available in the node itself)
autosarfactory.read(['component.arxml'])
swc = autosarfactory.get_node('/Swcs/swc1')
swc.export_to_file('swc1Export.arxml', overWrite = True)
  • option2(using export function where the node is passed)
autosarfactory.read(['component.arxml'])
swc = autosarfactory.get_node('/Swcs/swc1')
autosarfactory.export_to_file(swc, 'swc1Export.arxml', overWrite = True)

MCP server

The mcp_server/ folder contains an MCP (Model Context Protocol) server that exposes the autosarfactory API to AI coding assistants such as Claude Code. It allows an AI agent to query the full API reference, discover element hierarchies, look up enum values, and generate correct autosarfactory Python scripts — all without needing to read source code manually.

For setup instructions and full details, see mcp_server/README.md.

Autosar visualizer

The package also includes a graphical visualizer for the Autosar models which can be simply opened by passing the autosar root to the method show_in_ui. For example:

$ python -m autosarfactory.ui.autosar_ui

File(s) can be loaded using the File->Load Model(s) menu item.

Please see below a screenshot of the viewer.

Autosar Viewer

The viewer mainly consists of 4 views and a menu bar.

  • Autosar Explorer - A simple tree which shows all elements in the model.
  • Property view - Info about property and its corresponding values of the selected element in autosar explorer.
  • Referenced by view - This views list elements which references the selected element in autosar explorer.
  • Search view - Provision to search any elements in the model. The type of search can be selected through a combobox at the top of the view. There are 3 different types of search available: by the element short name, by a regular expression applied to the name of the element or by the Autosar type of the element.

It's also possible to edit the existing properties(via the property view), create new model elements(via the right click menu of the respective nodes) and save the updated model to the file system.

Interactive Graph Visualization

Bring your AUTOSAR models to life by generating interactive graphs for any model element. This feature provides a dynamic, explorable map of the element's hierarchy and connections, making it easier to understand complex relationships within your model.

To generate a graph:

  • In the tree viewer, right-click the model element you wish to visualize.
  • Select Generate Graph from the context menu.

The generated graph shows all the child/reference relationship, and has a possibility to filter element by name and view it's relationship, can pan, zoom, and interact with the nodes to inspect your model in greater detail.

If you wish a CLI mode of graph generation, it's also possible by importing the file autosarfactory.ui.graph_gen and making a call to the API graph_gen.create_graph_report.

Examples

Please check the script inside the Examples folder which creates a basic communication matrix.

For more information on the usage, please refer tests/test_autosarmodel.py.

About

AutosarFactory is a python package which helps user to read/create/modify AUTOSAR standard arxml files.

Topics

Resources

Stars

129 stars

Watchers

8 watching

Forks

Used by

Contributors

Languages