A FastAPI interface for loading, managing and running Droneleaf Petal applications
Project description
Petal App Manager
A modular application framework for building and deploying "Petals" - pluggable components that can interact with various systems through a unified proxy architecture. Built on FastAPI, Petal App Manager provides a structured way to develop applications that need to interact with external systems like MAVLink devices, Redis, local databases, and more.
Overview
Petal App Manager serves as a backbone for developing modular applications. It:
- Provides a proxy system to interact with different backends (MAVLink, Redis, DynamoDB)
- Offers a plugin architecture for developing and loading "Petals"
- Handles HTTP, WebSocket, and MQTT (planned) endpoints automatically
- Manages the lifecycle of connections and resources
Dependencies
-
Python 3.10+ and
python3-devpackage (for building some dependencies)sudo add-apt-repository ppa:deadsnakes/ppa --yes sudo apt update; apt-get update; sudo apt-get install python3.10 -y sudo apt-get install python3.10-dev
[!NOTE] You can change
python3.10to whatever version you like>=3.10
-
Redis server (for caching and message passing)
# Install Redis on Ubuntu/Debian sudo apt-get install redis-server # Start Redis service sudo systemctl start redis-server sudo systemctl enable redis-server # Auto-start on boot
-
Controller-dashboard setup
The controller dashboard can be installed using
hear-cli local_machine run_program --p controller_dashboard_prepare
-
Additional dependencies based on specific petals
Installation
Dependencies Setup
- For building pymavlink from source, ensure GCC is used (see above)
export CC=gcc
pdm install -G prod
Installation From PyPI (recommended for users)
pip install petal-app-manager
You may run the server using
# Install and run with uvicorn
uvicorn petal_app_manager.main:app --port 9000
[!TIP] If you would like to run the server with logging to a file enabled: create a
.envfile and place it in the project root directory Below is a list of some other useful parameters# .env file for Petal App Manager configuration # General configuration PETAL_LOG_LEVEL=INFO PETAL_LOG_TO_FILE=true # MAVLink configuration MAVLINK_ENDPOINT=udp:127.0.0.1:14551 MAVLINK_BAUD=115200 MAVLINK_MAXLEN=200 MAVLINK_WORKER_SLEEP_MS=1 MAVLINK_HEARTBEAT_SEND_FREQUENCY=5.0 ROOT_SD_PATH=fs/microsd/log # Cloud configuration ACCESS_TOKEN_URL=http://localhost:3001/session-manager/access-token SESSION_TOKEN_URL=http://localhost:3001/session-manager/session-token S3_BUCKET_NAME=devhube21f2631b51e4fa69c771b1e8107b21cb431a-dev CLOUD_ENDPOINT=https://api.droneleaf.io # Local database configuration LOCAL_DB_HOST=localhost LOCAL_DB_PORT=3000 # Redis configuration REDIS_HOST=localhost REDIS_PORT=6379 REDIS_DB=0 REDIS_UNIX_SOCKET_PATH=/var/run/redis/redis-server.sock # Data operations URLs GET_DATA_URL=/drone/onBoard/config/getData SCAN_DATA_URL=/drone/onBoard/config/scanData UPDATE_DATA_URL=/drone/onBoard/config/updateData SET_DATA_URL=/drone/onBoard/config/setData # MQTT client TS_CLIENT_HOST=localhost TS_CLIENT_PORT=3004 CALLBACK_HOST=localhost CALLBACK_PORT=3005 POLL_INTERVAL=1.0 ENABLE_CALLBACKS=true
Development Installation (recommended for developers)
For development of petal-app-manager concurrently with your petal, it's recommended to use an editable installation.
- First clone the
petal-app-manager
[!NOTE] Please see the petal development guide first
```bash
git clone https://github.com/DroneLeaf/petal-app-manager.git
git clone https://github.com/DroneLeaf/petal-flight-log.git
git clone --recurse-submodules https://github.com/DroneLeaf/mavlink.git
cd petal-app-manager
```
-
Define your dev dependancies (i.e., your petal) in pyproject.toml as
dev = [ # your existing dependancies "-e file:///${PROJECT_ROOT}/../petal-flight-log/#egg=petal-flight-log", "-e file:///${PROJECT_ROOT}/../mavlink/pymavlink/#egg=leaf-pymavlink", # ... "-e file:///path/to/your/my-petal/#egg=my-petal" ]
[!NOTE] If you would like to develop mavlink or add user-defined mavlink messages, you may do so under your local clone of
mavlinkhttps://github.com/DroneLeaf/mavlink.gitpymavlinkwill be available at/path/to/mavlink/pymavlinkunder the mavlink directory. You can then add it to pyproject.tomldev = [ "-e file:///path/to/pymavlink/#egg=leaf-pymavlink", ]
[!TIP] You may use relative paths intead of absolute paths like so (assuming your directories are one level higher than
petal-app-manager)cd .. # if in the petal-app-manager directory git clone --recurse-submodules https://github.com/DroneLeaf/mavlink.gitand then add them to your dependancies under pyproject.toml
dev = [ # existing petals "-e file:///${PROJECT_ROOT}/../mavlink/pymavlink/#egg=leaf-pymavlink", "-e file:///${PROJECT_ROOT}/../my-petal/#egg=my-petal", ]
-
Finally, you may install your dependancies in editable mode
pdm install -G dev
-
You may now run the
petal-app-managerserversource .venv/bin/activate # to activate the pdm virtual environment in which everythign is installed uvicorn petal_app_manager.main:app --reload --port 9000
-
Test your endpoints:
- Access your petal at:
http://localhost:9000/petals/my-petal/hello - Check the API documentation:
http://localhost:9000/docs
- Access your petal at:
[!TIP] For debugging, you can use VSCode's launch configuration:
- Add this to
.vscode/launch.json:{ "version": "0.2.0", "configurations": [ { "name": "Petal App Manager", "type": "python", "request": "launch", "module": "uvicorn", "args": [ "petal_app_manager.main:app", "--reload", "--port", "9000" ], "jinja": true, "justMyCode": false } ] }- Start debugging with F5 or the Run and Debug panel
Project Structure
petal_app_manager/
├── __init__.py
├── main.py # FastAPI application setup
├── api/ # Core API endpoints
├── plugins/ # Plugin architecture
│ ├── base.py # Base Petal class
│ ├── decorators.py # HTTP/WebSocket decorators
│ └── loader.py # Dynamic petal loading
├── proxies/ # Backend communication
│ ├── base.py # BaseProxy abstract class
│ ├── external.py # MAVLink/ROS communication
│ ├── localdb.py # Local DynamoDB interaction
│ └── redis.py # Redis interaction
└── utils/ # Utility functions
How It Works
Proxy System
The framework uses proxies to interact with different backends:
MavLinkExternalProxy: Communicates with PX4/MAVLink devicesRedisProxy: Interfaces with Redis for caching and pub/subLocalDBProxy: Provides access to a local DynamoDB instance
Proxies are initialized at application startup and are accessible to all petals.
Accessing the API
Once running, access:
- API documentation: http://localhost:9000/docs
- ReDoc documentation: http://localhost:9000/redoc
- Petal endpoints: http://localhost:9000/petals/{petal-name}/{endpoint}
Troubleshooting
Common Issues
-
Redis Connection Errors:
- Ensure Redis server is running:
sudo systemctl status redis-server - Check default connection settings in main.py
- Ensure Redis server is running:
-
MAVLink Connection Issues:
- Verify the connection string
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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file petal_app_manager-0.1.33.tar.gz.
File metadata
- Download URL: petal_app_manager-0.1.33.tar.gz
- Upload date:
- Size: 145.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1a3e402195b015358e6dd159fc73aff4fc1cbf96bfe69422153d44c422f3367
|
|
| MD5 |
0485bb3671104e462ffe5587bf58952f
|
|
| BLAKE2b-256 |
c9ac4f8637dc19606772e9b66983fad3f80392d9f124bc551686b4405b430ef8
|
File details
Details for the file petal_app_manager-0.1.33-py3-none-any.whl.
File metadata
- Download URL: petal_app_manager-0.1.33-py3-none-any.whl
- Upload date:
- Size: 135.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
310eb915bb499e2a373abfd2986bccc6b73fd76893b5bc2123206c14972bbe57
|
|
| MD5 |
8134d265a1476cf556da9bfc82067503
|
|
| BLAKE2b-256 |
7a74a3b6b3c32309c8a6c1b43f0ae8eb54f4fc79ed8410da53807d4e6b8254cb
|