Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Native python SDK for Eclipse ioFog development.

Project description


This SDK is divided in two parts: client and deploy.


Install python package:

sudo python2 -m pip install iofog-python-sdk


This module lets you easily build an ioElement. It gives you all the functionality to interact with ioFog via Local API. It contains all necessary methods for IoMessage transformation as well.

  • send new message to ioFog (post_message)
  • fetch next unread messages from ioFog (get_next_messages)
  • fetch messages for time period and list of accessible publishers (get_next_messages_from_publishers_within_timeframe)
  • get config options (get_config)
  • create IoMessage, encode(decode) to(from) raw bytes, marshall(unmarshall) into(from) JSON object (IoMessage class methods)
  • connect to ioFog Control Channel via WebSocket (establish_control_ws_connection)
  • connect to ioFog Message Channel via WebSocket (establish_message_ws_connection) and publish new message via this channel (post_message_via_socket)

Code snippets:

Import iofog client and additional classes to your project:

from iofog_python_sdk.client.client import IoFogClient
from iofog_python_sdk.client.exception import IoFogException
from iofog_python_sdk.client.iomessage import IoMessage
from iofog_python_sdk.client.listener import *

Create IoFog client with default settings:

    client = IoFogClient()
except IoFogException as e:
 # client creation failed, e contains description

Or specify host, port, ssl and container id explicitly:

    client = IoFogClient(id='container_id', host='iofog_host', port=6666)
except IoFogException as e:
 # client creation failed, e contains description
REST calls

Get list of next unread IoMessages:

    messages = client.get_next_messages()
except IoFogException as e:
 # some error occurred, e contains description

Post new IoMessage to ioFog via REST call:


    receipt = client.post_message(msg)
except IoFogException, e:
 # some error occurred, e contains description

Get an array of IoMessages from specified publishers within given timeframe:

query = {
    	'timeframestart': 1234567890123,
    	'timeframeend': 1234567890123,
    	'publishers': ['sefhuiw4984twefsdoiuhsdf', 'd895y459rwdsifuhSDFKukuewf', 'SESD984wtsdidsiusidsufgsdfkh']
    query_response = client.get_next_messages_from_publishers_within_timeframe(query)
except IoFogException, e:
 # some error occurred, e contains description

Get container's config:

    config = client.get_config()
except IoFogException, ex:
 # some error occurred, ex contains description
WebSocket calls

To use websocket connections you should implement listeners as follows:

class MyControlListener(IoFogControlWsListener):
    def on_control_signal(self):
        # do smth on control signal

class MyMessageListener(IoFogMessageWsListener):
    def on_receipt(self, message_id, timestamp):
        # do smth with message receipt

    def on_message(self, io_msg):
        # do smth with new message

After that you can establish websocket connections:


Each of those connections will be managed in a separate thread.

After successful connection to message websocket you can send to it:

Message utils

Construct IoMessage from JSON(both json string and python dictionary are acceptable):

msg = IoMessage.from_json(json_msg)

IoMessage to JSON:

json_str = io_msg_instance.to_json()

Construct IoMessage from raw bytes:

msg = IoMessage.from_bytearray([0, 4, ...])

Pack IoMessage into bytearray:

msg_bytes = io_msg_instance.to_bytearray()


This module lets you easily communicate with the Controller REST API.

  • Deploy flow, microservices, agents, etc.
  • Edit microservice configuration
  • Edit flow routing

Code snippets

Import iofog deploy client

from iofog_python_sdk.deploy.create_rest_call import rest_call
from iofog_python_sdk.deploy.microservice_service import microservices

Update microservice config

controller_address = http://localhost:51121/api/v3
microservice_service = microservices()

def iofog_auth(controller_address, email, password):
    data = {}
    data["email"] = email
    data["password"] = password
    post_address = "{}/user/login".format(controller_address)
    jsonResponse = rest_call(data, post_address)
    auth_token = jsonResponse["accessToken"]
    return auth_token

auth_token = iofog_auth(controller_address, "", "myPassword")
flow_id = 1
current_microservice = microservice_service.get_microservice_by_name(controller_address, "my_microservice", flow_id, auth_token)

updated_microservice = current_microservice
updated_microservice.config = {"newKey": 42}

microservice_service.update_microservice(controller_address, updated_microservice, current_microservice.iofogUuid, catalog_id, auth_token)


This module is very much a Work In Progress. It was first written as a set of helper functions used by a python script to deploy a set of microservices configured using yaml files.

Our golang SDK is more adapted and modular for communicating with the Controller REST API

Project details

Download files

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

Files for iofog-python-sdk, version 1.3.0
Filename, size File type Python version Upload date Hashes
Filename, size iofog_python_sdk-1.3.0-py3-none-any.whl (4.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size iofog-python-sdk-1.3.0.tar.gz (4.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page