Skip to content

Commit 4c66229

Browse files
authored
Remove support for python 2 (#105)
Python 2's end-of-life date was Jan 1 2020.
1 parent 88908b5 commit 4c66229

File tree

15 files changed

+42
-70
lines changed

15 files changed

+42
-70
lines changed

NOTICE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
AWS IoT SDK for Python v2
2-
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
AWS IoT Device SDK v2 for Python
2+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
SPDX-License-Identifier: Apache-2.0.

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# AWS IoT Device SDK for Python v2
2-
This document provides information about the AWS IoT device SDK for Python V2.
1+
# AWS IoT Device SDK v2 for Python
2+
This document provides information about the AWS IoT Device SDK v2 for Python.
33

44
If you have any issues or feature requests, please file an issue or pull request.
55

@@ -35,26 +35,25 @@ to Python by the `awscrt` package ([PyPI](https://pypi.org/project/awscrt/)) ([G
3535

3636
### Install from PyPI
3737
```
38-
pip install awsiotsdk
38+
python3 -m pip install awsiotsdk
3939
```
4040

4141
### Install from source
4242
```
43-
pip install ./aws-iot-device-sdk-python-v2
43+
git clone https://github.com/aws/aws-iot-device-sdk-python-v2.git
44+
python3 -m pip install ./aws-iot-device-sdk-python-v2
4445
```
4546

4647
### Installation Issues
4748

48-
`awsiotsdk` depends on [awscrt](https://github.com/awslabs/aws-crt-python), which makes use of C extensions. Precompiled wheels are downloaded when installing on major platforms (Mac, Windows, Linux, Raspbian (python3 only)). If wheels are unavailable for your platform (ex: Raspbian with python2.7), your machine must compile some C libraries. If you encounter issues, install the following and try again:
49+
`awsiotsdk` depends on [awscrt](https://github.com/awslabs/aws-crt-python), which makes use of C extensions. Precompiled wheels are downloaded when installing on major platforms (Mac, Windows, Linux, Raspbian. If wheels are unavailable for your platform, your machine must compile some C libraries. If you encounter issues, install the following and try again:
4950

5051
```
5152
sudo apt-get update
5253
sudo apt-get install cmake
5354
sudo apt-get install libssl-dev
5455
```
5556

56-
57-
5857
## Mac-Only TLS Behavior
5958

6059
Please note that on Mac, once a private key is used with a certificate, that certificate-key pair is imported into the Mac Keychain. All subsequent uses of that certificate will use the stored private key and ignore anything passed in programmatically. Beginning in v1.3.2, when a stored private key from the Keychain is used, the following will be logged at the "info" log level:

awsiot/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
PayloadObj = Dict[str, Any]
2020
PayloadToClassFn = Callable[[PayloadObj], T]
2121

22-
class MqttServiceClient(object):
22+
class MqttServiceClient:
2323
"""
2424
Base class for an AWS MQTT Service Client
2525
"""
@@ -153,7 +153,7 @@ def callback_wrapper(topic, payload, **kwargs):
153153

154154
return future, topic
155155

156-
class ModeledClass(object):
156+
class ModeledClass:
157157
"""
158158
Base for input/output classes generated from an AWS service model.
159159
"""

awsiot/greengrass_discovery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from concurrent.futures import Future
88
import json
99

10-
class DiscoveryClient(object):
10+
class DiscoveryClient:
1111
__slots__ = ['_bootstrap', '_tls_context', '_socket_options', '_region', '_tls_connection_options', '_gg_server_name', 'gg_url', 'port']
1212

1313
def __init__(self, bootstrap, socket_options, tls_context, region):
@@ -63,7 +63,7 @@ def on_connection_completed(conn_future):
6363
http_stream = connection.request(
6464
request=request,
6565
on_body=on_incoming_body)
66-
66+
6767
http_stream.activate()
6868
http_stream.completion_future.add_done_callback(on_request_complete)
6969

builder.json

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
},
2424
"manylinux": {
2525
"post_build_steps": [
26+
["echo", "------ Python 3.7 ------"],
27+
["/opt/python/cp37-cp37m/bin/python", "-m", "pip", "install", "--upgrade", "pip", "setuptools"],
28+
["/opt/python/cp37-cp37m/bin/python", "-m", "pip", "install", ".", "--verbose"],
29+
["/opt/python/cp37-cp37m/bin/python", "-m", "pip", "install", "boto3", "autopep8"],
30+
["/opt/python/cp37-cp37m/bin/python", "-m", "unittest", "discover", "--verbose"],
2631
["echo", "------ Python 3.6 ------"],
2732
["/opt/python/cp36-cp36m/bin/python", "-m", "pip", "install", "--upgrade", "pip", "setuptools"],
2833
["/opt/python/cp36-cp36m/bin/python", "-m", "pip", "install", ".", "--verbose"],
@@ -32,22 +37,7 @@
3237
["/opt/python/cp35-cp35m/bin/python", "-m", "pip", "install", "--upgrade", "pip", "setuptools"],
3338
["/opt/python/cp35-cp35m/bin/python", "-m", "pip", "install", ".", "--verbose"],
3439
["/opt/python/cp35-cp35m/bin/python", "-m", "pip", "install", "boto3", "autopep8"],
35-
["/opt/python/cp35-cp35m/bin/python", "-m", "unittest", "discover", "--verbose"],
36-
["echo", "------ Python 3.4 ------"],
37-
["/opt/python/cp34-cp34m/bin/python", "-m", "pip", "install", "--upgrade", "pip", "setuptools"],
38-
["/opt/python/cp34-cp34m/bin/python", "-m", "pip", "install", ".", "--verbose"],
39-
["/opt/python/cp34-cp34m/bin/python", "-m", "pip", "install", "boto3", "autopep8"],
40-
["/opt/python/cp34-cp34m/bin/python", "-m", "unittest", "discover", "--verbose"],
41-
["echo", "------ Python 2.7 narrow-unicode ------"],
42-
["/opt/python/cp27-cp27m/bin/python", "-m", "pip", "install", "--upgrade", "pip", "setuptools"],
43-
["/opt/python/cp27-cp27m/bin/python", "-m", "pip", "install", ".", "--verbose"],
44-
["/opt/python/cp27-cp27m/bin/python", "-m", "pip", "install", "boto3", "autopep8"],
45-
["/opt/python/cp27-cp27m/bin/python", "-m", "unittest", "discover", "--verbose"],
46-
["echo", "------ Python 2.7 wide-unicode ------"],
47-
["/opt/python/cp27-cp27mu/bin/python", "-m", "pip", "install", "--upgrade", "pip", "setuptools"],
48-
["/opt/python/cp27-cp27mu/bin/python", "-m", "pip", "install", ".", "--verbose"],
49-
["/opt/python/cp27-cp27mu/bin/python", "-m", "pip", "install", "boto3", "autopep8"],
50-
["/opt/python/cp27-cp27mu/bin/python", "-m", "unittest", "discover", "--verbose"]
40+
["/opt/python/cp35-cp35m/bin/python", "-m", "unittest", "discover", "--verbose"]
5141
],
5242
"run_tests": false,
5343
"_comment": "manylinux has all its own build steps, turn off 'tests' which is where normal build steps are declared. using data to program sucks"

docsrc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
# -- Project information -----------------------------------------------------
2121

22-
project = 'AWS IoT Device SDK Python v2'
22+
project = 'AWS IoT Device SDK v2 for Python'
2323
copyright = '%s, Amazon Web Services, Inc' % datetime.now().year
2424
author = 'Amazon Web Services, Inc'
2525

docsrc/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
.. AWS IoT Device SDK Python v2 documentation master file, created by
1+
.. AWS IoT Device SDK v2 for Python documentation master file, created by
22
sphinx-quickstart on Mon Aug 17 14:57:36 2020.
33
You can adapt this file completely to your liking, but it should at least
44
contain the root `toctree` directive.
55
6-
AWS IoT Device SDK Python v2
7-
============================
6+
AWS IoT Device SDK v2 for Python
7+
================================
88

99
Python bindings for the AWS IoT Device API.
1010

@@ -18,7 +18,7 @@ API Reference
1818
-------------
1919
.. toctree::
2020
:maxdepth: 2
21-
21+
2222
awsiot/greengrass_discovery
2323
awsiot/iotidentity
2424
awsiot/iotjobs

samples/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Sample apps for the AWS IoT Device SDK for Python v2
1+
# Sample apps for the AWS IoT Device SDK v2 for Python
22

33
* [pubsub](#pubsub)
44
* [shadow](#shadow)
@@ -19,7 +19,7 @@ Source: `samples/pubsub.py`
1919

2020
Run the sample like this:
2121
```
22-
python pubsub.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file>
22+
python3 pubsub.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file>
2323
```
2424

2525
Your Thing's
@@ -90,7 +90,7 @@ Source: `samples/shadow.py`
9090

9191
Run the sample like this:
9292
```
93-
python shadow.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --thing-name <name>
93+
python3 shadow.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --thing-name <name>
9494
```
9595

9696
Your Thing's
@@ -176,7 +176,7 @@ Source: `samples/jobs.py`
176176

177177
Run the sample like this:
178178
```
179-
python jobs.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --thing-name <name>
179+
python3 jobs.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --thing-name <name>
180180
```
181181

182182
Your Thing's
@@ -248,12 +248,12 @@ Source: `samples/fleetprovisioning.py`
248248

249249
Run the sample using createKeysAndCertificate:
250250
```
251-
python fleetprovisioning.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --templateName <name> --templateParameters <parameters>
251+
python3 fleetprovisioning.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --templateName <name> --templateParameters <parameters>
252252
```
253253

254254
Run the sample using createCertificateFromCsr:
255255
```
256-
python fleetprovisioning.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --templateName <name> --templateParameters <parameters> --csr <csr file>
256+
python3 fleetprovisioning.py --endpoint <endpoint> --root-ca <file> --cert <file> --key <file> --templateName <name> --templateParameters <parameters> --csr <csr file>
257257
```
258258

259259
Your Thing's
@@ -353,15 +353,15 @@ you'll need to substitute the name of the template you previously created, and o
353353

354354
(Optional) Create a temporary provisioning claim certificate set:
355355
<pre>
356-
aws iot create-provisioning-claim --template-name [TemplateName] | python ../utils/parse_cert_set_result.py --path /tmp --filename provision
356+
aws iot create-provisioning-claim --template-name [TemplateName] | python3 ../utils/parse_cert_set_result.py --path /tmp --filename provision
357357
</pre>
358358

359359
The provisioning claim's cert and key set have been written to `/tmp/provision*`. Now you can use these temporary keys
360360
to perform the actual provisioning. If you are not using the temporary provisioning certificate, replace the paths for `--cert`
361361
and `--key` appropriately:
362362

363363
<pre>
364-
python fleetprovisioning.py --endpoint [your endpoint]-ats.iot.[region].amazonaws.com --root-ca [pathToRootCA] --cert /tmp/provision.cert.pem --key /tmp/provision.private.key --templateName [TemplateName]--templateParameters "{\"SerialNumber\":\"1\",\"DeviceLocation\":\"Seattle\"}"
364+
python3 fleetprovisioning.py --endpoint [your endpoint]-ats.iot.[region].amazonaws.com --root-ca [pathToRootCA] --cert /tmp/provision.cert.pem --key /tmp/provision.private.key --templateName [TemplateName]--templateParameters "{\"SerialNumber\":\"1\",\"DeviceLocation\":\"Seattle\"}"
365365
</pre>
366366

367367
Notice that we provided substitution values for the two parameters in the template body, `DeviceLocation` and `SerialNumber`.
@@ -383,13 +383,13 @@ openssl req -new -key /tmp/deviceCert.key -out /tmp/deviceCert.csr
383383
be skipped if you're using a certificate set capable of provisioning the device:
384384

385385
<pre>
386-
aws iot create-provisioning-claim --template-name [TemplateName] | python ../utils/parse_cert_set_result.py --path /tmp --filename provision
386+
aws iot create-provisioning-claim --template-name [TemplateName] | python3 ../utils/parse_cert_set_result.py --path /tmp --filename provision
387387
</pre>
388388

389389
Finally, supply the certificate signing request while invoking the provisioning sample. As with the previous workflow, if
390390
using a permanent certificate set, replace the paths specified in the `--cert` and `--key` arguments:
391391
<pre>
392-
python fleetprovisioning.py --endpoint [your endpoint]-ats.iot.[region].amazonaws.com --root-ca [pathToRootCA] --cert /tmp/provision.cert.pem --key /tmp/provision.private.key --templateName [TemplateName]--templateParameters "{\"SerialNumber\":\"1\",\"DeviceLocation\":\"Seattle\"}" --csr /tmp/deviceCert.csr
392+
python3 fleetprovisioning.py --endpoint [your endpoint]-ats.iot.[region].amazonaws.com --root-ca [pathToRootCA] --cert /tmp/provision.cert.pem --key /tmp/provision.private.key --templateName [TemplateName]--templateParameters "{\"SerialNumber\":\"1\",\"DeviceLocation\":\"Seattle\"}" --csr /tmp/deviceCert.csr
393393
</pre>
394394

395395
## basic discovery

samples/fleetprovisioning.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0.
33

4-
from __future__ import absolute_import
5-
from __future__ import print_function
64
import argparse
75
from awscrt import auth, http, io, mqtt
86
from awsiot import iotidentity
@@ -63,7 +61,7 @@
6361
createCertificateFromCsrResponse = None
6462
registerThingResponse = None
6563

66-
class LockedData(object):
64+
class LockedData:
6765
def __init__(self):
6866
self.lock = threading.Lock()
6967
self.disconnect_called = False

samples/jobs.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0.
33

4-
from __future__ import absolute_import
5-
from __future__ import print_function
64
import argparse
75
from awscrt import auth, http, io, mqtt
86
from awsiot import iotjobs
@@ -64,7 +62,7 @@
6462
jobs_client = None
6563
thing_name = ""
6664

67-
class LockedData(object):
65+
class LockedData:
6866
def __init__(self):
6967
self.lock = threading.Lock()
7068
self.disconnect_called = False

samples/pubsub.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0.
33

4-
from __future__ import absolute_import
5-
from __future__ import print_function
64
import argparse
75
from awscrt import io, mqtt, auth, http
86
from awsiot import mqtt_connection_builder

samples/shadow.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0.
33

4-
from __future__ import absolute_import
5-
from __future__ import print_function
64
import argparse
75
from awscrt import auth, io, mqtt, http
86
from awsiot import iotshadow
@@ -64,7 +62,7 @@
6462

6563
SHADOW_VALUE_DEFAULT = "off"
6664

67-
class LockedData(object):
65+
class LockedData:
6866
def __init__(self):
6967
self.lock = threading.Lock()
7068
self.shadow_value = None
@@ -207,10 +205,7 @@ def user_input_thread_fn():
207205
while True:
208206
try:
209207
# Read user input
210-
try:
211-
new_value = raw_input() # python 2 only
212-
except NameError:
213-
new_value = input() # python 3 only
208+
new_value = input()
214209

215210
# If user wants to quit sample, then quit.
216211
# Otherwise change the shadow value.

setup.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
description='AWS IoT SDK based on the AWS Common Runtime',
1212
author='AWS SDK Common Runtime Team',
1313
url='https://github.com/aws/aws-iot-device-sdk-python-v2',
14-
packages = ['awsiot'],
14+
packages=['awsiot'],
1515
install_requires=[
16-
'awscrt==0.8.0',
17-
'futures;python_version<"3.2"',
18-
'typing;python_version<"3.5"',
16+
'awscrt==0.9.0',
1917
],
20-
python_requires='>=2.7',
18+
python_requires='>=3.5',
2119
)

test/test_samples.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0.
3-
from __future__ import absolute_import, print_function
43
import awsiot
54
import boto3
65
import botocore.exceptions
@@ -43,10 +42,7 @@ def get():
4342

4443
# boto3 caches the HTTPS connection for the API calls, which appears to the unit test
4544
# framework as a leak, so ignore it, that's not what we're testing here
46-
try:
47-
warnings.simplefilter('ignore', ResourceWarning)
48-
except NameError: # Python 2 has no ResourceWarning
49-
pass
45+
warnings.simplefilter('ignore', ResourceWarning)
5046

5147
try:
5248
secrets = boto3.client('secretsmanager')

utils/parse_cert_set_result.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
Example usage:
1212
13-
aws iot create-provisioning-claim --template-name <TemplateName> | python parse_cert_set_result.py --path <PathToOutputtedCerts> --filename <Filename>
13+
aws iot create-provisioning-claim --template-name <TemplateName> | python3 parse_cert_set_result.py --path <PathToOutputtedCerts> --filename <Filename>
1414
1515
"""
1616

0 commit comments

Comments
 (0)