# Disruptive Technologies Python Client
![build](https://github.com/disruptive-technologies/python-client/actions/workflows/build.yml/badge.svg)
[![codecov](https://codecov.io/gh/disruptive-technologies/python-client/branch/main/graph/badge.svg)](https://codecov.io/gh/disruptive-technologies/python-client)
## Documentation
- [Python API Reference](https://developer.disruptive-technologies.com/api/libraries/python/)
- [Developer Documentation](https://developer.disruptive-technologies.com/docs/)
## Installation
The package can be installed through pip:
```sh
pip install --upgrade disruptive
```
or from source:
```sh
pip install .
```
### Requirements
- Python 3.9-3.13
## Authentication
The package is authenticated by providing [Service Account](https://developer.disruptive-technologies.com/docs/service-accounts/introduction-to-service-accounts) credentials in either of the following ways.
- By setting the following environment variables:
```bash
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:
```python
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](https://developer.disruptive-technologies.com/api/libraries/python/client/authentication.html) 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](https://developer.disruptive-technologies.com/api/libraries/python/) for full documentation.
```python
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`.
```python
dt.log_level = dt.logging.INFO
```
If more fine-grained control is desired, the standard library `logging` can also be used.
```python
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](https://developer.disruptive-technologies.com/api/libraries/python/client/examples.html) has been provided. Before running, the required environment variables listed at the start of each example must be set.
```sh
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](https://developer.disruptive-technologies.com/api/libraries/python/client/errors.html).
## 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
```
Raw data
{
"_id": null,
"home_page": "https://github.com/disruptive-technologies/disruptive-python",
"name": "disruptive",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "disruptive, technologies, dt, rest, api",
"author": "Disruptive Technologies Research AS",
"author_email": "developer-support@disruptive-technologies.com",
"download_url": "https://files.pythonhosted.org/packages/82/f2/05718cda2fcba610912400490611d9a58d36306e184d31064c96b2facdd7/disruptive-1.7.0.tar.gz",
"platform": null,
"description": "# Disruptive Technologies Python Client\n\n![build](https://github.com/disruptive-technologies/python-client/actions/workflows/build.yml/badge.svg)\n[![codecov](https://codecov.io/gh/disruptive-technologies/python-client/branch/main/graph/badge.svg)](https://codecov.io/gh/disruptive-technologies/python-client)\n\n## Documentation\n\n- [Python API Reference](https://developer.disruptive-technologies.com/api/libraries/python/)\n- [Developer Documentation](https://developer.disruptive-technologies.com/docs/)\n\n## Installation\n\nThe package can be installed through pip:\n\n```sh\npip install --upgrade disruptive\n```\n\nor from source:\n\n```sh\npip install .\n```\n\n### Requirements\n\n- Python 3.9-3.13\n\n## Authentication\n\nThe package is authenticated by providing [Service Account](https://developer.disruptive-technologies.com/docs/service-accounts/introduction-to-service-accounts) credentials in either of the following ways.\n\n- By setting the following environment variables:\n```bash\nexport DT_SERVICE_ACCOUNT_KEY_ID=\"<SERVICE_ACCOUNT_KEY_ID>\"\nexport DT_SERVICE_ACCOUNT_SECRET=\"<SERVICE_ACCOUNT_SECRET>\"\nexport DT_SERVICE_ACCOUNT_EMAIL=\"<SERVICE_ACCOUNT_EMAIL>\"\n```\n\n- By providing the credentials programmatically:\n```python\nimport disruptive as dt\n\ndt.default_auth = dt.Auth.service_account(\n key_id=\"<SERVICE_ACCOUNT_KEY_ID>\",\n secret=\"<SERVICE_ACCOUNT_SECRET>\",\n email=\"<SERVICE_ACCOUNT_EMAIL>\",\n)\n```\n\nSee [Python API Authentication](https://developer.disruptive-technologies.com/api/libraries/python/client/authentication.html) for more details.\n\n## Usage\n\nOnce authenticated, most functionality can be accessed through resource methods on the following format.\n\n```\ndisruptive.<Resource>.<method>()\n```\n\nA few common uses are showcased in the snippet below. See the [Python API Reference](https://developer.disruptive-technologies.com/api/libraries/python/) for full documentation.\n\n```python\nimport disruptive as dt\n\n# Fetch a sensor, specified by its ID.\nsensor = dt.Device.get_device('<DEVICE_ID>')\n\n# Printing the returned object will list all attributes.\nprint(sensor)\n\n# Set a new label on the sensor.\ndt.Device.set_label(sensor.device_id, sensor.project_id, key='nb', value='99')\n\n# Get touch- and temperature event history for the sensor.\nhistory = dt.EventHistory.list_events(\n sensor.device_id,\n sensor.project_id,\n event_types=[\n dt.events.TOUCH,\n dt.events.TEMPERATURE,\n ]\n)\n\n# Initiate an event stream for all devices in the sensor's project.\nfor event in dt.Stream.event_stream(sensor.project_id):\n # Print new events data as they arrive.\n print(event.data)\n```\n\n## Logging\nThe simplest method is enabled by setting `disruptive.log_level`.\n```python\ndt.log_level = dt.logging.INFO\n```\nIf more fine-grained control is desired, the standard library `logging` can also be used.\n```python\nlogging.basicConfig(\n filename='example.log',\n format='[%(asctime)s.%(msecs)03d] %(levelname)-8s - %(message)s',\n datefmt='%Y-%m-%d %H:%M:%S',\n)\nlogging.getLogger('disruptive').setLevel(logging.INFO)\n``` \nFor both methods, the standard levels `DEBUG`, `INFO`, `WARNING`, `ERROR`, and `CRITICAL` are supported.\n\n## Examples\nA few [examples](https://developer.disruptive-technologies.com/api/libraries/python/client/examples.html) has been provided. Before running, the required environment variables listed at the start of each example must be set.\n\n```sh\npython examples/example_name.py\n```\n\n## Exceptions\nIf 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](https://developer.disruptive-technologies.com/api/libraries/python/client/errors.html).\n\n## Development\n\nSet up the development virtualenv environment:\n```\nmake\n```\n\nRun unit-tests against the currently active python version:\n```\nmake test\n```\n\nLint the package code using MyPy and flake8:\n```\nmake lint\n```\n\nBuild the package distribution:\n```\nmake build\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Disruptive Technologies Python API.",
"version": "1.7.0",
"project_urls": {
"Developers Page": "https://developer.disruptive-technologies.com/docs/",
"Documentation": "https://developer.disruptive-technologies.com/api/libraries/python/",
"Homepage": "https://github.com/disruptive-technologies/disruptive-python"
},
"split_keywords": [
"disruptive",
" technologies",
" dt",
" rest",
" api"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3cf0331a0cf220d785599447689bba804dda94f0c7454460535ea7aaf700ec5c",
"md5": "b7c30429b1d522aa2ee2d05315783615",
"sha256": "a988cdab88a2a5f78b21567a1c79c318077fc1381c9d9fc1354259ea300f29d9"
},
"downloads": -1,
"filename": "disruptive-1.7.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b7c30429b1d522aa2ee2d05315783615",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 53473,
"upload_time": "2024-10-10T08:29:27",
"upload_time_iso_8601": "2024-10-10T08:29:27.695687Z",
"url": "https://files.pythonhosted.org/packages/3c/f0/331a0cf220d785599447689bba804dda94f0c7454460535ea7aaf700ec5c/disruptive-1.7.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "82f205718cda2fcba610912400490611d9a58d36306e184d31064c96b2facdd7",
"md5": "b137ffa75de0aadb329c32ca1730d236",
"sha256": "83be49d92bab37bc1917cfab6faee3b6d3d510de75483844c0553062455f3060"
},
"downloads": -1,
"filename": "disruptive-1.7.0.tar.gz",
"has_sig": false,
"md5_digest": "b137ffa75de0aadb329c32ca1730d236",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 58624,
"upload_time": "2024-10-10T08:29:28",
"upload_time_iso_8601": "2024-10-10T08:29:28.866474Z",
"url": "https://files.pythonhosted.org/packages/82/f2/05718cda2fcba610912400490611d9a58d36306e184d31064c96b2facdd7/disruptive-1.7.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-10 08:29:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "disruptive-technologies",
"github_project": "disruptive-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "disruptive"
}