Skip to content

Commit a65a953

Browse files
authored
Merge branch 'development' into dependabot/pip/development/virtualenv-20.24.1
2 parents 3d5d35f + 0150f19 commit a65a953

23 files changed

+330
-336
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.3.1
2+
current_version = 0.3.4
33
commit = False
44
tag = False
55

.github/workflows/bump-version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
access_token: ${{ github.token }}
2323

2424

25-
- uses: actions/checkout@v3
25+
- uses: actions/checkout@v4
2626
with:
2727
token: ${{ secrets.EMNIFY_GITHUB_ACTIONS_TOKEN }}
2828

.github/workflows/documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
with:
1818
access_token: ${{ github.token }}
1919

20-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2121

2222
- name: Prepare doc-gen
2323
run: docker build . -f docs/Dockerfile.dev -t emnify/python-sdk-docs

.github/workflows/gitleaks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: checkout
12-
uses: actions/checkout@v3
12+
uses: actions/checkout@v4
1313
- name: gitleaks
1414
uses: zricethezav/[email protected]
1515
with:

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: styfle/[email protected]
1919
with:
2020
access_token: ${{ github.token }}
21-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@v4
2222

2323
- name: Install dependencies
2424
run: pip install -r req.txt

DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ To set up your sandbox, modify the code in this file as needed.
2424
2525
Once your sandbox is set up, you can launch the file and view the results.
2626
```shell
27-
docker run -t -e EMNIFY_APPLICATION_TOKEN=<your_token_here> -v $(pwd):/sdk emnify/python-sdk python docs/examples/local_debug.py
27+
docker run -t -e EMNIFY_SDK_APPLICATION_TOKEN=<your_token_here> -e EMINFY_SDK_API_ENDPOINT_URL=<your_debug_API_endpoint> -v $(pwd):/sdk emnify/python-sdk python docs/examples/local_debug.py
2828
```
2929

3030
## Version Bump

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ distlib = "==0.3.6"
1010
filelock = "==3.12.2"
1111
idna = "==3.4"
1212
importlib-metadata = "==6.7.0"
13-
pipenv = "==2023.6.18"
13+
pipenv = "==2023.7.23"
1414
platformdirs = "==3.5.1"
1515
pydantic = "==1.10.9"
1616
requests = "==2.31.0"
Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1+
# === Example: Initialize the SDK client ===
2+
13
from emnify import EMnify
24
from emnify import constants as emnify_constants
35

4-
emnify = EMnify(app_token='your token')
6+
# To operate the emnify SDK, you need to generate an application token.
7+
# Step-by-step guide: https://www.emnify.com/developer-blog/how-to-use-an-application-token-for-api-authentication
8+
emnify = EMnify(app_token='YOUR_TOKEN')
9+
510
# [endblock]
6-
# === Create and activate a device ===
711

12+
# === Example: Create and activate a device ===
813

914
unassigned_sims = [i for i in emnify.sim.get_sim_list(without_device=True)]
10-
# If no unassigned_sims - register new one by batch code
15+
# If there aren't any unassigned SIMs, register a new one via batch code:
1116
if not unassigned_sims:
12-
registered_sim = emnify.sim.register_sim(bic='sample_bic_code') # Returns as list
17+
registered_sim = emnify.sim.register_sim(bic='EXAMPLE_BIC_CODE') # Returns a list
1318
sim = emnify.sim.retrieve_sim(registered_sim[0].id)
1419
else:
15-
sim = unassigned_sims[0] # Taking the first one unassigned sim
20+
sim = unassigned_sims[0] # Takes the first unassigned SIM
1621

17-
# Defining of new device parameters
18-
# All required models can be retrieved through manager`s properties
22+
# To create your new device, you need to define the parameters.
23+
# You can retrieve all required models through the manager properties.
24+
# API reference: https://emnify.github.io/emnify-sdk-python/autoapi/emnify/modules/device/manager/index.html
1925
service_profile = emnify.devices.service_profile_model(id=1)
2026
tariff_profile = emnify.devices.tariff_profile_model(id=1)
2127
device_status = emnify.devices.status_model(id=0)
@@ -28,50 +34,51 @@
2834
name=name
2935
)
3036

