DriftClient
drift_client.DriftClient
¶
Drift Python Client Class
__init__(host, password, **kwargs)
¶
Drift Client for easy access to Compute Devices on the Drift Platform
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host |
str
|
hostname or IP of Compute Device |
required |
password |
str
|
password to access data |
required |
Other Parameters:
Name | Type | Description |
---|---|---|
user |
str
|
A user of the platform. Default: "panda" |
org |
str
|
An organisation name. Default: "panda" |
secure |
bool
|
Use HTTPS protocol to access data: Default: False |
minio_port |
int
|
Minio port. Default: 9000 |
reduct_port |
int
|
Reduct port. Default: 8383 |
influx_port |
int
|
InfluxDB port. Default: 8086, |
mqtt_port |
int
|
MQTT port. Default: 1883 |
loop |
asyncio loop for integration into async code |
get_item(path)
¶
Returns requested single historic data from initialised Device
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
path of item in storage |
required |
Raises:
Type | Description |
---|---|
ValueError
|
In case of broken WaveletBuffer |
Returns:
Type | Description |
---|---|
DriftDataPackage
|
Parsed Drift Package |
Examples:
>>> client = DriftClient("127.0.0.1", "PASSWORD")
>>> client.get_item("topic-1/1644750605291.dp")
get_list(topics, timeframe)
¶
Returns list of history data from initialised Device
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topics |
List[str]
|
List of topic names, e.g. |
required |
timeframe |
List[str]
|
List with begin and end of request timeframe,
Format: |
required |
Returns:
Type | Description |
---|---|
Dict[str, List[str]]
|
List of item names available |
:rtype: List[str]
Examples:
>>> client = DriftClient("127.0.0.1", "PASSWORD")
>>> client.get_list(["topic-1", "topic-2", "topic-3"],
>>> ["2022-02-03 10:00:00", "2022-02-03 10:00:10"])
>>> # => {"topic-1": ['topic-1/1644750600291.dp',
>>> # 'topic-1/1644750601291.dp', ...] ... }
get_metrics(topic, start, stop, names=None)
¶
Reads history metrics from timeseries database
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topic |
str
|
MQTT topic |
required |
start |
Union[float, datetime, str]
|
Begin of request timeframe, Format: ISO string, datetime or float timestamp |
required |
stop |
Union[float, datetime, str]
|
End of request timeframe, Format: ISO string, datetime or float timestamp |
required |
names |
Optional[List[str]]
|
Name of metrics, if None get all metrics for the topic |
None
|
Examples
>>> client = DriftClient("127.0.0.1", "PASSWORD")
>>> client.get_metrics("topic", "2022-02-03 10:00:00",
>>> "2022-02-03 10:00:10", names=["status", "field"])
>>> #=> [{"status": 0, "field": 0.1231}, ....]
get_package_names(topic, start, stop)
¶
Returns list of history data from initialised Device
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topic |
str
|
Topic name |
required |
start |
Union[float, datetime, str]
|
Begin of request timeframe, Format: ISO string, datetime or float timestamp |
required |
stop |
Union[float, datetime, str]
|
End of request timeframe, Format: ISO string, datetime or float timestamp |
required |
Returns:
Type | Description |
---|---|
List[str]
|
List with item names available |
Examples:
>>> client = DriftClient("127.0.0.1", "PASSWORD")
>>> client.get_package_names("topic-1",
>>> "2022-02-03 10:00:00", "2022-02-03 10:00:10")
>>> # => ['topic-1/1644750600291.dp',
>>> # 'topic-1/1644750601291.dp', ...]
get_topics()
¶
Returns list of topics (measurements in InfluxDB)
Returns:
Type | Description |
---|---|
List[str]
|
List of topics available |
Examples:
>>> client = DriftClient("127.0.0.1", "PASSWORD")
>>> client.get_topics() # => ['topic-1', 'topic-2', ...]
publish_data(topic, payload)
¶
Publishes payload to selected topic on initialised Device
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topic |
str
|
MQTT topic |
required |
payload |
bytes
|
Stringified data, defaults to None |
required |
Examples >>> client = DriftClient("127.0.0.1", "PASSWORD") >>> client.publish_data("topic-2", b"hello")
subscribe_data(topic, handler)
¶
Subscribes to selected topic from initialised Device
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topic |
str
|
MQTT topic |
required |
handler |
Callable[[DriftDataPackage], None]
|
Handler - own handler function to be used, e.g.
|
required |
Examples:
>>> def package_handler(package: DriftDataPackage) -> None:
>>> print(package.meta)
>>>
>>> client = DriftClient("127.0.0.1", "PASSWORD")
>>> client.subscribe_data("topic-1", package_handler)
walk(topic, start, stop)
¶
Walks through history data for selected topic
Parameters:
Name | Type | Description | Default |
---|---|---|---|
topic |
str
|
Topic name |
required |
start |
Union[float, datetime, str]
|
Begin of request timeframe, Format: ISO string, datetime or float timestamp |
required |
stop |
Union[float, datetime, str]
|
End of request timeframe, Format: ISO string, datetime or float timestamp |
required |
Returns:
Type | Description |
---|---|
Iterator[DriftDataPackage]
|
Iterator with DriftDataPackage |
Examples:
>>> client = DriftClient("127.0.0.1", "PASSWORD")
>>> for pkg in client.walk("topic-1", "2022-02-03 10:00:00",
"2022-02-03 10:00:10")
>>> print(pkg)