Library for connecting to iobeam, the data analysis platform for the Internet of Things.
Project description
`iobeam <http://iobeam.com>`__ is a data platform for connected devices.
Please note that we are currently invite-only. You will need an invite to generate a valid token and use our APIs. (Sign up `here <http://iobeam.com>`__ for an invite.)
Before you start
pip install requests
Installation
To install with pip:
pip install iobeam
To install from source:
git clone https://github.com/iobeam/iobeam-client-python.git
Then make sure that the iobeam-client-python folder is in your PYTHONPATH.
Overview
This library allows Python clients to send data to the iobeam Cloud.
At a high-level, here’s how it works:
- Build an iobeam client object with your project_id andproject_token
- Register your device to get an auto-generated device_id. Optionally,you can initialize the object with a previously registered device_id inthe previous step and skip this step
- Create a iobeam.DataPoint object for each time-series data point. Or,for a collection of data points, create a iobeam.DataSeries object.
Add the DataPoint under your series_name (e.g., “temperature”)
When you’re ready, send your data to the iobeam Cloud
Getting Started
iobeam Initialization
Without a registered ``device_id``
Let iobeam generate one for you:
from iobeam import iobeam ... builder = iobeam.ClientBuilder(PROJECT_ID, PROJECT_TOKEN) \ .saveToDisk().registerDevice() iobeamClient = builder.build()
Provide your own (must be unique to your project):
from iobeam import iobeam ... builder = iobeam.ClientBuilder(PROJECT_ID, PROJECT_TOKEN) \ .saveToDisk().registerDevice(deviceId="my_desired_id") iobeamClient = builder.build()
With a registered ``device_id``
from iobeam import iobeam ... builder = iobeam.ClientBuilder(PROJECT_ID, PROJECT_TOKEN) \ .saveToDisk().setDeviceId(DEVICE_ID) iobeamClient = builder.build()
Advanced: not saving to disk
builder = iobeam.ClientBuilder(PROJECT_ID, PROJECT_TOKEN).registerDevice() iobeamClient = builder.build()
Tracking Time-series Data
For each time-series data point, create a iobeam.DataPoint object:
t = getTemperature() d = iobeam.DataPoint(t) # You can also pass a specific timestamp now = ... # e.g., now = int(time.time()*1000) (import time first) d = iobeam.DataPoint(t, timestamp=now)
iobeamClient.addDataPoint("temperature", d)
now = ... # current time dt = iobeam.DataPoint(getTemperature(), timestamp=now) dh = iobeam.DataPoint(getHumidity(), timestamp=now) iobeamClient.addDataPoint("temperature", dt) iobeamClient.addDataPoint("humidity", dh)
Connecting to the iobeam Cloud
iobeamClient.send()
Full Example
Here’s the full source code for our example:
from iobeam import iobeam import time # Constants initialization PATH = ... # Can be None if you don't want to persist device_id to disk PROJECT_ID = ... # int PROJECT_TOKEN = ... # String ... # Init iobeam builder = iobeam.ClientBuilder(PROJECT_ID, PROJECT_TOKEN) \ .saveToDisk().registerDevice() iobeamClient = builder.build() ... # Data gathering now = int(time.time()*1000) dt = iobeam.DataPoint(getTemperature(), timestamp=now) dh = iobeam.DataPoint(getHumidity(), timestamp=now) iobeamClient.addDataPoint("temperature", dt) iobeamClient.addDataPoint("humidity", dh) ... # Data transmission iobeamClient.send()
Retrieving Data
In the simplest form, here is how you make a few different queries:
# all series from all devices in project PROJECT_ID q = iobeam.QueryReq(PROJECT_ID) # all series from device DEVICE_ID in project PROJECT_ID q = iobeam.QueryReq(PROJECT_ID, deviceId=DEVICE_ID) # series "temp" from device DEVICE_ID in project PROJECT_ID q = iobeam.QueryReq(PROJECT_ID, deviceId=DEVICE_ID, seriesName="temp")
Then to actually execute the query:
# token is a project token with read access res = iobeam.MakeQuery(token, q)
Your result will look something like this:
{ "result": [ { "project_id": "<PROJECT_ID>", "device_id": "<DEVICE_ID>", "name": "temp", "data": [ { "time": 1427316488000, "value": 22.23 }, { "time": 1427316489000, "value": 22.22 }, ... ] }, ... ], "timefmt": "msec" }
Adjusting Your Query
# start with this basic query q = iobeam.QueryReq(PROJECT_ID, deviceId=DEVICE_ID, seriesName="temp") # Last 5 results after a given START_TIME: q = q.limit(5).fromTime(START_TIME) # All results between two times, START and END q = q.fromTime(START).toTime(END) # All results where the value is greater than 0 q = q.greaterThan(0)
The full list of (chainable) parameters:
limit(limit) fromTime(time) toTime(time) greaterThan(value) lessThan(value) equals(value)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for iobeam-0.1.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3663d749adfd0ee2b793337c3176bcbfbc129b04fa4ef78b603e7587494d346 |
|
MD5 | 3260622391a88be9d62c4349ecab0139 |
|
BLAKE2b-256 | 16baffad4582e2c1e6e849e0ff4b97a93d97c6c771dba2d9c6684b983db3e14f |