Python SDK for reading and writing signals to Clarify.
Project description
PyClarify
Useful tutorials and documentation
- PyClarify SDK
- PyClarify documentation
- Clarify Developer documentation
- Basic tutorial on using Python with Clarify
- Clarify Forecast tutorial
- Pattern Recognition tutorial
- Google Cloud Hosting tutorial
Prerequisites
In order to start using the Python SDK, you need
- To know a bit of Python. For a refresher, see the Official Python tutorial.
- Python3 (>= 3.7) and pip.
- Credentials from a Clarify integration. See the introduction notebook for a complete introduction.
Install and import PyClarify
To install this package:
$ pip install pyclarify
import pyclarify
Interact with Clarify
PyClarify provides a fast and easy way to write data into Clarify, create or update the signal metadata and get item data, by using the APIClient
class.
This class takes as an argument the path of your credentials in string format, which should always be the first step when starting to interact with PyClarify.
For information about the Clarify Developer documentation click her.
Add Signal metadata
To add or update the signal's metadata, use the save_signals
method.
Step 1 : Create a SignalInfo
model.
Step 2 : Use the save_signals
method.
Example: Add Signal metadata
>>> from pyclarify import APIClient, SignalInfo
>>> client = APIClient("./clarify-credentials.json")
>>> signal_1 = SignalInfo(
>>> name="Home temperature",
>>> description="Temperature in the bedroom",
>>> labels={"data-source": ["Raspberry Pi"], "location": ["Home"]},
>>> )
>>> signal_2 = SignalInfo(
>>> name="Home humidity",
>>> description="Humidity in the living room",
>>> labels={"data-source": ["Raspberry Pi"], "location": ["Home"]},
>>> )
>>> response = client.save_signals(
>>> params={"inputs": {"id1": signal_1, "id2": signal_2}, "createOnly": False}
>>> )
>>> print(response.json())
Write data into Clarify
Step 1: Create a DataFrame
model.
Step 2: Use the insert
method which takes as an argument the DataFrame model.
Example: Write data into Clarify
>>> from pyclarify import DataFrame, APIClient
>>> client = APIClient("./clarify-credentials.json")
>>> data = DataFrame(
>>> series={"id1": [1, 2, 3, None], "id2": [3, 4, None, 5]},
>>> times=[
>>> "2021-11-09T21:50:06Z",
>>> "2021-11-10T21:50:06Z",
>>> "2021-11-12T21:50:06Z",
>>> "2021-11-12T21:50:06Z",
>>> ],
>>> )
>>> response = client.insert(data)
>>> print(response.json())
Get Signal meta-data
This call retrieves signal meta-data and/or exposed items. This call is a recommend step before doing a publishSignals call. For more information click here.
Step 1: Create the params dictionary.
Step 2: Call the select_signals
method.
Example: Get Signal meta-data
>>> from pyclarify import APIClient
>>> client = APIClient("./clarify-credentials.json")
>>> response = client.select_signals(
>>> params={
>>> "signals": {
>>> "include": True,
>>> "filter": {"id": {"$in": ["<signal_id>"]}},
>>> },
>>> "items": {
>>> "include": True,
>>> },
>>> }
>>> )
>>> print(response.json())
Publish signals
Publish one or more Signals by providing the SignalInfo, which will add metadata to your created Item.
Example: Publish signals
>>> from pyclarify import APIClient, SignalInfo
>>> client = APIClient("./clarify-credentials.json")
>>> response = client.publish_signals(
>>> params={
>>> "itemsBySignal": {"<signal_id>": SignalInfo(name="<item_name>")},
>>> "createOnly": False,
>>> }
>>> )
>>> print(response.json())
Get Item data
To get the data from an item, you must first have an integration with reading access.
Once reading access is enabled, use the select_items
method.
Step 1: Create the params dictionary.
Step 2: Call the select_items
method.
Example: Get Item data
>>> from pyclarify import APIClient
>>> client = APIClient("./clarify-credentials.json")
>>> response = client.select_items(
>>> params={
>>> "items": {"include": True, "filter": {"id": {"$in": ["<item_id>"]}}},
>>> "data": {"include": True},
>>> }
>>> )
>>> print(response.json())
Changelog
Wondering about upcoming or previous changes to the SDK? Take a look at the CHANGELOG.
Contributing
Want to contribute? Check out CONTRIBUTING.
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 pyclarify-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a2ae6db3a566973ceb4f14bb17cdb1bf666d19718addbb2032c4dad844545bb |
|
MD5 | a8da9193d8a4b1fca0628d826a7932b1 |
|
BLAKE2b-256 | 291bcd65fbc6153be9d5b40a90a1da00be53146dd8441397fb2410c8f9c2bd47 |