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 disruptive as dt
# Using serviceaccount credentials, authenticate the package.
dt.default_auth = dt.Auth.serviceaccount(key_id, secret, 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
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
module 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 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.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4a003a022be00273b9f1731ed0834d572f1c2ac294516b2ebacba0005411677 |
|
MD5 | c8fbe39378c19d75d5f620471137ca42 |
|
BLAKE2b-256 | 25c22fa72d87e0591358be840848c4d873a741c868cb3fe9b5a60a82c654964f |