Arduino iot-api Python client
Requirements
- Python 3.10+
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"))
In case of organization access, you can add organization identifier specifying required header:
org_id="<org-id>"
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",
headers={"X-Organization":org_id}
)
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.exceptions import ApiException
from iot_api_client.models import *
from iot_api_client.configuration import Configuration
from iot_api_client.api import DevicesV2Api
# configure and instance the API client
client_config = Configuration(host="https://api2.arduino.cc")
client_config.access_token = YOUR_ACCESS_TOKEN
client = iot.ApiClient(client_config)
# as an example, interact with the devices API
devices_api = deviceApi.DevicesV2Api(client)
client_config = Configuration(host="https://api2.arduino.cc")
client_config.access_token = access_token
client = iot.ApiClient(client_config)
try:
api_instance = DevicesV2Api(client)
api_response = api_instance.devices_v2_list()
for device in api_response:
print(device.name+" - id:"+device.id+" - type:"+device.type)
except ApiException as e:
print("Exception when calling DevicesV2Api->devices_v2_list: %s\n" % e)
In case of organization access, you can specify organization identifier in this way:
client = iot.ApiClient(client_config,header_name="X-Organization",header_value=org_id)
# or you can specify at method level, like:
api_instance.devices_v2_list(x_organization="org_id")
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 API Keys section in the IoT Cloud:
Step 1
Step 2
Step 3
Metadata
Release files for arduino-iot-client 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| arduino_iot_client-3.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / arduino_iot_client-3.0.0-py3-none-any.whl
| Download URL | arduino_iot_client-3.0.0-py3-none-any.whl |
|---|---|
| Size | 234.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
105285ebddec3cfda68f4da96bae47ae86a9eea86ce02a2d068ff7675278e6ed
|
|
BLAKE2b-256 checksum How to use checksums |
38ea8fcc5fb25ff4b261594c848e1129e232f0d850cfb42593c7dccac1a9b496
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.20
|
Security for arduino-iot-client 3.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.