Skip to main content

Python SDK for reading and writing signals to Clarify.

Project description

Clarify logo

PyClarify

PyPI package version number Actions Status License Code style: black

Useful tutorials and documentation

Prerequisites

In order to start using the Python SDK, you need

Install and import PyClarify

To install this package:

$ pip install pyclarify

import pyclarify

Interact with Clarify

PyClarify provides a fast and easy way to interact with Clarify using the APIClient and ClarifyClient 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.

The APIClient and ClarifyClient class can do the almost the same operations, but the ClarifyClient provides a more pythonic way.

For information about the Clarify Developer documentation click here.

Using Python with Clarify

Open In Colab

Use colab to learn fast end easy how to interact with Clarify using Python. In this introduction tutorial you will learn all the basics to get you started.

Quickstart

Save signals

Example:

from pyclarify import ClarifyClient, SignalInfo

client = ClarifyClient("./clarify-credentials.json")

signal = SignalInfo(
   name = "Home temperature",
   description = "Temperature in the bedroom",
   labels = {"data-source": ["Raspberry Pi"], "location": ["Home"]}
)

response = client.save_signals(input_ids=["<INPUT_ID>"], signals=[signal], create_only=False)
print(response.json())

Insert data into a signal

Example:

from pyclarify import DataFrame, ClarifyClient

client = APIClient("./clarify-credentials.json")

date = ["2021-11-01T21:50:06Z",  "2021-11-02T21:50:06Z"]

data = DataFrame(
    series={"<INPUT_ID_1>": [1, None], "<INPUT_ID_2>": [None, 5]},
    times = date,
)

response = client.insert(data)
print(response.json())

Get metadata from signals and/or items

Example:

from pyclarify import ClarifyClient

client = ClarifyClient("./clarify-credentials.json")

response = client.select_signals(
                ids = ['<SIGNAL_ID>'],
                name = "Electricity",
                labels = {"city": "Trondheim"},
                limit = 10,
                skip = 0,
                include_items = False
)
print(response.json())

Publish signals

Example:

from pyclarify import ClarifyClient, Item

client = ClarifyClient("./clarify-credentials.json")

item = Item(
   name = "Home temperature",
   description = "Temperature in the bedroom",
   labels = {"data-source": ["Raspberry Pi"], "location": ["Home"]},
   visible=True
)
response = client.publish_signals(signal_ids=['<SIGNAL_ID>'], items=[item], create_only=False)
print(response.json())

Get Item data

Example:

from pyclarify import ClarifyClient

client = ClarifyClient("./clarify-credentials.json")

response = client.select_items_data(
    ids = ['<ITEM_ID>'],
    limit = 10,
    skip = 0,
    not_before = "2021-10-01T12:00:00Z",
    before = "2021-11-10T12:00:00Z",
    rollup = "P1DT"
)
print(response.json())

Get Item metadata

Example:

from pyclarify import ClarifyClient

client = ClarifyClient("./clarify-credentials.json")

response = client.select_items_metadata(
    ids = ['<ITEM_ID>'],
    name = "Electricity",
    labels = {"city": "Trondheim"},
    limit = 10,
    skip = 0
)
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


Download files

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

Source Distribution

pyclarify-0.3.1.tar.gz (22.9 kB view hashes)

Uploaded Source

Built Distribution

pyclarify-0.3.1-py3-none-any.whl (30.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page