Skip to main content

Python wrapper for MAVSDK

Project description

MAVSDK-Python

GitHub Actions Status

This is the Python wrapper for MAVSDK.

The Python wrapper is based on a gRPC client communicating with the gRPC server written in C++. To use the Python wrapper the gRPC server called "backend" needs to be running on the same system. The wrapper is essentially auto-generated from the message definitions (proto files).

Important Notes

  • Python 3.7+ is required (because the wrapper is based on asyncio).
  • You may need to run pip3 instead of pip and python3 instead of python, depending of your system defaults.
  • Auterion used to have a Getting started with MAVSDK-Python (web.archive.org) guide if you're a beginner and not sure where to start.

API Reference docs

-> API Reference documentation.

Install using pip from PyPi

Note for Raspberry Pi 1/2 and Zero:

MAVSDK-Python requires grpcio. However, there are no binary packets of grpcio for armv6 available via pip (also see files on pypi.org). In this case, install grpcio via the package manager, e.g. sudo apt-get install python3-grpcio.

To install mavsdk-python, simply run:

pip3 install mavsdk

The package contains mavsdk_server already (previously called "backend"), which is started automatically when connecting (e.g. await drone.connect()). Have a look at the examples to see it used in practice. It will be something like:

from mavsdk import System

...

drone = System()
await drone.connect(system_address="udpin://0.0.0.0:14540")

Note: System() takes two named parameters: mavsdk_server_address and port. When left empty, they default to None and 50051, respectively, and mavsdk_server -p 50051 is run by await drone.connect(). If mavsdk_server_address is set (e.g. to "localhost"), then await drone.connect() will not start the embedded mavsdk_server and will try to connect to a server running at this address. This is useful for platforms where mavsdk_server does not come embedded, for debugging purposes, and for running mavsdk_server in a place different than where the MAVSDK-Python script is run.

Run the examples

Once the package has been installed, the examples can be run:

examples/takeoff_and_land.py

The examples assume that the embedded mavsdk_server binary can be run. In some cases (e.g. on Raspberry Pi), it may be necessary to run mavsdk_server manually, and therefore to set mavsdk_server_address='localhost' as described above.

Contribute

Note: this is more involved and targeted at contributors.

Most of the code is auto-generated from the proto definitions, using our templates. The generated files can be found in the generated folder. As a result, contributions are generally made in the templates or on the build system. Regularly, there is a need to update MAVSDK-Python to include the latest features defined in the proto definitions. This is described below.

Clone the repo

Clone this repo and recursively update submodules:

git clone https://github.com/mavlink/MAVSDK-Python --recursive
cd MAVSDK-Python

Install prerequisites

First install the protoc plugin (protoc-gen-mavsdk):

cd proto/pb_plugins
pip3 install -r requirements.txt

You can check that the plugin was installed with $ which protoc-gen-mavsdk, as it should now be in the PATH.

Then go back to the root of the repo and install the dependencies of the SDK:

cd ../..
pip3 install -r requirements.txt -r requirements-dev.txt

Generate the code

Run the following helper script. It will generate the Python wrappers for each plugin.

./other/tools/run_protoc.sh

Adding support for new plugins

In case you updated the ./proto submodule to include a new plugin, you will also have to manually edit the file mavsdk/system.py to register the plugin.

Update mavsdk_server version

MAVSDK_SERVER_VERSION contains exactly the tag name of the mavsdk_server release corresponding to the version of MAVSDK-Python. When the proto submodule is updated here, chances are that mavsdk_server should be updated, too. Just edit this file, and the corresponding binary will be downloaded by the setup.py script (see below).

Build and install the package locally

After generating the wrapper and only in ARM architectures with linux, defines a variable MAVSDK_SERVER_ARCH:

export MAVSDK_SERVER_ARCH=<ARM embedded architecture>

Supported architectures: armv6l, armv7l and aarch64. For example for Raspberry Pi it is armv7l, or aarch64 (if a 64 bit distribution is used).

Then you can install a development version of the package, which links the package to the generated code in this local directory. To do so, use:

python3 setup.py build
pip3 install -e .

Note: MAVDSK-Python runs mavsdk/bin/mavsdk_server when await drone.connect() is called. This binary comes from MAVSDK and is downloaded during the setup.py step above.

Generate the API documentation

Make sure the version tag is set correctly before generating new documentation.

pip3 install -r requirements-docs.txt
make -C mavsdk html

Formatting checks before committing

We use the following checks in CI:

pipx run ruff format --check --line-length=100 examples
pipx run ruff check --select=ASYNC,RUF006,E,F --line-length=100 examples
pipx run codespell .

Release steps

  1. Check the proto submodule is up-to-date and the generated code has been updated.
  2. Check all required pull requests are merged to main
  3. Check MAVSDK_SERVER_VERSION is set to the correct version of mavsdk_server.
  4. Create git tag on laster main, e.g.:
    git switch main
    git pull
    git tag X.Y.Z
    git push --tags
    
  5. Go to releases page and create new release. The CI will now:
    • Create and push a wheel for Windows, Linux and macOS to PyPi.
    • Generate the latest docs and push them to s3.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

mavsdk-3.15.3-py3-none-win_arm64.whl (10.8 MB view details)

Uploaded Python 3Windows ARM64

mavsdk-3.15.3-py3-none-win_amd64.whl (10.8 MB view details)

Uploaded Python 3Windows x86-64

mavsdk-3.15.3-py3-none-win32.whl (10.8 MB view details)

Uploaded Python 3Windows x86

