English | Türkçe
Mavflow
Repository · Releases · Source package · MIT License
Mavflow provides Python tools for MAVLink endpoints, connections, message routing, telemetry subscriptions, bounded asyncio delivery, and an optional application packet protocol.
The package was extracted from the MAVLink layer of Vehicle Autonomy Core. Mavflow is maintained as a standalone library; its source project is not needed to install or use it. The transport, routing, application protocol, tests, and examples live in this repository.
Mavflow focuses on reusable MAVLink infrastructure. Vehicle mission logic and application-specific behavior belong to the projects built on top of it.
Contents
- Getting started
- Core concepts
- Working with telemetry
- Async applications
- Application packets
- Troubleshooting
- Security and operational boundaries
- Composing the stack
- Lifecycle and reference
- Development and license
Getting started
Install
Python 3.10 or newer is required. From a checkout, install Mavflow into the active environment:
python -m pip install .
After the PyPI release is available, install the distribution with:
python -m pip install mavflow
The distribution and import package are both named mavflow. Its required
dependencies, flowevent and pymavlink, are installed automatically.
flowevent supplies event buses and subscription handles; Mavflow uses those
types directly.
For editable development, install the development tools:
python -m pip install -e ".[dev]"
The dev extra provides build, coverage, pyperf, Pyright, Ruff, and Twine.
Version
The current package line is v1.0. The project metadata and installed
package expose the same version through mavflow.__version__:
from mavflow import __version__
print(__version__) # 1.0
Receive your first heartbeat
This async example listens on UDP port 14550 and awaits a heartbeat through
MavAsyncChannel. The runtime owns the connection lifecycle; the channel
forwards routed messages into the asyncio event loop. A vehicle or simulator
must send MAVLink packets to the configured endpoint.
import asyncio
from mavflow import MavAsyncChannel, MavEndpoint, MavRuntime
async def main() -> None:
runtime = MavRuntime(MavEndpoint.udp("0.0.0.0", 14550))
channel = MavAsyncChannel(runtime.router, "HEARTBEAT", maxsize=64)
channel.start()
try:
runtime.start()
try:
message = await channel.receive(timeout=10.0)
except asyncio.TimeoutError:
print("No heartbeat received before the timeout")
else:
print("First heartbeat:", message)
finally:
channel.stop()
runtime.stop()
asyncio.run(main())
For a synchronous application, use the runtime context manager and wait_for()
directly:
from mavflow import MavEndpoint, MavRuntime
with MavRuntime(MavEndpoint.udp("0.0.0.0", 14550)) as link:
message = link.wait_for("HEARTBEAT", timeout=10.0)
if message is not None:
print("First heartbeat:", message)
The synchronous and async examples are also available as runnable modules.
Run an example
Install Mavflow first, then run these commands from the repository root. Each telemetry example expects a vehicle, simulator, or MAVLink router to send data to the selected endpoint.
python -m examples.telemetry_async --host 0.0.0.0 --port 14550 --timeout 10
python -m examples.telemetry --host 0.0.0.0 --port 14550 --timeout 10
python -m examples.filtered_telemetry --system 1 --seconds 30
python -m examples.message_history --message-type HEARTBEAT --limit 20
python -m examples.application_packets
telemetry_async demonstrates asyncio consumption, while telemetry shows the
synchronous runtime. filtered_telemetry selects position and attitude
messages from one source system; message_history waits for a message and
prints the router's retained history and counters. application_packets
demonstrates packet encoding and reassembly without opening a vehicle link.
Choose an API layer
| Component | Use it for |
|---|---|
MavConnection |
Opening a pymavlink transport and sending or receiving raw MAVLink messages. |
MavMessageRouter |
Owning the receive loop, filtering messages, and keeping bounded message history. |
MavClient |
Using a connection and router through one synchronous facade. |
MavRuntime |
Owning the client lifecycle and optionally composing application peers and handlers. |
MavAsyncChannel |
Delivering routed messages to an asyncio event loop through a bounded queue. |
Use MavRuntime for the normal application entry point. Compose the lower
level types directly when an application needs to own a transport or router
itself.
Core concepts
Endpoints and connections
MavEndpoint is an immutable description of a connection. The helpers
tcp(host, port), udp(host, port), and serial(device, baud=...) build
common endpoint forms:
from mavflow import MavEndpoint
udp = MavEndpoint.udp("0.0.0.0", 14550)
tcp = MavEndpoint.tcp("192.0.2.10", 5760)
serial = MavEndpoint.serial("/dev/ttyUSB0", baud=57600)
An endpoint also carries the local system and component IDs, MAVLink dialect,
reconnect setting, and heartbeat timeout. Its default URI is
udp:127.0.0.1:14550. Use the address and transport mode expected by the
vehicle, radio, simulator, or router.
MavConnection owns the underlying pymavlink connection. Importing
mavflow does not open a device or load the transport module; pymavlink is
loaded when a real connection is created. The connection provides lifecycle
methods, raw message access, send helpers, and vehicle target information.
One reader and the message router
MavMessageRouter owns the receive loop for a connection. It reads each
incoming message once, records the message and sequence state, then delivers
matching messages to active subscriptions.
This single-reader ownership keeps transport reads and routing in one place. Router callbacks run as part of message delivery, so keep them short. Move blocking work to an application-owned worker instead of holding up the receive loop.
The router exposes current statistics, the latest matching message, a bounded
history, and a wait operation. MavClient combines one connection and one
router so callers do not have to wire those pieces together manually.
Filtering and message history
MavMessageFilter can match message types, source system IDs, source
component IDs, message IDs, a message condition, or a predicate. Combine
criteria when a callback should receive only a subset of the telemetry:
from mavflow import MavMessageFilter
position_filter = MavMessageFilter.for_types(
"GLOBAL_POSITION_INT",
source_systems=1,
)
Pass the filter to subscribe() to register a callback. A type filter can also
be supplied directly to wait_for(),
latest(), or the router's history() method. Use limit with history() to
retrieve only the most recent matching messages. History is in memory and
bounded; it is not a durable telemetry log.
Lifecycle and composition
MavRuntime composes a client and, when requested, an application channel,
peer, and dispatcher. start() starts the transport and owned application
services in dependency order. stop() shuts them down in reverse order and
collects shutdown errors. A runtime can be used as a synchronous context
manager, as in the first example.
Create separate runtimes for separate connections. A runtime can also accept
an existing MavClient when an application needs to share or configure
the lower-level connection and router.
Event delivery
Mavflow uses flowevent for event buses and subscription handles. Runtime
message, packet, and error events use that library's contracts directly; Mavflow
does not implement a second event bus.
A subscription returned by subscribe() or handle() has an explicit
cancel() lifecycle. Cancel subscriptions when their work is complete, or
manage them with the surrounding service lifetime.
Working with telemetry
Subscribe to messages
MavRuntime.subscribe() accepts a message type or a filter and a callback.
The returned subscription can be cancelled independently of the runtime:
from mavflow import MavEndpoint, MavMessageFilter, MavRuntime
def report_position(message: object) -> None:
print(message)
position_filter = MavMessageFilter.for_types(
"GLOBAL_POSITION_INT",
source_systems=1,
)
with MavRuntime(MavEndpoint.udp("0.0.0.0", 14550)) as link:
position_subscription = link.subscribe(position_filter, report_position)
heartbeat_subscription = link.subscribe("HEARTBEAT", print)
try:
link.wait_for("HEARTBEAT", timeout=10.0)
finally:
position_subscription.cancel()
heartbeat_subscription.cancel()
Message filters can also restrict source components and message IDs, or apply
a condition or predicate to a received message. The message object is provided
by pymavlink; use its generated message accessors for fields such as source
system, source component, and message type.
Wait for a message and inspect history
Use wait_for() when code needs one matching message as a value. Use latest()
for the most recent match already observed, or history() to inspect retained
messages:
from mavflow import MavEndpoint, MavRuntime
with MavRuntime(MavEndpoint.udp("0.0.0.0", 14550)) as link:
first_heartbeat = link.wait_for("HEARTBEAT", timeout=10.0)
most_recent = link.latest("HEARTBEAT")
recent_messages = link.router.history("HEARTBEAT", limit=20)
router_state = link.state.router
wait_for() returns None after its timeout. latest() also returns None
until a matching message has arrived. History contains message envelopes and
is read in publication order. Router statistics include received messages,
receive and dispatch errors, estimated dropped messages, and delivery quality.
Use send() or send_named() when sending a MAVLink message through the
client or runtime. The method name and arguments follow the generated
pymavlink dialect API.
Async applications
MAVLink transport reads remain owned by the synchronous router. Use
MavAsyncChannel to forward selected messages into an asyncio event loop;
this is a bounded bridge, not a second transport reader. When the queue fills,
the channel drops the oldest queued message and increments dropped_messages.
Start the channel from inside its running event loop. Stop it before stopping the runtime so it can cancel its router subscription cleanly. This example consumes a continuous stream and can be cancelled with the surrounding task:
import asyncio
from mavflow import MavAsyncChannel, MavEndpoint, MavRuntime
async def main() -> None:
runtime = MavRuntime(MavEndpoint.udp("0.0.0.0", 14550))
channel = MavAsyncChannel(
runtime.router,
"HEARTBEAT",
maxsize=64,
)
channel.start()
try:
runtime.start()
while True:
message = await channel.receive()
print(message)
finally:
channel.stop()
runtime.stop()
asyncio.run(main())
receive(timeout=...) raises asyncio.TimeoutError when no message arrives
before the deadline. receive_nowait() reads an already queued message and raises
asyncio.QueueEmpty when the queue is empty. The channel exposes its pending
count and drop count so applications can monitor bounded delivery. For a CLI
version with argument parsing and cleanup, see
examples/telemetry_async.py.
Application packets
The optional application protocol carries JSON-compatible Mavflow packets over
MAVLink V2_EXTENSION messages. It is separate from ordinary telemetry
routing; applications that only need standard MAVLink messages do not need to
enable it.
Encode and reassemble packets
MavApplicationPacket stores a packet type, JSON-compatible payload,
packet ID, timestamp, source IDs, and response flag. MavApplicationCodec
encodes a packet into bounded fragments, adds a checksum, and validates
fragments during decode. MavApplicationAssembler reassembles fragments
while bounding incomplete packet count, memory, and lifetime.
The codec can be used without opening a vehicle connection:
from mavflow import (
MavApplicationAssembler,
MavApplicationCodec,
MavApplicationPacket,
)
packet = MavApplicationPacket(
"vehicle.health",
{"ready": True, "battery_percent": 84},
packet_id=42,
)
fragments = MavApplicationCodec.encode(packet)
assembler = MavApplicationAssembler()
decoded = None
for fragment in fragments:
decoded = assembler.accept(fragment, source_system=1, source_component=1)
if decoded is None:
raise RuntimeError("The packet was not fully reassembled")
print(decoded.to_dict())
See examples/application_packets.py for the complete example. The codec rejects malformed JSON, invalid checksums, unsupported protocol versions, and packets outside its configured bounds.
Peers, requests, and handlers
Set application_role when constructing a runtime to enable the application
channel, peer, and dispatcher:
from mavflow import MavEndpoint, MavRuntime
def read_health(_request: object) -> dict[str, object]:
return {"ready": True, "battery_percent": 84}
endpoint = MavEndpoint.udp("0.0.0.0", 14550)
runtime = MavRuntime(endpoint, application_role="vehicle")
handler = runtime.handle("vehicle.health.query", read_health)
try:
with runtime:
# The remote peer can now request vehicle.health.query.
...
finally:
handler.cancel()
A handler receives a MavApplicationPacket. It can return a mapping, a
MavApplicationResult, or None. If the request expects a response,
Mavflow sends the handler result to the requesting peer. Handler registration
returns a cancellable subscription.
Use notify() for a one-way application packet and request() when the caller
needs a correlated response. Requests carry an ID, accept response type filters,
and raise TimeoutError when no matching response arrives before the deadline:
with MavRuntime(endpoint, application_role="ground-station") as link:
response = link.request(
"vehicle.health.query",
{},
response_types="system.ack",
timeout=3.0,
)
print(response.response.payload)
The default response types are system.ack and system.error. The peer also
tracks remote liveness and transport availability. Configure request deadlines
and dispatcher capacity for the timing and workload of the application.
Remote log models
MavRemoteLogRecord and MavRemoteLogBatch describe application log
records that can be converted to and from protocol payloads. They provide
validated record and batch models; they do not configure a Python logging
handler or persist logs locally.
Troubleshooting
| Symptom | Checks |
|---|---|
wait_for() returns None or an async receive times out. |
Confirm the sender targets the configured UDP/TCP endpoint, the vehicle or simulator is transmitting, and the requested message type is present. Increase the timeout only when the link needs more time to start. |
MavAsyncChannel.start() raises that no loop is running. |
Create and start the channel from inside an active async def function, then start the runtime. |
dropped_messages keeps increasing. |
The bounded queue is receiving faster than the consumer processes messages. Reduce the filter to needed message types, speed up the consumer, or increase maxsize if memory permits. |
An application request() times out. |
Check that the remote peer is running, the packet type and response type match the registered handler, and the selected system/component IDs route to that peer. |
The synchronous runtime uses None for a wait timeout. Async channel receives
raise asyncio.TimeoutError; application requests raise TimeoutError. Handle
these separately when one task uses more than one API layer.
Security and operational boundaries
Mavflow provides MAVLink transport and reusable routing primitives. It does not decide vehicle policy, command authorization, mission behavior, or how an application stores telemetry.
Router history, the asyncio channel, application fragment assembly, and dispatcher work are bounded in-memory resources. They are cleared with their owning lifecycle and are not durable queues. Monitor router statistics, channel drops, peer state, and runtime/application error events when operating a long-running service.
MAVLink endpoints and network access must match the vehicle and deployment configuration. Applications remain responsible for their transport security, command policy, and validation of business-level payloads.
Composing the stack
The core telemetry path is MavEndpoint → MavConnection →
MavMessageRouter → MavClient → MavRuntime. Each layer has
one job: describe the address, own the transport, own the receive loop,
provide a synchronous facade, and coordinate application lifecycle.
An application role adds the packet channel, peer state, and bounded dispatcher on top of that same client and router:
from mavflow import MavClient, MavEndpoint, MavRuntime
endpoint = MavEndpoint.udp("0.0.0.0", 14550)
client = MavClient(endpoint)
runtime = MavRuntime(
client=client,
application_role="ground-station",
workers=2,
max_pending=128,
)
with runtime:
runtime.notify("mission.status", {"state": "ready"})
The transport and router remain shared. Creating an application role does not start another receive loop for the same connection. Use a separate runtime when an application needs an independent transport or lifecycle.
Lifecycle and reference
Defaults
| Setting | Default | Notes |
|---|---|---|
| Endpoint URI | udp:127.0.0.1:14550 |
Local default endpoint. |
| Endpoint system/component | 255 / 0 |
Local MAVLink source IDs. |
| Endpoint dialect | ardupilotmega |
Used by pymavlink. |
| Heartbeat timeout | 10 seconds |
Connection setting. |
| Async channel capacity | 128 messages |
Oldest queued message is dropped on overflow. |
| Application role | Disabled | Set application_role to create a peer and dispatcher. |
| Application dispatcher | 1 worker, 64 pending jobs |
Runtime defaults when an application role is enabled. |
Component responsibilities
| Component | Responsibility |
|---|---|
MavEndpoint |
Normalize a TCP, UDP, or serial connection description. |
MavConnection |
Own the pymavlink transport, lifecycle, and raw send/receive operations. |
MavMessageRouter |
Own one receive loop, filter callbacks, sequence state, and bounded history. |
MavClient |
Compose a connection and router behind a synchronous facade. |
MavRuntime |
Start and stop the client and optional application services as one unit. |
MavAsyncChannel |
Bridge filtered router delivery into a bounded asyncio queue. |
MavApplicationChannel |
Carry application fragments over MAVLink V2_EXTENSION. |
MavApplicationPeer |
Send notifications and correlated requests and track peer liveness. |
MavApplicationDispatcher |
Run registered packet handlers with bounded worker capacity. |
Runtime methods
| Method | Behavior |
|---|---|
start() / stop() |
Start or stop the runtime and its owned services. |
subscribe(filter, callback) |
Route matching MAVLink messages to a synchronous callback. |
once(filter, callback) |
Register a callback for one matching message. |
wait_for(filter, timeout=None) |
Return one matching message or None after timeout. |
latest(filter=None) |
Return the latest matching message or None. |
notify(packet_type, payload=None) |
Send a one-way application packet; requires an application role. |
request(packet_type, payload=None, ...) |
Send a correlated application request and wait for a response. |
handle(packet_type, handler) |
Register an application handler; returns a cancellable subscription. |
Public types and errors
The package exports these public names:
| Area | Public names |
|---|---|
| Transport and routing | MavEndpoint, MavConnection, MavMessageRouter, MavMessageFilter, MavMessageEnvelope, MavHeader, MavMessage, MavRouterStats, MessageCache |
| Runtime and async | MavClient, MavRuntime, MavRuntimeState, MavAsyncChannel |
| Application protocol | MavApplicationPacket, MavApplicationCodec, MavApplicationAssembler, MavApplicationChannel, MavApplicationPeer, MavApplicationDispatcher, MavApplicationHandlerRegistry, MavApplicationResult, MavApplicationResponse |
| Remote logs | MavRemoteLogLevel, MavRemoteLogRecord, MavRemoteLogBatch |
MavHeader and MavMessage are defined in mavflow.contracts and
re-exported from mavflow.
Key error types include MavUnavailableError, MavRouterError,
MavRuntimeError, and MavApplicationProtocolError. Import the
specific error classes from mavflow when an application needs to handle them.
Development and license
The project supports Python 3.10 and newer and uses setuptools as its build backend. From the project root, install development dependencies and run the checks:
python -m pip install -e ".[dev]"
python run_tests.py
python -m coverage run --branch -m unittest discover -s tests -v
python -m coverage report --fail-under=75
python -m ruff check .
python -m ruff format --check .
python -m pyright
python -m build
python -m twine check dist/*
The test suite includes a real pymavlink UDP loopback check. For that test
alone, run python -m unittest tests.test_pymavlink_integration -v.
The benchmark suite uses pyperf for
calibration, worker processes, and JSON result suites. Install the dev extra,
then run a benchmark module from the repository root:
python -m benchmarks.benchmark_router --output router-run.json
python -m benchmarks.benchmark_codec --output codec-run.json
python -m pyperf show --metadata --stats router-run.json
python -m pyperf compare_to --table benchmarks/results/router.json router-run.json
Use a fresh output filename for each run; pyperf does not overwrite an
existing result file. The router benchmark measures single-reader delivery
through a preloaded in-memory connection. The codec benchmark measures
application packet encoding and reassembly. --fast is for CI smoke checks;
use the default calibration for local measurements. Results are specific to
their recorded interpreter, platform, source fingerprint, and workload. They
are not deployment guarantees. See
benchmarks/results/README.md for the workload
definitions and comparison guidance.
The CHANGELOG records the extraction from
Vehicle Autonomy Core.
Copyright © 2026 TahsinCr. Mavflow is licensed under the MIT License. See LICENSE.
Metadata
Release files for mavflow 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mavflow-1.0.tar.gz | 85.9 kB | Without provenance | Details for mavflow-1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mavflow-1.0-py3-none-any.whl | Python 3 | none | any | Details for mavflow-1.0-py3-none-any.whl |
Total release size: 130.6 kB
Release files / mavflow-1.0.tar.gz
| Download URL | mavflow-1.0.tar.gz |
|---|---|
| Size | 85.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fed590a145c9c0b11bf3d81a9dff0267c4ef18e6c09346e573baaf99fc9734b2
|
|
BLAKE2b-256 checksum How to use checksums |
6aff238bb206099a1bfd89e30e881a3f777f01c5dae6be60d1b129690325139b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.9
|
Release files / mavflow-1.0-py3-none-any.whl
| Download URL | mavflow-1.0-py3-none-any.whl |
|---|---|
| Size | 44.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4d9e4aa35567b8c550c951cfa19849a6f06a7f895ff39fe5d84238538ed0197b
|
|
BLAKE2b-256 checksum How to use checksums |
dd11f4496ef972e61b422395d56a87eb9623ae239dd8ee1883e9d83b5886c8fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.9
|
Security for mavflow 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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.