Skip to main content

Static ROS 2 architecture analysis, visualization, and policy checking

Project description

ros2inspector

Static ROS 2 architecture analysis, visualization, and policy checks.

ros2inspector scans supported Python, C++, interface, and launch-file patterns in a ROS 2 workspace. It builds an evidence-backed architecture graph, renders that graph in several formats, and enforces architecture policies in CI.

This first release ships seven commands: scan, packages, nodes, graph, viz, audit, and validate.

Features

  • Static node and endpoint discovery with Python AST and Tree-sitter C++ parsers
  • .msg, .srv, and .action interface parsing and type resolution
  • Python, XML, and YAML launch-file analysis with per-node remapping
  • NetworkX Unified Architecture Model for packages, nodes, topics, services, actions, and interfaces
  • Content-fingerprinted incremental analysis cache backed by diskcache
  • Rich table, JSON, YAML, Mermaid, DOT, and interactive HTML output
  • Built-in connectivity audit and YAML policy enforcement

Analysis scope

ROS 2 Inspector analyzes source files without executing or building the workspace. Unsupported or ambiguous constructs are reported through evidence, confidence, dynamic-name flags, or diagnostics rather than presented as complete architectural truth.

Installation

Requires Python 3.10 or newer. A ROS 2 installation is not required for source analysis.

For a globally available CLI in an isolated environment, use pipx:

pipx install ros2inspector

Run it once without keeping it installed:

pipx run ros2inspector --help

Inside an existing Python virtual environment, use pip:

pip install ros2inspector

Install from source for development:

git clone https://github.com/aminebensaid66/ros2_inspector
cd ros2_inspector
pip install -e ".[dev]"

Quickstart

# Workspace summary
ros2inspector scan

# Package metadata and dependencies
ros2inspector packages --show-deps

# Nodes and their connections
ros2inspector nodes --show-connections

# Communication graph as Mermaid
ros2inspector graph comms --format mermaid

# Interactive HTML graph
ros2inspector viz --no-open

# Built-in architecture checks
ros2inspector audit

# Policy enforcement
ros2inspector validate --policy ros2inspector_policy.yaml

Commands

scan

ros2inspector scan [PATH] [--format table|json|yaml]

Discovers ROS 2 packages and displays a health-scored workspace summary.

packages

ros2inspector packages [-C PATH] [--filter cpp|python|meta] [--sort name|score|version] [--show-deps] [--format table|json|yaml]

Shows package metadata, type, license, maintainers, health score, and optional dependency details.

nodes

ros2inspector nodes [-C PATH] [--format table|json|yaml] [-p PACKAGE] [-o FILE] [--show-connections] [--no-cache]

Lists discovered nodes and their publishers, subscriptions, services, clients, action servers, and action clients. --show-connections includes resolved peer connections and interface types.

graph

ros2inspector graph [deps|comms|full] [-C PATH] [--format mermaid|dot|json] [-p PACKAGE] [-o FILE] [--no-cache]

Graph views:

View Contents
deps Package dependencies
comms Node-to-topic, service, and action communication
full Dependency and communication relationships together

Examples:

ros2inspector graph deps --format json
ros2inspector graph comms --format mermaid -o architecture.mmd
ros2inspector graph full --format dot | dot -Tsvg -o architecture.svg

viz

ros2inspector viz [-C PATH] [-o FILE] [--open|--no-open] [--no-cache]

Generates a self-contained interactive Cytoscape.js HTML graph.

audit

ros2inspector audit [PATH] [--format table|json|yaml] [--fail-on error|warning|info] [--strict] [--exclude NAME] [--no-cache]

Runs built-in connectivity checks for orphan topics, dead outputs, isolated nodes, and unmatched service or action endpoints.

validate

ros2inspector validate [PATH] --policy FILE [--fail-on error|warning|info] [--format table|json|yaml] [--no-cache]

Validates the workspace against a YAML policy file.

Global options

ros2inspector --version
ros2inspector --quiet scan

--version prints the package version. --quiet suppresses diagnostic headers and progress output.

Output formats

scan, packages, nodes, audit, and validate support table, JSON, and YAML output where applicable. graph supports Mermaid, DOT, and JSON. viz writes interactive HTML.

Machine-readable records go to standard output while diagnostics go to standard error, which keeps pipelines clean:

