Skip to main content

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

Project description

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

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

awsiotclient-0.2.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

awsiotclient-0.2.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file awsiotclient-0.2.0.tar.gz.

File metadata

  • Download URL: awsiotclient-0.2.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.10 Linux/5.15.0-76-generic

File hashes

Hashes for awsiotclient-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8e09ae33397aeab76aa76d499bc529f5c2f1db4918458b6fca6babe9ca9f50e1
MD5 a5a871116a0a8695545a829f2286c3ad
BLAKE2b-256 b44a83aadc7c742195ca0348eeb96843f1e18c4266a0719f778abb5c76db1645

See more details on using hashes here.

File details

Details for the file awsiotclient-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: awsiotclient-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.10 Linux/5.15.0-76-generic

File hashes

Hashes for awsiotclient-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85b2562c8b2ee76a78858fe366e918e21810d18c80d1994a8330e54691ce4193
MD5 79fe4896b6fa4495be10f57133adb96c
BLAKE2b-256 e4eb251307dcef2085287f887b377792c1dada671b9e0c28e87627bb646d088b

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