Skip to main content

EnOS API SDK for Python

Project description

Using EnOS Service SDK for Python (Preview Edition)

This repo contains the preview edition of EnOS Service SDK for Python. This article instructs how to prepare your development environment and use the EnOS Service SDK for Python.

Installing Python

To use the EnOS Service SDK for Python, you will need Python 2.7.13+ or 3.5.3+, and pip is required.

Obtaining EnOS Service SDK for Python

You can obtain the SDK through the following methods:

  • Install from pip
  • Download the source code by cloning this repo and build on your machine

Installing from PIP

Use the following command to install EnOS Service SDK for Python from PIP.

pip install enos-api-sdk-python

Building from Source Code

  1. Obtain the EnOS Service SDK for Python source code from GitHub:

    git clone https://github.com/EnvisionIot/enos-api-sdk-python.git
    
  2. From the directory where the source code is stored, run the following command:

    python setup.py install
    

Key Features

As the preview edition, the EnOS Service SDK for Python currently contains only partial of the EnOS Service REST API features as listed below:

  • Apply certificate by device key
  • Post measure point data
  • Create and list products

API Reference

To access the EnOS API documentation, go to EnOS API > API Documents in the EnOS Console. For each service category, you can check the summary of the APIs from the API list table and click the More icon for view details of each specific API, including API description, calling method, requesting URL, parameter description, calling sample, and response sample.

Sample Code

This sample demonstrates how to post a struct type of measure point to the EnOS Cloud.

from enosapi.request.PostMeasurepointsEnOSRequest import PostMeasurepointsEnOSRequest
from enosapi.client.EnOSDefaultClient import EnOSDefaultClient
import time
import json

enos_api_url = "https://{HOST}/enosapi/"

# the application configuration created in console
access_key = "ACCESS_KEY"
secret_key = "SECRET_KEY"

# sub-device parameters
device_asset_id = 'DEVICE_ASSET_ID'
product_key = 'PRODUCT_KEY'

# OU ID
org_id = "OU_ID"


if __name__ == "__main__":
    timestamp = int(time.time() * 1000)  # timestamp in milliseconds
    struct_measure_point = {'Image1': 'local://file1',
			 'Sensor': 'PM2_5',
			 'UpperLimit': 100,
			 'Value': 120,
			 'AlertFlag': 1,
			 'AlertMessage': 'PM10 over limit'}

    measure_points = {
        'Image0': struct_measure_point
    }

    data = [{
        'measurepoints': measure_points,
        'assetId': device_asset_id,
        'time': timestamp
    }]

    param = {
        "data": json.dumps(data)
    }

    # two files named apple.png and orange.png should be put into the same directory as this code file
    file_to_upload = {"file1": open("image1.jpg", 'rb')}

    request = PostMeasurepointsEnOSRequest(org_id=org_id, product_key=product_key, params=param,
                                           upload_file=file_to_upload)

    enos_api_client = EnOSDefaultClient(enos_api_url, access_key, secret_key)

    response = enos_api_client.execute(request)
    print(response.status, response.msg)

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

enos-api-sdk-python-0.0.4.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

enos_api_sdk_python-0.0.4-py2-none-any.whl (10.4 kB view details)

Uploaded Python 2

File details

Details for the file enos-api-sdk-python-0.0.4.tar.gz.

File metadata

  • Download URL: enos-api-sdk-python-0.0.4.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15

File hashes

Hashes for enos-api-sdk-python-0.0.4.tar.gz
Algorithm Hash digest
SHA256 b845445a24853a68efb274361f572d64deb599c6842451f09f230acc79b86c84
MD5 ec9a899ef1541bfa508afb2c7e92baa0
BLAKE2b-256 a5c1427f3a4fa5edda1be58cdfba3fd7df2121d7e6116f7c4bb3d68be31da310

See more details on using hashes here.

File details

Details for the file enos_api_sdk_python-0.0.4-py2-none-any.whl.

File metadata

  • Download URL: enos_api_sdk_python-0.0.4-py2-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15

File hashes

Hashes for enos_api_sdk_python-0.0.4-py2-none-any.whl
Algorithm Hash digest
SHA256 0ca4f3b8f71ed1f76fb004aa2890b3936a6f5b3ded09e592559cc41c50d6aee5
MD5 d09af6197f237296747bdd89cec80017
BLAKE2b-256 b49bc563e2b69f800427ec4a1337cde5edb1041ccef4518d6f4db34bfc60d220

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