arduino-iot-client


Namearduino-iot-client JSON
Version 2.0.1 PyPI version JSON
download
home_page
SummaryIot API
upload_time2024-01-31 14:33:20
maintainer
docs_urlNone
author
requires_python
license
keywords openapi openapi-generator iot api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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`):

```sh
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:

```sh
pip install requests-oauthlib
```

After installing the library you can use this Python code to get a token:

```python
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:

```python
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](https://github.com/arduino/iot-client-py/tree/master/example/main.py) 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](https://create.arduino.cc/iot/things):

### Step 1

![IoT Cloud Site](https://github.com/arduino/iot-client-js/blob/master/img/selection_1.png?raw=true)

### Step 2

![IoT Cloud Site](https://github.com/arduino/iot-client-js/blob/master/img/selection_2.png?raw=true)

### Step 3

![IoT Cloud Site](https://github.com/arduino/iot-client-js/blob/master/img/selection_3.png?raw=true)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "arduino-iot-client",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "OpenAPI,OpenAPI-Generator,Iot API",
    "author": "",
    "author_email": "",
    "download_url": "",
    "platform": null,
    "description": "# Arduino iot-api Python client\n\n## Requirements\n\n* Python 3.7+\n\n## Installation\n\nYou can install the package directly from Github (you may need to run `pip` with\n`sudo`):\n\n```sh\npip install arduino-iot-client\n```\n\n## Getting Started\n\n### Authentication\n\nThe client requires a valid access token, you can use `requests-oauthlib` to get\none, to install the library do:\n\n```sh\npip install requests-oauthlib\n```\n\nAfter installing the library you can use this Python code to get a token:\n\n```python\nfrom oauthlib.oauth2 import BackendApplicationClient\nfrom requests_oauthlib import OAuth2Session\n\noauth_client = BackendApplicationClient(client_id=YOUR_CLIENT_ID)\ntoken_url = \"https://api2.arduino.cc/iot/v1/clients/token\"\n\noauth = OAuth2Session(client=oauth_client)\ntoken = oauth.fetch_token(\n    token_url=token_url,\n    client_id=YOUR_CLIENT_ID,\n    client_secret=YOUR_CLIENT_SECRET,\n    include_client_id=True,\n    audience=\"https://api2.arduino.cc/iot\",\n)\n\nprint(token.get(\"access_token\"))\n```\n\nOnce you get a token, you can create an instance of the iot-api client:\n\n```python\nimport iot_api_client as iot\nfrom iot_api_client.rest import ApiException\nfrom iot_api_client.configuration import Configuration\n\n# configure and instance the API client\nclient_config = Configuration(host=\"https://api2.arduino.cc/iot\")\nclient_config.access_token = YOUR_ACCESS_TOKEN\nclient = iot.ApiClient(client_config)\n\n# as an example, interact with the devices API\ndevices_api = iot.DevicesV2Api(client)\n\ntry:\n    resp = devices_api.devices_v2_list()\n    print(resp)\nexcept ApiException as e:\n    print(\"Got an exception: {}\".format(e))\n```\n\nFor a working example, see [the example folder](https://github.com/arduino/iot-client-py/tree/master/example/main.py) in this repo.\n\n## How to get Arduino IoT Cloud Client Credentials\n\nYou can generate Arduino IoT Cloud Client Credentials in the `ARDUINO API` section in the [IoT Cloud things section](https://create.arduino.cc/iot/things):\n\n### Step 1\n\n![IoT Cloud Site](https://github.com/arduino/iot-client-js/blob/master/img/selection_1.png?raw=true)\n\n### Step 2\n\n![IoT Cloud Site](https://github.com/arduino/iot-client-js/blob/master/img/selection_2.png?raw=true)\n\n### Step 3\n\n![IoT Cloud Site](https://github.com/arduino/iot-client-js/blob/master/img/selection_3.png?raw=true)\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Iot API",
    "version": "2.0.1",
    "project_urls": null,
    "split_keywords": [
        "openapi",
        "openapi-generator",
        "iot api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4192a9278bf233b19df44c60ecee34105fcc5e8f5fb172f025cb08fff98b2c79",
                "md5": "4a03a87d8e011e04362b0681955c34bd",
                "sha256": "6d1e869fa7526ce05112c0b46dbea37eeec3e45ec38304d0edbb5f54642ebbce"
            },
            "downloads": -1,
            "filename": "arduino_iot_client-2.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4a03a87d8e011e04362b0681955c34bd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 968758,
            "upload_time": "2024-01-31T14:33:20",
            "upload_time_iso_8601": "2024-01-31T14:33:20.415059Z",
            "url": "https://files.pythonhosted.org/packages/41/92/a9278bf233b19df44c60ecee34105fcc5e8f5fb172f025cb08fff98b2c79/arduino_iot_client-2.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-31 14:33:20",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "arduino-iot-client"
}
        
Elapsed time: 0.17468s