Disruptive Technologies Python API.
Project description
Disruptive Technologies Python Client
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 disruptive as dt
dt.default_auth = dt.Auth.service_account(key_id, secret, email)
Usage
Once authenticated, most functionality can be accessed through resource methods on the following format.
disruptive.<Resource>.<method>()
A few common uses are showcased in the snippet below. See the Python API Reference for full documentation.
import disruptive as dt
# Fetch a sensor, specified by its ID.
sensor = dt.Device.get_device('<DEVICE_ID>')
# Printing the returned object will list all 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 for the sensor.
history = dt.EventHistory.list_events(
sensor.device_id,
sensor.project_id,
event_types=[
dt.events.TOUCH,
dt.events.TEMPERATURE,
]
)
# Initiate an event stream for all devices in the sensor's project.
for event in dt.Stream.event_stream(sensor.project_id):
# Print new events data as they arrive.
print(event.data)
Logging
The simplest method is enabled by setting disruptive.log_level
with a string level.
dt.log_level = 'info'
If more fine-grained control is desired, the standard library logging
can also be used.
logging.basicConfig(
filename='example.log',
format='[%(asctime)s.%(msecs)03d] %(levelname)-8s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
)
logging.getLogger('disruptive').setLevel(logging.INFO)
For both methods, the standard levels debug
, info
, warning
, error
, and critical
are available.
Examples
A few examples has been provided. Before running, the required environment variables listed at the start of each example must be set.
python examples/example_name.py
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 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-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f09ae3efc7deb367651757ebc3cf6cdc8d23d2410cf3c7c2b6c25740e6c2c452 |
|
MD5 | 29b422ba3dea2b08eaa1b874848e2e13 |
|
BLAKE2b-256 | 232d445d9792ddf36aa90407104460480b785f7f763814103e082b1c67f9d6b4 |