# 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.8+
## 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": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"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/a7/6c/45bdf8789e9f79cb03d2b032d47959cdb55ff6417f306fc60a9921c34a06/disruptive-1.6.6.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.8+\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": "",
"summary": "Disruptive Technologies Python API.",
"version": "1.6.6",
"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": "e034457f54e80add16e5303f691470c18a844f20fc5a480236c2a394f2e7ead5",
"md5": "c4e9ba5fcb8ede983ab0e6b9c105ee9b",
"sha256": "f20e14b29e56032123a865464c376e7bdf1fc860de4d81be4beda72f2fceae6d"
},
"downloads": -1,
"filename": "disruptive-1.6.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c4e9ba5fcb8ede983ab0e6b9c105ee9b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 53155,
"upload_time": "2024-02-22T08:34:14",
"upload_time_iso_8601": "2024-02-22T08:34:14.007986Z",
"url": "https://files.pythonhosted.org/packages/e0/34/457f54e80add16e5303f691470c18a844f20fc5a480236c2a394f2e7ead5/disruptive-1.6.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a76c45bdf8789e9f79cb03d2b032d47959cdb55ff6417f306fc60a9921c34a06",
"md5": "cd40f5110aeb8c32f47588ca130234a1",
"sha256": "0807700361babc316f90e5155bf58aef6b67e94e0c27de6117ec4b79d821b0a3"
},
"downloads": -1,
"filename": "disruptive-1.6.6.tar.gz",
"has_sig": false,
"md5_digest": "cd40f5110aeb8c32f47588ca130234a1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 43142,
"upload_time": "2024-02-22T08:34:15",
"upload_time_iso_8601": "2024-02-22T08:34:15.989105Z",
"url": "https://files.pythonhosted.org/packages/a7/6c/45bdf8789e9f79cb03d2b032d47959cdb55ff6417f306fc60a9921c34a06/disruptive-1.6.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-22 08:34:15",
"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"
}