ros2inspector nodes --format json | jq '.[] | select(.package == "my_pkg")'
ros2inspector audit --format yaml > audit.yaml
ros2inspector graph comms --format mermaid -o architecture.mmd

Policy files

Create a ros2inspector_policy.yaml file:

version: 1
rules:
  - type: health_threshold
    min_score: 70
    severity: warning

  - type: license
    allowed: [Apache-2.0, MIT]
    severity: error

  - type: naming
    packages:
      pattern: '^[a-z][a-z0-9_]*$'
      severity: warning
    nodes:
      pattern: '^[A-Z][a-zA-Z0-9]*Node$'
      severity: info

  - type: dependency
    forbidden:
      - { from: perception, to: planner, severity: error }
    required:
      - { package: navigation, depends_on: nav_core, severity: warning }

  - type: no_circular_deps
    severity: error

  - type: topic_connectivity
    no_publisher: true
    no_subscriber: true
    exclude: [/rosout, /clock]

  - type: maintainer_required
    require_email: true
    severity: warning

Supported rule types are health_threshold, license, naming, dependency, no_circular_deps, topic_connectivity, node_isolation, service_connectivity, action_connectivity, maintainer_required, and version_not_default.

CI integration

- name: Install ROS 2 Inspector
  run: pip install ros2inspector

- name: Architecture audit
  run: ros2inspector audit --fail-on warning --format json > audit.json

- name: Policy validation
  run: ros2inspector validate --policy .ros2inspector_policy.yaml --fail-on error

Relevant exit codes:

Code Meaning
0 Success or no findings at the configured threshold
1 Findings at or above the configured threshold
2 Invalid invocation or policy configuration
3 Workspace or policy file not found

Architecture

ros2inspector/
├── cli/           # scan, packages, nodes, graph, viz, audit, validate
├── discovery/     # workspace, package, and interface discovery
├── static/        # Python, C++, interface, launch, package, and health parsers
├── model/         # Pydantic schemas and the NetworkX UAM
├── graph/         # Mermaid, DOT, and JSON renderers
├── viz/           # interactive HTML renderer and bundled Cytoscape.js
├── policy/        # policy loader, engine, and rules
├── cache/         # diskcache-backed incremental analysis
├── output/        # output package plumbing
└── utils/         # shared utilities

The Unified Architecture Model is a networkx.MultiDiGraph. Graph nodes represent packages, ROS nodes, topics, services, actions, and interfaces. Edges carry relationships such as depends_on, publishes, subscribes, provides, calls, defined_in, and uses_interface.

Development

pip install -e ".[dev]"
pytest
ruff check ros2inspector/
mypy ros2inspector/

The test suite uses fixture workspaces under tests/fixtures/ and does not require a live ROS 2 environment.

Publishing

Maintainers should follow RELEASING.md. Publishing is performed by GitHub Actions through PyPI Trusted Publishing when a GitHub Release is published.

License

MIT. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ros2inspector-0.1.0.tar.gz (170.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ros2inspector-0.1.0-py3-none-any.whl (181.3 kB view details)

Uploaded Python 3

File details

Details for the file ros2inspector-0.1.0.tar.gz.

File metadata

  • Download URL: ros2inspector-0.1.0.tar.gz
  • Upload date:
  • Size: 170.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for ros2inspector-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4592be271bd3a84bbd092523968983927d58c7d07d96e081b6b394576e422fb3
MD5 d8662dcad38707a3469423df3ea61bf4
BLAKE2b-256 1c5e4f9a437200c1b1e316fabbacaaa9fdffb7007ca1a0b0c8cb8740cad794dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for ros2inspector-0.1.0.tar.gz:

Publisher: publish.yml on aminebensaid66/ros2_inspector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ros2inspector-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ros2inspector-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 181.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for ros2inspector-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df72000c2e83b4ccbfddb64ff3effca95f5265a3822f0a8406c77575e202e9ab
MD5 45ec0dfc8763ed401e5641b71b9b172a
BLAKE2b-256 8a9b901bc31ac785da3e8247631fd233c5e26793086d96a09f4e81914c2ff139

See more details on using hashes here.

Provenance

The following attestation bundles were made for ros2inspector-0.1.0-py3-none-any.whl:

Publisher: publish.yml on aminebensaid66/ros2_inspector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page