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.9-3.13
Authentication
The package is authenticated by providing Service Account credentials in either of the following ways.
- By setting the following environment variables:
export DT_SERVICE_ACCOUNT_KEY_ID="<SERVICE_ACCOUNT_KEY_ID>"
export DT_SERVICE_ACCOUNT_SECRET="<SERVICE_ACCOUNT_SECRET>"
export DT_SERVICE_ACCOUNT_EMAIL="<SERVICE_ACCOUNT_EMAIL>"
- By providing the credentials programmatically:
import disruptive as dt
dt.default_auth = dt.Auth.service_account(
key_id="<SERVICE_ACCOUNT_KEY_ID>",
secret="<SERVICE_ACCOUNT_SECRET>",
email="<SERVICE_ACCOUNT_EMAIL>",
)
See Python API Authentication for more details.
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
.
dt.log_level = dt.logging.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 supported.
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
File details
Details for the file disruptive-1.7.0.tar.gz
.
File metadata
- Download URL: disruptive-1.7.0.tar.gz
- Upload date:
- Size: 58.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83be49d92bab37bc1917cfab6faee3b6d3d510de75483844c0553062455f3060 |
|
MD5 | b137ffa75de0aadb329c32ca1730d236 |
|
BLAKE2b-256 | 82f205718cda2fcba610912400490611d9a58d36306e184d31064c96b2facdd7 |
File details
Details for the file disruptive-1.7.0-py3-none-any.whl
.
File metadata
- Download URL: disruptive-1.7.0-py3-none-any.whl
- Upload date:
- Size: 53.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a988cdab88a2a5f78b21567a1c79c318077fc1381c9d9fc1354259ea300f29d9 |
|
MD5 | b7c30429b1d522aa2ee2d05315783615 |
|
BLAKE2b-256 | 3cf0331a0cf220d785599447689bba804dda94f0c7454460535ea7aaf700ec5c |