Skip to main content

aws-iot-device-client-python

The AWS IoT Device Client provides device-side functionality for AWS IoT services such as jobs, device shadow, and simple pubsub.

Installation

Minimum Requirements

  • Python 3.7.1+

Install from PyPI

python3 -m pip install awsiotclient

Install from source

git clone https://github.com/whill-labs/aws-iot-device-client-python
python3 -m pip install ./aws-iot-device-client-python

Usage

Create MQTT connection

from awsiotclient import mqtt

# Construct connection parameters
conn_params = mqtt.ConnectionParams()

# Required params
conn_params.endpoint = <your_endpoint_url>
conn_params.cert = <path_to_your_certificate>
conn_params.key = <path_to_your_private_key>
conn_params.root_ca = <path_to_your_root_ca>

# Optional params
conn_params.client_id = <client_id> # default "mqtt-" + uuid4()
conn_params.signing_region = <signing_region> # default "ap-northeast-1" (Tokyo Region)
conn_params.use_websocket = <True/False> # default False

# Initialize connection
mqtt_connection = mqtt.init(conn_params)
connect_future = mqtt_connection.connect()
connect_future.result()

Use AWS IoT named shadow

Note that usage of classic shadow client is similar to named shadow client.

without delta (one-way communication from device to cloud)

from awsiotclient import mqtt, named_shadow

# <create mqtt connection here as described above>
my_client = named_shadow.client(
    mqtt_connection,
    thing_name="my_thing",
    shadow_name="my_shadow"
)

my_value = dict(foo="var")
my_clinet.change_reported_value(my_value)

with delta (two-way communication from/to device and cloud)

from awsiotclient import mqtt, named_shadow

def my_delta_func(thing_name: str, shadow_name: str, value: Dict[str, Any]) -> None:
    print("my_client invokes this callback when it receives delta message")
    print(f"thing_name: {thing_name}, shadow_name: {shadow_name}, value: {value}")

# <create mqtt connection here as described above>
my_client = named_shadow.client(
    mqtt_connection,
    thing_name="my_thing",
    shadow_name="my_shadow",
    delta_func=my_delta_func,
)

my_value = dict(foo="var")
my_client.change_reported_value(my_value)
# <wait until the client receives delta>

Use AWS IoT jobs

from awsiotclient import mqtt, named_shadow

def job_runner(id: str, document: dict):
    print("my_client invokes this callback when it receives job document")
    print(f"job id: {id}, document: {document}")

# <create mqtt connection here as described above
job_client = jobs.client(
    mqtt_connection,
    thing_name="my_thing",
    job_func=job_runner
)
# <wait until the client receives job>

License

This library is licensed under the Apache 2.0 License.

Acknowledgments

Metadata

Release files for awsiotclient 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for awsiotclient 0.2.2
File Size Uploaded Provenance
awsiotclient-0.2.2.tar.gz 13.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for awsiotclient 0.2.2
File Interpreter ABI Platform
awsiotclient-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 30.1 kB

Release files / awsiotclient-0.2.2.tar.gz

Download URL awsiotclient-0.2.2.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
473d9ac1b78aa193eca5623139d34f2af1d85a653ded8d260bbf5ca42f5ab178
BLAKE2b-256 checksum
How to use checksums
b72f9bdb3d8b7fd1a7525a4f82c275a7da6ce22932ad445deb6f86f44575bc11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.12.3 Linux/6.17.0-14-generic

Release files / awsiotclient-0.2.2-py3-none-any.whl

Download URL awsiotclient-0.2.2-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
112341880ee00c16f58483e7f61966773ed4e99258fb3fd7bcccf5bab4ddc63f
BLAKE2b-256 checksum
How to use checksums
8614194775c152c2c5833979a7f9a24e284c11a7cc13ed0be4898e9c8942739a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.12.3 Linux/6.17.0-14-generic

Security for awsiotclient 0.2.2

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page