31-
# After creating model sdk returns id of device
37+
# After creating a model, the SDK returns the device ID.
3238
device_id = emnify.devices.create_device(device=device_model)
33-
# Then we can retrieve all device details
39+
# Then, you can retrieve the device details
3440
device = emnify.devices.retrieve_device(device_id=device_id)
35-
# Activate device
41+
# and finally, activate the device:
3642
emnify.devices.change_status(device=device, enable=True)
3743

38-
# Retrieving updated device details
44+
# Retrieve updated device details
3945
device = emnify.devices.retrieve_device(device_id=device_id)
40-
device_status = device.status.description # Will be 'Enabled'
41-
sim_status = device.sim.status.description # Will be 'Activated'
46+
device_status = device.status.description # Device status is "Enabled"
47+
sim_status = device.sim.status.description # SIM status is "Activated"
48+
4249
# [endblock]
4350

44-
# === Configure a device ===
51+
# === Example: Configure a device ===
4552

46-
# Getting details of device
53+
# Get device details
4754
device = emnify.devices.retrieve_device(device_id=device_id)
4855

49-
tags = 'arduino, meter, temp' # Sample tags
50-
name = 'new name' # Sample name
56+
tags = 'arduino, meter, temp' # Example tags
57+
name = 'new name' # Example name
5158

52-
# Adjust device config
59+
# Adjust the device configuration
5360
update_device_fields = emnify.devices.device_update_model(name='new name', tags='arduino')
5461
emnify.devices.update_device(device_id=device.id, device=update_device_fields)
5562

56-
# Getting details of updated device
63+
# Get updated device details
5764
updated_device = emnify.devices.retrieve_device(device_id=device_id)
58-
device_tags = updated_device.tags # Will be arduino
59-
deivce_name = updated_device.name # Will be 'new name'
65+
device_tags = updated_device.tags # Updated tag is "arduino"
66+
deivce_name = updated_device.name # Updated name is "new name"
6067
# [endblock]
6168

62-
# === Configure operator blacklist for device ===
69+
# === Example: Configure operator blacklist for a device ===
6370

64-
# List of all operators
71+
# Retrieve a list of all operators
6572
all_operators = [i for i in emnify.operator.get_operators()]
6673

67-
device_id = 0 # Your device id
74+
# Add three operators to the blacklist:
75+
device_id = 0 # Your device ID
6876
emnify.devices.add_device_blacklist_operator(operator_id=all_operators[0].id, device_id=device_id)
6977
emnify.devices.add_device_blacklist_operator(operator_id=all_operators[1].id, device_id=device_id)
7078
emnify.devices.add_device_blacklist_operator(operator_id=all_operators[2].id, device_id=device_id)
71-
# Adding 3 operators to the blacklist
7279

80+
# Get all blacklist operators of the device by device ID:
7381
device_blacklist = emnify.devices.get_device_operator_blacklist(device_id=device_id)
74-
# Getting all blacklist operators of device by device_id
7582

7683
operator_id = 0
7784
for operator in device_blacklist:
@@ -80,78 +87,76 @@
8087
print(operator.mnc)
8188
operator_id = operator.id
8289

90+
# Removes the last operator from the blacklist
8391
emnify.devices.delete_device_blacklist_operator(device_id=device_id, operator_id=operator_id)
84-
# Removing the last operator from blacklist
92+
8593
# [endblock]
8694

87-
# === Disable device ===
95+
# === Example: Disable a device ===
8896

97+
# Get a list of all devices with SIM cards and the "Enabled" device status
8998
device_filter = emnify.devices.get_device_filter_model(status=emnify_constants.DeviceStatuses.ENABLED_ID.value)
9099
all_devices_with_sim = [
91100
device for device in emnify.devices.get_devices_list(filter_model=device_filter) if device.sim
92101
]
93-
# Getting list of all devices with sim cards and enabled status
94102

95103
device = all_devices_with_sim[0]
96104

97-
emnify.devices.change_status(disable=True, device=device.id)
98105
# Disable a device
106+
emnify.devices.change_status(disable=True, device=device.id)
99107

100108
disabled_device = emnify.devices.retrieve_device(device_id=device.id)
101-
device_status = disabled_device.status.description # Will be 'Disabled'
102-
sim_status = disabled_device.sim.status.description # Will be 'Suspended'
109+
device_status = disabled_device.status.description # Device status is "Disabled"
110+
sim_status = disabled_device.sim.status.description # SIM status is "Suspended"
111+
103112
# [endblock]
104113

