Skip to main content

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-dev package (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.10 to 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 .env file and place it in the project root directory Below is a list of some other useful parameters

PETAL_LOG_LEVEL=INFO
PETAL_LOG_TO_FILE=true
PETAL_LOG_FILE_PATH=./app.log
MAVLINK_ENDPOINT=udp:127.0.0.1:14551
MAVLINK_BAUD=115200
MAVLINK_MAXLEN=200
MAVLINK_POLLING_FREQUENCY=200.0

Development Installation (recommended for developers)

For development of petal-app-manager concurrently with your petal, it's recommended to use an editable installation.

  1. 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
```
  1. 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 mavlink https://github.com/DroneLeaf/mavlink.git pymavlink will be available at /path/to/mavlink/pymavlink under the mavlink directory. You can then add it to pyproject.toml

dev = [
    "-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.git

and 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",
]
  1. Finally, you may install your dependancies in editable mode

    pdm install -G dev
    
  2. You may now run the petal-app-manager server

    source .venv/bin/activate # to activate the pdm virtual environment in which everythign is installed
    uvicorn petal_app_manager.main:app --reload --port 9000
    
  3. Test your endpoints:

    • Access your petal at: http://localhost:9000/petals/my-petal/hello
    • Check the API documentation: http://localhost:9000/docs

[!TIP] For debugging, you can use VSCode's launch configuration:

  1. 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
            }
        ]
    }
    
  2. 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 devices
  • RedisProxy: Interfaces with Redis for caching and pub/sub
  • LocalDBProxy: 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:

Troubleshooting

Common Issues

  • Redis Connection Errors:

    • Ensure Redis server is running: sudo systemctl status redis-server
    • Check default connection settings in main.py
  • MAVLink Connection Issues:

    • Verify the connection string

Project details


Download files

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

Source Distribution

petal_app_manager-0.1.10.tar.gz (51.4 kB view details)

Uploaded Source

Built Distribution

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

petal_app_manager-0.1.10-py3-none-any.whl (46.1 kB view details)

Uploaded Python 3

File details

Details for the file petal_app_manager-0.1.10.tar.gz.

File metadata

  • Download URL: petal_app_manager-0.1.10.tar.gz
  • Upload date:
  • Size: 51.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for petal_app_manager-0.1.10.tar.gz
Algorithm Hash digest
SHA256 55bbf8df07079dce9f6ef9c9768e8e5df8df7d40092d46221a6b671f1660ef60
MD5 fdafddc862676709a0fffdb4efa67a83
BLAKE2b-256 194734d6361623b150c51ad4d0042d71ab69d3b2a08561f6834f4229391e80a0

See more details on using hashes here.

File details

Details for the file petal_app_manager-0.1.10-py3-none-any.whl.

File metadata

File hashes

Hashes for petal_app_manager-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 ea31a8cf62dada3ced3b119442f98a96f583b5a5adfb6214efdcff4ca9dac13c
MD5 d3568fdc8b57a8f69a2c0459df24de99
BLAKE2b-256 52df618996fbd38e2d76df14ea2ea5a743e6182882beac40a5da1dda601d243c

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