# Disruptive Technologies Python Client

[](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/38/bd/dfd04df5429e1f70e2d21895b61511ac52cad2418d110d15daff59a66145/disruptive-1.7.2.tar.gz",
"platform": null,
"description": "# Disruptive Technologies Python Client\n\n\n[](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.2",
"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": null,
"digests": {
"blake2b_256": "1817504f75f8c37148152a1f691a50d3ea2ef6b5914e0806e5e3c9dbf1824c53",
"md5": "ce6e77635a3210677586875845c52372",
"sha256": "c9368f5f698581d10717b4f569714436256d2b6abd35ec93b76e5ca461da0ec4"
},
"downloads": -1,
"filename": "disruptive-1.7.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ce6e77635a3210677586875845c52372",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 54002,
"upload_time": "2025-01-24T12:49:59",
"upload_time_iso_8601": "2025-01-24T12:49:59.504424Z",
"url": "https://files.pythonhosted.org/packages/18/17/504f75f8c37148152a1f691a50d3ea2ef6b5914e0806e5e3c9dbf1824c53/disruptive-1.7.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "38bddfd04df5429e1f70e2d21895b61511ac52cad2418d110d15daff59a66145",
"md5": "35c2f7b82914812af5e1b9e96dc5f9df",
"sha256": "8dae6e3f42a6281121eb87770c68baa40008812fdac55ce63297e19e9ede0ce0"
},
"downloads": -1,
"filename": "disruptive-1.7.2.tar.gz",
"has_sig": false,
"md5_digest": "35c2f7b82914812af5e1b9e96dc5f9df",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 59290,
"upload_time": "2025-01-24T12:50:00",
"upload_time_iso_8601": "2025-01-24T12:50:00.694141Z",
"url": "https://files.pythonhosted.org/packages/38/bd/dfd04df5429e1f70e2d21895b61511ac52cad2418d110d15daff59a66145/disruptive-1.7.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-24 12:50:00",
"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"
}