ROS 2 Publisher Subscriber Python Tutorial: Complete Guide (2026)

Build your first ROS 2 publisher and subscriber in Python: create a package, write publisher/subscriber nodes, register entry points, use QoS profiles for sensor data, create custom .msg types, and debug with ros2 topic echo and rqt_graph.

In this article

  • Step 1: Create a ROS 2 Package
  • Step 2: Write the Publisher Node
  • Step 3: Write the Subscriber Node
  • Step 4: Register Nodes in setup.py
  • Step 5: Custom Message Types
  • Step 6: QoS. The Hidden Gotcha
  • Debugging Commands
  • Summary