Skip to main content

Receive and respond to Helin Platform edge-module-requests.

Project description

helin-edge-sdk

The Helin Edge SDK allows you to securely and reliably get and set JSON payloads via the Helin Platform's edge-module-requests API: get_configuration, set_configuration and get_health to your containers (modules) deployed on Nodes on the edge.

For more information see https://docs.helinplatform.com

Install

pip install helin-edge-sdk

Usage

Implement the three methods and run the client:

from typing import Any
from helin_edge_sdk import EdgeModuleRequestsHandler, EdgeModuleClient, ConfigurationFailedError

class MyModule(EdgeModuleRequestsHandler):
    def __init__(self) -> None:
        self.configuration = {"opcua_ip": "123.34.233.1", "opcua_port": 4840, "poll_interval_ms": 1000}

    def on_get_configuration(self, payload: dict[str, Any]) -> Any:
        return self.configuration

    def on_set_configuration(self, payload: dict[str, Any]) -> Any:
        cfg = payload.get("configuration")
        if cfg is None:
            raise ConfigurationFailedError("missing configuration", status_code=400,
                                           current_configuration=self.configuration)
        self.configuration = cfg
        return {"configuration": cfg}

    def on_get_health(self, payload: dict[str, Any]) -> Any:
        return {"metrics": [{"name": "opcua_connected", "value": 1}]}

EdgeModuleClient.from_edge_environment(MyModule()).run() #Fetches all required env variables on your provisioned Node

Each callback receives the decompressed request payload and returns a JSON-serializable value, which is wrapped as {"status": 200, "response": <value>}

compressed, and published back to the caller.

Raise ConfigurationFailedError to return the configuration-failure envelope:

{"status": <code>, "response": {"error": ..., "current_configuration": ...}}.

Status codes

Handler outcome Status
Returns a value 200
Raises ValueError 400
Raises ConnectionError 400
Unknown method 400
Raises FileNotFoundError 404
Raises ConfigurationFailedError its status_code (default 409)
Raises any other exception 500

Local testing

# 1. start a plaintext broker
docker compose -f docker/docker-compose.test.yml up -d

# 2. run the module against it
python -m examples.run_local

# 3. invoke a method (simulates the Platform API)
python -m examples.publish_method get_health
python -m examples.publish_method set_configuration '{"configuration": {"opcua_ip": "10.0.0.5", "opcua_port": 4840}}'

Develop

poetry install
poetry run pytest -m "not integration"   # unit tests, no broker
poetry run pytest                        # all tests (needs the broker above)
poetry run ruff check
poetry run ty check

Architecture

flowchart TB
    subgraph platform["Cloud"]
        API["Platform API <br/> POST /api/v1/edge-module-requests/nodes/{node_id}/modules/{module_id} <br/> GET /api/v1/edge-module-requests/nodes/{node_id}/modules/{module_id} <br/> GET /api/v1/edge-module-requests/nodes/{node_id}/modules/{module_id}/health"]
    end

    subgraph hub["Azure IoT Hub (Cloud)"]
        IOTHUB
    end

    subgraph edge["Node — Edge runtime"]
        EDGEHUB["edgeHub<br/>MQTT broker :8883 (TLS)"]
        WL["Edge workload API<br/>unix:///…/workload.sock<br/>/sign · /trust-bundle"]

        subgraph mod["Module using helin-edge-sdk"]
            direction TB
            CLIENT["EdgeModuleClient<br/>from_edge_environment()"]
            LISTENER["MqttModuleListener<br/>(paho-mqtt transport)"]
            HANDLER["EdgeModuleRequestsHandler<br/>(your on_* callbacks)"]
            CLIENT --> LISTENER
            LISTENER -- "dispatch(method, payload)" --> HANDLER
            HANDLER -- "result / ConfigurationFailedError" --> LISTENER
        end
    end

    API <== "edge-module-requests<br/>(gzip payload)" ==> IOTHUB
    IOTHUB <== "cloud uplink" ==> EDGEHUB

    EDGEHUB -- "SUB - (gzip payload)" --> LISTENER
    LISTENER -- "PUB - (gzip payload)" --> EDGEHUB

    LISTENER -- "SAS token + trust bundle" --> WL

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

helin_edge_sdk-0.0.2.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

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

helin_edge_sdk-0.0.2-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file helin_edge_sdk-0.0.2.tar.gz.

File metadata

  • Download URL: helin_edge_sdk-0.0.2.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for helin_edge_sdk-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2a54d7d882f136ad3f594bf9f7e324383252db00e9fab842b2ae3c1682117d77
MD5 39e9598c7aecc2423d18fa6d102d37ba
BLAKE2b-256 38ad02434a55e1f83c9d2e96e9c1f9b08417bb077e88cbe22681515d835ebd62

See more details on using hashes here.

File details

Details for the file helin_edge_sdk-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: helin_edge_sdk-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for helin_edge_sdk-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dea4761a0aa9268a6a30d9678234d7293faa80d213c2d09aaeaad6d608513de0
MD5 bdf54b1f1905fe1691a7ab0fd83e865c
BLAKE2b-256 16941cdca5ea8238817519cc017d70fe3c978a70d5474104927926c050e31b56

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