Last updated

Quick Start Guide:

The Python SDK provides modules for developing an IIoT Edge App using Python 3.8 or higher. All examples assume this has been installed.

You should also update 'pip':

> pip install -U pip

Create an Edge App

The IIoT Edge App Python SDK provides the following modules combined within one Python package called agoraiot:

  • agora_logging
  • agora_busclient
  • agora_config
  • agora_utils

To install the package use:

> pip install agoraiot

Alternatively, create a requirements.txt file and place all dependencies there.

"Hello World!"

Create a helloWorld.py file:

from agoraiot import logger

logger.info("Hello World!")

Execute using Python:

> python helloWorld.py

Creating an Edge Application Container Image

Create the following files:

helloworld.py [from above]
Dockerfile

Dockerfile:

FROM python:3.12-alpine3.21
ADD ./src app
RUN pip install agoraiot
ADD requirements.txt /
RUN pip3 install -r requirements.txt
WORKDIR /app
CMD python3 app/helloWorld.py

Run the following command to build the image:

> docker build .

The SDK is available for CSharp application. Details to setup application using CSharp SDK is Quick Guide for CSharp

Configuring and using the SDK in your application

1. Configuration at startup

  • Applications can be configured at startup in the following ways:
    • Defaults
    • Default configuration files (AEA.json)
  • Supports prioritized configuration overlays.

2. Configuration at runtime

  • Configure applications dynamically at runtime using:
    • External configuration files (AEA.json) published in Redis via Twin Property
  • Additional details found in the Configuration Tutorial.

3. Messaging Framework

  • Advanced messaging via NATS for efficient communication between edge and cloud systems.
  • Among supported topics:
    • slbapps.<app-name>.DataIn/slbapps.<app-name>.DataOut: Data messages
    • slbapps.<app-name>.RequestIn/slbapps.<app-name>.RequestOut: Application services requests
    • slbapps.<app-name>.EventIn/slbapps.<app-name>.EventOut: Alerts and events
  • Additional details found in the BusClient Tutorial.

4. Digital Twins

  • Synchronize desired (cloud) and reported (edge) properties to maintain an accurate representation of physical devices.
  • Properties are grouped into Twin Property Groups for easy management.
  • Configuration AEA.json can also be submitted using Twin Property under config group
  • Additional details found in the Twin Property Tutorial.

Deployment

  • Applications are deployed in containers to ensure isolation and security.
  • Containers are distributed via a private container registry and scanned for security compliance.

IRIS

  • IRIS environment comes with Redis and NATS

Local Development

For local development, you can run both NATS and Redis locally either installed on the host or as docker containers.

Install Redis or run as a docker container, e.g.:

  • $ docker run --name alpine-redis -d redis:latest

Install NATS or run as a docker container, e.g:

  • $ docker run --name nats-server -p 4222:4222 nats:latest

Sample AEA.json with local Redis and NATS

{
    "Name": "MyApp",
    "AEA2": {
        "RedisClient": {
            "Server": "localhost",
            "Port": "6379"
        },
        "BusClient": {
            "Server": "nats://localhost:4222"
        }
      }
}

Alternatively, you may point your application config file to a deployed IRIS environment if the external IP of the gateway is known.

Sample AEA.json with IRIS-deployed gateway

{
    "Name": "MyApp",
    "AEA2": {
        "RedisClient": {
            "Server": "163.188.xxx.xxx",
            "Port": "6379"
        },
        "BusClient": {
            "Server": "nats://163.188.xxx.xxx:4222"
        }
      }
}