Disruptive Technologies Python API.
Project description
Disruptive Technologies Python API
Documentation
Installation
The package can be installed through pip:
pip install --upgrade disruptive
or from source:
pip install .
Requirements
- Python 3.7+
Authentication
Using Service Account credentials, setting disruptive.default_auth
authenticates the package:
import os
import disruptive as dt
# Using serviceaccount credentials, authenticate the package.
dt.default_auth = dt.Auth.serviceaccount(
key_id=os.environ.get('DT_SERVICE_ACCOUNT_KEY_ID', ''),
secret=os.environ.get('DT_SERVICE_ACCOUNT_SECRET', ''),
email=os.environ.get('DT_SERVICE_ACCOUNT_EMAIL', ''),
)
Usage
API methods are grouped under various resource names on the form disruptive.<Resource>.<method>()
.
# Fetch a specific temperature sensor from a project.
sensor = dt.Device.get_device(device_id)
# Print the sensor information, listing all available attributes.
print(sensor)
# Set a new label on the sensor.
dt.Device.set_label(sensor.device_id, sensor.project_id, key='nb#', value='99')
# Get touch- and temperature event history the last 24 hours for the sensor.
history = dt.EventHistory.list_events(
sensor.device_id,
sensor.project_id,
event_types=['touch', 'temperature']
)
# Set up a real-time event stream for the sensor.
for new_event in dt.Stream.device(sensor.device_id, sensor.project_id):
# Print the data in new events as they arrive.
print(new_event.data)
Logging
Information about outbound requests and their response can be printed to console by setting:
dt.log = True
Examples
A few examples showcasing various uses for the package has been provided. They do not require additional dependencies and can, provided the package has been installed, be run by:
python example_name.py
or from root using the source code:
python -m examples.example_name
Exceptions
If a request is unsuccessful or has been provided with invalid parameters, an exception is raised. A list of available exceptions are available in the API Reference.
Development
Set up the development virtualenv environment:
make
Run unit-tests against the currently active python version:
make test
Lint the package code using MyPy and flake8:
make lint
Build the sphinx documentation:
make docs
Build the package distribution:
make build
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 disruptive-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b60811cdf433f56369499743b89d4fd5f40150c1fb518ad8419980088a762be6 |
|
MD5 | c9a0539d454480a9e88eb1b8c851fde1 |
|
BLAKE2b-256 | 6c9c64bdae267c207ff92c3c38b64a70139a18d3519e4c4074052d64215609c9 |