Python wrapper for MAVSDK
Project description
MAVSDK-Python
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 ofpip
andpython3
instead ofpython
, 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="udp://: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
Release steps
- Check the proto submodule is up-to-date and the generated code has been updated.
- Check all required pull requests are merged to main
- Check MAVSDK_SERVER_VERSION is set to the correct version of mavsdk_server.
- Create git tag on laster main, e.g.:
git switch main git pull git tag X.Y.Z git push --tags
- 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
Built Distributions
File details
Details for the file mavsdk-2.8.4-py3-none-win_amd64.whl
.
File metadata
- Download URL: mavsdk-2.8.4-py3-none-win_amd64.whl
- Upload date:
- Size: 364.8 kB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0ab5dafb8c296518075492dd8164fa8c3669e8831a8bb90ad1064c08cbb6788 |
|
MD5 | aab2714a2195db4b4793135cfad5ba1b |
|
BLAKE2b-256 | 120fa1148bb8bd211c56608ae85deeea46f060d43364536e2e566a5f33547fa1 |
File details
Details for the file mavsdk-2.8.4-py3-none-win32.whl
.
File metadata
- Download URL: mavsdk-2.8.4-py3-none-win32.whl
- Upload date:
- Size: 364.8 kB
- Tags: Python 3, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df80d42a7755ff6829ffcd3587b75ed3437675658ba6f216b8941ca0f2df7946 |
|
MD5 | 4234a489bd76ba37d3bf8dedb0066b09 |
|
BLAKE2b-256 | 7167807dedddf19c77fa213121fea9115f6f6a9d64724f558c796f5d59bd2c5b |
File details
Details for the file mavsdk-2.8.4-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: mavsdk-2.8.4-py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 13.6 MB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de32c1706da9aea3c1127a6f5f5869c8b893db2a94a70041f75ef367e7b0bfb3 |
|
MD5 | 84c97ebe908266ea90473683bc0be8e9 |
|
BLAKE2b-256 | 9057a2e53443c25f6052e76dd3ebc57d29c462af0fc4cad81c5d1d6bdce80fd8 |
File details
Details for the file mavsdk-2.8.4-py3-none-manylinux2014_aarch64.whl
.
File metadata
- Download URL: mavsdk-2.8.4-py3-none-manylinux2014_aarch64.whl
- Upload date:
- Size: 16.6 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c111a234e435920d9ec0a337edb24560e6c7e5dc0205e52c7d4a12513a6b262a |
|
MD5 | 499db7744faf6ea189498fac30a2feae |
|
BLAKE2b-256 | 714334134c69367b82a16c7ba187a77602c349e482e575bba21c1517de8dd4e9 |
File details
Details for the file mavsdk-2.8.4-py3-none-macosx_11_0_arm64.whl
.
File metadata
- Download URL: mavsdk-2.8.4-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 10.9 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33bca5326dc6ddb3799c2ce6b3ca2aa117d14cc572c4bcfee524fa276c1f5b5d |
|
MD5 | 399adbc10389cd176adf25ae01b5dafe |
|
BLAKE2b-256 | e8282090fc18707377eb3db6b9c80e8049cf95829ca79081846459eab07d21ed |
File details
Details for the file mavsdk-2.8.4-py3-none-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: mavsdk-2.8.4-py3-none-macosx_10_9_x86_64.whl
- Upload date:
- Size: 11.0 MB
- Tags: Python 3, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa24f78bacc630172c6fbbe5453ca503b884aef57e537a5751ae4aaaffeb4eba |
|
MD5 | 587dc05424604689f94274c237e1699d |
|
BLAKE2b-256 | 6863cc6624a5b55b9b8760f2855fc0ce9a799d948a60912b5a71a1a0d94678c2 |
File details
Details for the file mavsdk-2.8.4-py3-none-linux_armv7l.whl
.
File metadata
- Download URL: mavsdk-2.8.4-py3-none-linux_armv7l.whl
- Upload date:
- Size: 15.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a8f128e52ba3971c141928d7a35b03fe27c213d23573d4bba790e079a25106d |
|
MD5 | 29868ee081100b3b2fa3d3b82572b9e2 |
|
BLAKE2b-256 | 1acab3adb91e9a99267670319215588ab4189a46b9c27547a69ce2c78b09e0c8 |
File details
Details for the file mavsdk-2.8.4-py3-none-linux_armv6l.whl
.
File metadata
- Download URL: mavsdk-2.8.4-py3-none-linux_armv6l.whl
- Upload date:
- Size: 15.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a7bf78b4e76d6c8eedcfc27fcdf3e8ffc7789474ada0ce585f685018a9a9353 |
|
MD5 | 130ca479080251472739e275c51d014d |
|
BLAKE2b-256 | 3f02079e5455cb555a757d8d3c76c3b3036f62b370172b915d26e803a86bd9d3 |