Skip to main content

Interact with Coiote DM API

Project description

Coiote Python

python-coiote is a Python package providing access to the Coiote DM server API. It supports v3 Coiote DM API.

If you spot an issue, have a feature request or would like to discuss anything else, you're welcome to join Coiote Discord community.

Features

python-coiote enables you to:

  • interact with Coiote DM v3 API to manage your devices, groups and domains,
  • automatically URL-encode path parameters whenever needed,
  • convert API responses to convenient Python data classes,
  • conveniently deal with batch/paginated responses from v3 API,
  • handle authentication errors and retries,

and more.

Installation

python-coiote is compatible with Python >= 3.7.

Use pip to install the latest stable version of python-coiote:

pip install --upgrade python-coiote

Authentication

There are two ways of authenticating in Coiote API when using this SDK:

  • Using credentials to your Coiote account:
from coiote.auth import Credentials
from coiote.client import Coiote


client = Coiote(url="https://eu.iot.avsystem.cloud", auth=Credentials("<your-username>", "<your-password>")) 

Since Coiote does not support generating API tokens yet, preferably, you should create a separate account in your Coiote domain that will have the permissions only to access the API endpoints you intend to use.

  • Using a raw token acquired manually using the oauth endpoint in v3 API:
from coiote.client import Coiote

client = Coiote(url="https://eu.iot.avsystem.cloud", auth="<your-token>") 

Using device client

python-coiote comes with builtin high level client designed for accessing specific device and to do so, composes multiple API calls. To read more, see Device Client class. The device client supports a set of basic operations:

client = Coiote(url="https://eu.iot.avsystem.cloud", auth="<token>")
endpoint_name = "device_name"
device = client.create_device_client(endpoint_name)

Get the whole datamodel or its parts:

device.get_all_data()
device.get_resource_value("Device.0.Timezone")

Schedule writing value to device's data model (it's async, method returns task ID):

write_task_id = device.write_to_resource("Device.0.Timezone", "Kraków/Radzikowskiego")

Schedule reading value from the actual device into its data model (it's async, method returns task ID):

read_task_id = device.read_resource("Device.0.Timezone")

Manually schedule executing a resource on a device (it's async, method returns task ID):

execute_task_id = device.execute_resource("Device.0.Reboot")

Schedule reboot of the device (it's async, method returns task ID):

reboot_task_id = device.reboot_device()

Get recently reported location:

device.get_location()

Access the device historical data - only for resources from objects with ID > 502:

from datetime import datetime, timedelta

start_time = datetime.now() - timedelta(minutes=15)
end_time = datetime.now()
data = c.device_monitoring.get_data_batch(endpoint_name, lwm2m_url="/3303/0/5700", start_time=start_time, end_time=end_time)

Download device data from given time range and save it to CSV using pandas:

import pandas as pd
from datetime import datetime, timedelta

device_id = "<enter device ID or endpointname>"
url = "<enter resource URL>"

# Pick last 30 days 
start_time = datetime.now() - timedelta(days=30)

# Download data
data = c.device_monitoring.get_all_data(device_id, lwm2m_url=url, start_time=start_time)

# Map data to Pandas dataframe and save it to CSV
data = {"value": [datapoint.value for datapoint in data],
        "datetime": [datapoint.date for datapoint in data]}
df = pd.DataFrame(data)
df.to_csv("<enter CSV file name>.csv")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_coiote-2.11.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

python_coiote-2.11.0-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

Details for the file python_coiote-2.11.0.tar.gz.

File metadata

  • Download URL: python_coiote-2.11.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for python_coiote-2.11.0.tar.gz
Algorithm Hash digest
SHA256 302fa2a1ca0937da4f779cf15283fd1f72fe4f0f432b5f0721c5341b1253ea60
MD5 29cc164c5278b4a438f4e1ba798b66e8
BLAKE2b-256 4c26c04584e77730d705aef464adcc15dea397fa8356ea75d6af9a1e110c265e

See more details on using hashes here.

File details

Details for the file python_coiote-2.11.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_coiote-2.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38dc40e038c9cd2d392d8946afe9cc73ad1b4f631a8c73de3228f79c454b2ddf
MD5 86d2ed946458f09e12782c620e08f373
BLAKE2b-256 0d54fe19e28e6a8bfd5bd46a7910bfc5f3bb21566c045c03862c5f26aa999215

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page