Code Monkey home page Code Monkey logo

python-sdk's Introduction

Enapter Python SDK

CI PyPI version Code Style

Enapter software development kit for Python.

⚠️ This project is work in progress. The API is not stable and may change at any time. ⚠️

Installation

Stable from PyPI:

pip install enapter

Latest for GitHub:

pip install git+https://github.com/Enapter/python-sdk#egg=enapter

Usage

Checkout examples.

Implementing your own VUCM

Device Telemetry and Properties

Every method of enapter.vucm.Device subclass with a name that starts with task_ prefix is considered a device task. When such a device is started, all of its tasks are started as well. Device tasks are started in random order and are being executed concurrently in the background. If a device task returns or raises an exception, device routine is terminated. A typical use of the task is to run a periodic job to send device telemetry and properties.

In order to send telemetry and properties define two corresponding device tasks. It is advised (but is not obligatory) to send telemetry every 1 second and to send properties every 10 seconds.

Examples:

Device Commands

Every method of enapter.vucm.Device subclass with a name that starts with cmd_ prefix is considered a device command handler. Device command handlers receive the same arguments as described in device Blueprint manifest and can optionally return a payload as dict.

In order to handle device commands define corresponding device command handlers.

Examples:

Device Alerts

Device alerts are stored in self.alerts. It is a usual Python set, so you can add an alert using alerts.add, remove an alert alerts.remove and clear alerts using alerts.clear.

Alerts are sent only as part of telemetry, so in order to report device alert, use send_telemetry with any payload.

Running your own VUCM via Docker

A simple Dockerfile can be:

FROM python:3.10-alpine3.16

WORKDIR /app

RUN python -m venv .venv
COPY requirements.txt requirements.txt
RUN .venv/bin/pip install -r requirements.txt

COPY script.py script.py

CMD [".venv/bin/python", "script.py"]

ℹ️ If you are using Enapter Gateway and running Linux, you should connect your containers to host network :information_source::

docker run --network host ...

python-sdk's People

Contributors

dimonzozo avatar kulti avatar nkrasko avatar rnovatorov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

python-sdk's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.