105-
# === Delete device ===
114+
# === Example: Delete a device ===
106115

116+
# Get a list of all devices
107117
old_devices_list = [device for device in emnify.devices.get_devices_list()]
108-
# Getting list of all devices
109118

110119
device_to_delete = list(
111120
filter(
112121
lambda device: device.sim and device.status.id == emnify_constants.DeviceStatuses.ENABLED_ID,
113122
old_devices_list
114123
)
115124
)[0]
116-
# Picking up a device to delete with assigned sim and enabled status
117125

126+
# Choose a device to delete with an assigned SIM and the "Enabled" device status
118127
sim_id_of_deleted_device = device_to_delete.sim.id
119128

129+
# Delete the device
120130
emnify.devices.delete_device(device_id=device_to_delete.id)
121-
# Deleting a device
122131

132+
# Retrieve a new list of all devices
123133
new_device_list = [device for device in emnify.devices.get_devices_list()]
124-
# Getting new list of all devices
125-
126134

135+
# Once your device is deleted, the total device count should be lower:
127136
assert len(old_devices_list) > len(new_device_list)
128-
# After deleting count of all devices will be lowered
129137

130138
sim = emnify.sim.retrieve_sim(sim_id=sim_id_of_deleted_device)
131-
sim_status = sim.status.description # Will be 'Suspended'
139+
sim_status = sim.status.description # SIM status is 'Suspended'
132140

133141
# [endblock]
134142

143+
# === Example: Manage device connectivity ===
135144

136-
# === Manage device connectivity ===
137-
138-
# Lookup for documentation for learn more
139-
# https://www.emnify.com/developer-blog/5-ways-to-detect-and-solve-connectivity-issues#network-events
140-
141-
# There are many reasons why connection issues arise. For example:
142-
# * The device executes the wrong procedures due to a bad firmware update.
143-
# * The device executes network registration too frequently that the network no longer allows it to register.
144-
# * You have simply changed a policy due to a blocked device.
145+
# There are many reasons why connection issues arise.
146+
# For example:
147+
# - The device executes the wrong procedures due to a bad firmware update.
148+
# - The device executes network registration too frequently, so the network no longer allows it to register.
149+
# - You changed a policy due to a blocked device.
145150

146-
# For resetting a device connectivity you can use the following methods:
147-
# * Resetting the connectivity of device
151+
# To reset device connectivity, use the following methods:
152+
# - Reset the device's connectivity
148153
device_id = 0
149154
emnify.devices.reset_connectivity_data(device_id=device_id)
150-
# * Resetting the connectivity
155+
# - Reset the network connectivity
151156
emnify.devices.reset_connectivity_network(device_id=device_id)
152157

153-
# For checking connectivity you can use the method:
158+
# Use the following method to check the connectivity:
154159
connectivity = emnify.devices.get_device_connectivity_status(device_id=device_id)
155-
print(connectivity.status.description) # Will be 'ATTACHED'/'ONLINE'/'OFFLINE'/'BLOCKED'
160+
print(connectivity.status.description) # Status is either "Attached", "Online", "Offline", or "Blocked"
156161

157162
# [endblock]
Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,58 @@
11

2-
# === Using a Filtering for List calls ===
32
from emnify import EMnify
43
from emnify import constants as emnify_constants
54

6-
emnify_client = EMnify(app_token='your_application_token')
5+
# To operate the emnify SDK, you need to generate an application token.
6+
# Step-by-step guide: https://www.emnify.com/developer-blog/how-to-use-an-application-token-for-api-authentication
7+
emnify_client = EMnify(app_token='YOUR_TOKEN')
78

89
# Some methods that return multiple objects allow sorting and filtering.
9-
# This allows us to optimize processing time, since using filtering we can immediately get the necessary objects with
10-
# the necessary qualities, and sorting allows us to set the order in which objects are displayed.
11-
# Instead of sending several requests in search of the required object, we can reduce their number to one.
10+
# API reference: https://emnify.github.io/emnify-sdk-python/autoapi/index.html
1211

