Skip to main content

flypi

Fly ArduPilot and PX4 drones from a Raspberry Pi with a few lines of Python.

CI PyPI Python License

flypi is a small, modern, high-level MAVLink library for companion computers. It is built on pymavlink, has no other dependencies, and installs cleanly on a Raspberry Pi.

import flypi

with flypi.connect("udp:127.0.0.1:14550") as drone:
    drone.wait_ready()  # pre-arm checks pass + 3D GPS fix
    drone.arm()
    drone.takeoff(5)  # metres above home; waits until it gets there
    print(drone.telemetry.position)
    drone.land()  # waits until landed and disarmed

Status: alpha (v0.1). The API may still change before 1.0. ArduPilot Copter is the primary target. PX4 support is experimental.

Install

pip install flypi

Python 3.10 or newer. Works on Raspberry Pi OS (Bookworm and later), Linux, macOS and Windows.

Connecting

flypi.connect() takes a pymavlink connection string:

Setup Address
ArduPilot SITL via MAVProxy, or PX4 SITL "udp:127.0.0.1:14550" (default)
ArduPilot SITL directly "tcp:127.0.0.1:5760"
Pi UART (GPIO 14/15) wired to the flight controller "/dev/serial0" with baud=921600 (match your SERIALx_BAUD)
Flight controller over USB "/dev/ttyACM0"
drone = flypi.connect("/dev/serial0", baud=921600, timeout=30)

flypi waits for the autopilot's heartbeat. It ignores heartbeats from ground stations, gimbals and cameras. If nothing is heard within timeout, you get a flypi.ConnectionTimeout that tells you what to check.

What you can do in v0.1

Call What it does
drone.telemetry Immutable snapshot: armed, mode, position, velocity, attitude, battery, gps, heartbeat_age
drone.wait_ready(require_gps=True) Wait until the vehicle is ready to arm
drone.set_mode("LOITER") Change flight mode and confirm it
drone.arm() / drone.disarm() Arm or disarm and confirm it
drone.takeoff(altitude) Vertical takeoff to altitude metres above home
drone.land() Land at the current position, wait for disarm
drone.return_to_launch() Switch to RTL
drone.wait_until(cond, timeout) Wait for any telemetry condition
drone.status_messages Recent messages from the autopilot (e.g. PreArm: reasons)
drone.available_modes Mode names this vehicle accepts

Every command checks the vehicle's acknowledgement. When the autopilot refuses something, flypi raises an error that includes the autopilot's own explanation:

flypi.errors.CommandRejected: MAV_CMD_COMPONENT_ARM_DISARM was rejected by the
vehicle (MAV_RESULT_FAILED). Recent vehicle messages: PreArm: Need 3D Fix

All errors inherit from flypi.FlypiError.

Telemetry example

t = drone.telemetry
print(t.mode, t.armed)
print(f"{t.position.lat:.6f}, {t.position.lon:.6f} @ {t.position.alt_rel:.1f} m")
print(f"Battery {t.battery.voltage:.1f} V ({t.battery.remaining}%)")
print(f"GPS fix {t.gps.fix_type}, {t.gps.satellites} satellites")

Values the vehicle has not reported yet are None.

Try it in simulation first

Always test in software-in-the-loop (SITL) simulation before flying real hardware.

ArduPilot SITL (see the ArduPilot SITL docs):

sim_vehicle.py -v ArduCopter --console --map
# in another terminal
python examples/first_flight.py

PX4 SITL (see the PX4 simulation docs):

make px4_sitl gz_x500
python examples/first_flight.py

How it works

Each connection runs one background thread. The thread reads every MAVLink message from the vehicle to keep telemetry current, and sends a 1 Hz ground-station heartbeat so the autopilot knows a controller is attached. Your code calls ordinary blocking methods. No asyncio is needed.

Because flypi heartbeats as a ground station, an autopilot with a GCS failsafe enabled (FS_GCS_ENABLE on ArduPilot) will treat your script stopping mid-flight as a lost ground station and run its failsafe action. That is usually what you want on a companion computer.

Safety

Drones can seriously injure people and damage property. Test in SITL first, then with propellers removed. Fly only where it is safe and legal, follow your local aviation rules, and always keep a manual RC override ready. flypi is provided "as is", without warranty. See the LICENSE.

Development

git clone https://github.com/kestrel-research/flypi
cd flypi
pip install -e ".[dev]"
pytest
ruff check .

The test suite runs flypi end to end over real UDP sockets against a small MAVLink vehicle emulator (tests/fake_vehicle.py), so it needs no simulator.

Roadmap

  • goto(lat, lon, alt) and velocity control in GUIDED/OFFBOARD
  • Missions: upload, start, monitor
  • Parameters: read and write
  • Camera capture helpers for the Raspberry Pi camera
  • A companion research library (simulation, RL and navigation) built on flypi

License

Apache-2.0 © Kestrel Research contributors. Part of Kestrel Research.

Metadata

Release files for flypi 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flypi 0.1.0
File Size Uploaded Provenance Actions
flypi-0.1.0.tar.gz 22.1 kB With provenance Details for flypi-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flypi 0.1.0
File Interpreter ABI Platform Actions
flypi-0.1.0-py3-none-any.whl Python 3 none any Details for flypi-0.1.0-py3-none-any.whl

Total release size: 41.6 kB

Release files / flypi-0.1.0.tar.gz

Download URL flypi-0.1.0.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d566a286691f8075d0adc633528e71610feeff64270e8d52fac0b472a9de317f
BLAKE2b-256 checksum
How to use checksums
c73389caf8553c514ed498ba681c53cf7bdd3b93c9806b6fc1938b57c5f58771
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / flypi-0.1.0-py3-none-any.whl

Download URL flypi-0.1.0-py3-none-any.whl
Size 19.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9245fe2f4d4656b83c5da1c47efb7ec0b4dce68fcbfb2ebf103ad3a3e15c3c9
BLAKE2b-256 checksum
How to use checksums
0ecdccb0fed34a0a213713051e49c33490f1798dc793123c4301b70856a2872c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Security for flypi 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for flypi-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page