Pymavrest - Python RESTful API for MAVLink enabled vehicles

Pymavrest is another RESTful API for MAVLink enabled vehicles written in Python.

With Pymavrest, you can easily monitor vehicle state (MAVLink messages) programmatically (using any programming language capable of doing HTTP POST/GET requests) or from your favorite browser, as a JSON object.

Here are the ready-to-use, key features:

  • Get all vehicular data at once.
  • Get a specific message by name or message id.
  • Get timestamp (wall clock, monotonic counter) or rate of messages at once, by name, message id.
  • Try to reconnect to master after some specific time if no message is received during some period.
  • Drop non-periodic messages after some specific time.
  • Whitelist & blacklist support of messages, if you only want or don’t want to see some specific messages.
  • Get all on-board parameters or a specific one.

This started as a self-paced project and it is still in its early phases, many more features will come.
Hope this will be useful to those who want to show vehicle state in some graphical interfaces or monitor vehicle state from different processes.
Feel free to comment down below, and if you want to see some features, face an issue, trouble using it, please create an issue on GitHub.
Happy coding :slight_smile:


Excellent !
It would be nice if you can sync with GitHub - patrickelectric/mavlink2rest: mavlink2rest creates a REST server that provides mavlink information from a mavlink source to have a commun rest protocol !

1 Like

Noted, will do it as soon as possible.

@patrickelectric do you still have the rest protocol documenation somewhere ?

Well that isn’t mandatory, but that would be nice to note have yet another web protocole !

Hi @khancyr,

The documentation is in the README, there is also generic support for all MAVLink messages inside the autopilotmega dialect supported by rust-mavlink.
There is the swagger documentation webpage provided in /docs:

Hi @Mustafa_Gokce,

Nice work! Do you have a benchmark table or something closer to compare with mavlink2rest ?
It was initially projected with Rust for performance reasons, and also to provide the tool as a single binary, making it easier to integrate with embedded linux solutions.
Is there also a websocket for async mavlink messages (Like parameters) ?

I will try to implement your suggestions.
I did a quick hammering benchmark on my laptop (not a fancy one) like the one below (will do a comprehensive one later).

import requests
import time

time_max = 0
while True:
    time_initial = time.monotonic()
    data = requests.get("").json()
    time_final = time.monotonic()
    time_delta = time_final - time_initial
    if time_delta > time_max:
        time_max = time_delta

I spawned this code 8 times and get at most 0.015 seconds on each client which gives a roughly 66Hz update rate, note that this endpoint contains all the telemetry data (maybe I reached the limits of requests module, IDK).
So seems like the API can handle 500Hz releasing all the data.
Of course, to compare I need to do this test with both pymavrest and mavlink2rest on the same device (especially on SBCs like RPi).
But basic functionality is there :smiley:

In the repository, you can find the latest version of Pymavrest.

Now the features are:

  • Get all messages from vehicle
  • Get a specific message by it’s name or ID
  • Get a specific message field with field name by message name or ID
  • Get all parameters from vehicle
  • Get a specific parameter by it’s name
  • Get all mission items on vehicle
  • Get a specific mission item on vehicle by it’s ID
  • Get all fence items on vehicle
  • Get a specific fence item on vehicle by it’s ID
  • Get all rally items on vehicle
  • Get a specific rally item on vehicle by it’s ID
  • Get statistics of API and vehicle connection
  • Get and set custom key/value pairs
  • Send COMMAND_LONG messages to vehicle
  • Send COMMAND_INT messages to vehicle
  • Send parameter send command to vehicle
  • Send mission item list to vehicle
  • Send fence item list to vehicle
  • Send rally item list to vehicle
  • Reconnect to vehicle if not received a message within a timeout
  • Drop non-periodic messages after a desired timeout
  • Set message stream rate
  • Message whitelist/blacklist support
  • Fetch parameters and plan, fence and rally items at start