# Import mavutil
from pymavlink import mavutil
# Create the connection
master = mavutil.mavlink_connection('udp:0.0.0.0:14550')
# Choose a mode
mode = 'MANUAL'
# Check if mode is available
if mode not in master.mode_mapping():
print('Unknown mode : {}'.format(mode))
print('Try:', list(master.mode_mapping().keys()))
return
# Get mode ID
mode_id = master.mode_mapping()[mode]
# Set new mode
master.set_mode(mode_id)
We are upgrading our documentation to add more pymavlink examples, should release soon.