Iot API
Project description
Arduino iot-api Python client
Requirements
- Python 3.7+
Installation
You can install the package directly from Github (you may need to run pip
with
sudo
):
pip install arduino-iot-client
Getting Started
Authentication
The client requires a valid access token, you can use requests-oauthlib
to get
one, to install the library do:
pip install requests-oauthlib
After installing the library you can use this Python code to get a token:
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
oauth_client = BackendApplicationClient(client_id=YOUR_CLIENT_ID)
token_url = "https://api2.arduino.cc/iot/v1/clients/token"
oauth = OAuth2Session(client=oauth_client)
token = oauth.fetch_token(
token_url=token_url,
client_id=YOUR_CLIENT_ID,
client_secret=YOUR_CLIENT_SECRET,
include_client_id=True,
audience="https://api2.arduino.cc/iot",
)
print(token.get("access_token"))
Once you get a token, you can create an instance of the iot-api client:
import iot_api_client as iot
from iot_api_client.rest import ApiException
from iot_api_client.configuration import Configuration
# configure and instance the API client
client_config = Configuration(host="https://api2.arduino.cc/iot")
client_config.access_token = YOUR_ACCESS_TOKEN
client = iot.ApiClient(client_config)
# as an example, interact with the devices API
devices_api = iot.DevicesV2Api(client)
try:
resp = devices_api.devices_v2_list()
print(resp)
except ApiException as e:
print("Got an exception: {}".format(e))
For a working example, see the example folder in this repo.
How to get Arduino IoT Cloud Client Credentials
You can generate Arduino IoT Cloud Client Credentials in the ARDUINO API
section in the IoT Cloud things section:
Step 1
Step 2
Step 3
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for arduino_iot_client-2.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d1e869fa7526ce05112c0b46dbea37eeec3e45ec38304d0edbb5f54642ebbce |
|
MD5 | 4a03a87d8e011e04362b0681955c34bd |
|
BLAKE2b-256 | 4192a9278bf233b19df44c60ecee34105fcc5e8f5fb172f025cb08fff98b2c79 |