13-
# For example - we want to find all SIM`s with specific customer organisation, first one for instance.
14-
# We need to initiate the model for filtering by specifying the necessary parameters in it as arguments.
12+
# This optimizes processing time because:
13+
# - Filtering lets you only retrieve the objects you need.
14+
# - Sorting allows you to set the order that objects are displayed.
15+
# Instead of sending several requests to get the required object, you only need one.
16+
17+
# === Example: Filter a list of SIM cards ===
18+
19+
# This example finds all SIMs for a specific customer organization.
20+
# Start by initiating the model for filtering by specifying the necessary parameters as arguments.
1521
sim_filter = emnify_client.sim.get_sim_filter_model(customer_org=1)
16-
# To get the filtering model for filling, you need to get it as a property of a manager
17-
# for SIM cards, this would be get_sim_filter_model, for Devices it would be a get_device_filter_model
1822

19-
# After initializing the model object, it must be passed as an argument that makes a request to get a list of objects.
23+
# Next, you need to get the filtering model for filling as a property of a manager.
24+
# For SIM cards: get_sim_filter_model
25+
# For devices: get_device_filter_model
26+
27+
# After initializing the model object, pass it as an argument to request a list of objects.
2028
sims = emnify_client.sim.get_sim_list(filter_model=sim_filter)
21-
# sims now contains the objects we need with client organization 1
29+
# Now, sims contains the objects for customer organization 1.
2230

23-
# We can pass several parameters for filtering for a more detailed search for the necessary objects.
31+
# For a more detailed search, pass several parameters for filtering:
2432
sim_filter = emnify_client.sim.get_sim_filter_model(
2533
customer_org=1,
2634
status=emnify_constants.SimStatusesID.ACTIVATED_ID.value,
2735
production_date='2019-01-25'
2836
)
2937

30-
# The request to get a list of SIM cards also has a separate filter,
31-
# which is passed as an argument to the filtering function - without a device.
32-
38+
# The list SIM cards request also has a separate filter, passed as an argument.
39+
# The following example searches for SIMs without a device:
3340
sims_without_assigned_device = emnify_client.sim.get_sim_list(without_device=True)
3441

42+
# === Example: Sort all devices ===
3543

36-
# === Using a Sorting for List calls ===
37-
# Just like filtering, sorting allows us to reduce processing time by ordering objects in the server.
38-
# Thus, it is easier for you to group objects according to a certain attribute by specifying it in sorting.
44+
# Like filtering, sorting reduces processing time by ordering objects in the server.
45+
# Sorting also enables you to group objects by specifying a particular attribute.
3946

40-
# For example - we want to get all devices sorted by last updated date
41-
# All sorting is done by using enums
47+
# The following example sorts all devices by the last updated date.
48+
# Note: All sorting uses enums.
4249
sort_parameter = emnify_client.devices.get_device_sort_enum.LAST_UPDATED.value
4350

44-
# After choosing a parameter for filtering, we need to pass it as an argument sort_enum
51+
# After choosing a filtering parameter, pass it as an argument to sort_enum:
4552
sorted_devices = emnify_client.devices.get_devices_list(
4653
sort_enum=sort_parameter
4754
)
4855

49-
# Now we got a list of devices, at the beginning of which are the recently updated devices
56+
# Now, you have a list of devices with the most recently updated at the top.
5057
for latest_device in sorted_devices:
5158
...

docs/examples/local_debug.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,38 @@
1010
from emnify import EMnify
1111

1212
# Get the token from environment variable
13-
TOKEN = os.environ.get('EMNIFY_APPLICATION_TOKEN')
13+
TOKEN = os.environ.get('EMNIFY_SDK_APPLICATION_TOKEN')
1414

1515
# Initiate SDK instance using application token
1616
emnify = EMnify(TOKEN)
1717

18+
def get_iterator_length(iterator):
19+
return len(list(iterator))
20+
1821
# Execute a command against desired API
1922
devices = emnify.devices.get_devices_list()
23+
#
24+
#
25+
## print first 100 devices
26+
for i, device in enumerate(devices):
27+
if i >= 100:
28+
break
29+
print(device)
30+
31+
# Count remaining devices
32+
print(get_iterator_length(devices))
33+
34+
35+
# Get list of sims
36+
sims = emnify.sim.get_sim_list()
37+
38+
# Count sims
39+
print(get_iterator_length(sims))
40+
41+
sms_list = emnify.devices.get_device_sms_list(device=11379224)
42+
print(list(sms_list))
43+
print(sms_list)
2044

21-
# Showing all the devices
22-
print([device for device in devices])
45+
# Get list of events
46+
events = emnify.devices.get_device_events_list(device=11379224)
47+
print(list(events))

0 commit comments

Comments
 (0)