mavsdk-3.15.3-py3-none-manylinux2014_aarch64.whl (18.2 MB view details)

Uploaded Python 3

mavsdk-3.15.3-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl (15.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

mavsdk-3.15.3-py3-none-macosx_14_0_arm64.whl (11.7 MB view details)

Uploaded Python 3macOS 14.0+ ARM64

mavsdk-3.15.3-py3-none-macosx_13_0_x86_64.whl (12.3 MB view details)

Uploaded Python 3macOS 13.0+ x86-64

mavsdk-3.15.3-py3-none-linux_armv7l.whl (16.6 MB view details)

Uploaded Python 3

mavsdk-3.15.3-py3-none-linux_armv6l.whl (16.6 MB view details)

Uploaded Python 3

File details

Details for the file mavsdk-3.15.3-py3-none-win_arm64.whl.

File metadata

  • Download URL: mavsdk-3.15.3-py3-none-win_arm64.whl
  • Upload date:
  • Size: 10.8 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for mavsdk-3.15.3-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 dce986f9672f759fbe8f07c10568fa4111982a4a3da2502331aa79762f164115
MD5 422d7e7443db73f283e5a3575d4750aa
BLAKE2b-256 b3704c0d767506aa2bfe21587ba20416b859e23d4230bc469b85e136f0c75c12

See more details on using hashes here.

File details

Details for the file mavsdk-3.15.3-py3-none-win_amd64.whl.

File metadata

  • Download URL: mavsdk-3.15.3-py3-none-win_amd64.whl
  • Upload date:
  • Size: 10.8 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for mavsdk-3.15.3-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 5bfa8fb656b273f90f3d4c4e1ee65c205f3e1af83d8a4d8c7d5cf1f387c3931b
MD5 fb888821dc1878b60f43bcb6e76b03f1
BLAKE2b-256 f4b8b9220987869d626fe6fe6947ad5a107e18612c69e79f2b7fe1d9a40e629c

See more details on using hashes here.

File details

Details for the file mavsdk-3.15.3-py3-none-win32.whl.

File metadata

  • Download URL: mavsdk-3.15.3-py3-none-win32.whl
  • Upload date:
  • Size: 10.8 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for mavsdk-3.15.3-py3-none-win32.whl
Algorithm Hash digest
SHA256 b08a500236fa814c1f43a86fe3281085918c16c36c3c398ac954631ce0dcbb42
MD5 44cf7c156c51a051f06f239a03928683
BLAKE2b-256 2ad8266335200bb22021da58eeece232ed9323bf3d514dcfc75cde0b8507ba65

See more details on using hashes here.

File details

Details for the file mavsdk-3.15.3-py3-none-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for mavsdk-3.15.3-py3-none-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 18f0db1d017b237564bf25a31933e8ce29d35b5014e8667f05399a2ac4c415b4
MD5 adf2e1ad2ceb7704dc01338ae8092f9d
BLAKE2b-256 90438aa26d7439a8b93a325f79de6a9795d3e9e48d138405ec5748a726cd6a08

See more details on using hashes here.

File details

Details for the file mavsdk-3.15.3-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for mavsdk-3.15.3-py3-none-manylinux1_x86_64.manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 ce07022a4a292bb15e1e744abe93980d8338256f76852ca5352e51229017c62f
MD5 199546d78909c67c4ddddbcb973b28ed
BLAKE2b-256 f79cb889e9403024b6c8fcfb2012fb96433a1f92877de09c3ae14ea06f162b4f

See more details on using hashes here.

File details

Details for the file mavsdk-3.15.3-py3-none-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for mavsdk-3.15.3-py3-none-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d7425842aa240c9a3bbccf7f34af6231c0e034209e54cdc47a790b70f90f705d
MD5 6a4d02151739b084dadb94e9ce6bcac2
BLAKE2b-256 1ed12074e1dac83c83b1fc65cc4d6e3abcc2101f62059c8640cdb91c08c0c7fd

See more details on using hashes here.

File details

Details for the file mavsdk-3.15.3-py3-none-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for mavsdk-3.15.3-py3-none-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 620aa9afcd115be9d118630246bbab2f60f58f596902d01ddaacc3259a13fc79
MD5 a44797549e69bb7309b2f799121d90e4
BLAKE2b-256 32b581f857ec826c0b8b805ac7d3f4ec8e1dbd926ff318d1f92738e3594bff1d

See more details on using hashes here.

File details

Details for the file mavsdk-3.15.3-py3-none-linux_armv7l.whl.

File metadata

File hashes

Hashes for mavsdk-3.15.3-py3-none-linux_armv7l.whl
Algorithm Hash digest
SHA256 e4dc685d456aa47928bebdfebfcb2fa056bf7f5c6cf5a10f34e77e51b5a6b526
MD5 7f8529e8ddb30466e336ae195fb009ed
BLAKE2b-256 791631d2693ef1c084861cfeaa3afe85871a9af95f2b481e05d3209902357bc1

See more details on using hashes here.

File details

Details for the file mavsdk-3.15.3-py3-none-linux_armv6l.whl.

File metadata

File hashes

Hashes for mavsdk-3.15.3-py3-none-linux_armv6l.whl
Algorithm Hash digest
SHA256 3b9d35cc2ea7599f78d1a7f73a36d6df44d9df38175ef788b5783bcc0c8dc7c8
MD5 184ee067fdadffa471f83f13b893cc6b
BLAKE2b-256 1c8bfb30487c6804a79425bb4148481d84201728cf90dceb9886e0ad175dcef1

See more details on using hashes here.

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