You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2. Alternatively, define your API key as a variable in your source code; this method is not recommended due to its inherent insecurity.
38
40
39
41
3. Single line of code to import and use the library goes at the top of your script:
40
42
41
-
`import meraki`
43
+
```python
44
+
import meraki
45
+
```
42
46
43
47
4. Instantiate the client (API consumer class), optionally specifying any of the parameters available to set:
44
48
45
-
`dashboard = meraki.DashboardAPI()`
49
+
```python
50
+
dashboard = meraki.DashboardAPI()
51
+
```
46
52
47
53
5. Make dashboard API calls in your source code, using the format _client.section.operation_, where _client_ is the name you defined in the previous step (**dashboard** above), _section_ is the corresponding group (or tag from the OpenAPI spec) from the [API docs](https://developer.cisco.com/meraki/api/#/rest), and _operation_ is the name (or operation ID from OpenAPI) of the API endpoint. For example, to make a call to get the list of organizations accessible by the API key defined in step 1, use this function call:
6. If you were using this module versions 0.34 and prior, that file's functions are included in the _legacy.py_ file, and you can adapt your existing scripts by replacing their `from meraki import meraki` line to `import meraki`
52
60
61
+
### Examples
62
+
You can find fully working example scripts in the **examples** folder.
53
63
54
-
For a full working script that demos this library, please see and run the **org_wide_clients.py** file included (in **examples** folder). That code collects the clients of all networks, in all orgs to which the key has access. No changes are made, since only GET endpoints are called, and the data is written to local CSV output files.
| **org_wide_clients.py** | That code collects the clients of all networks, in all orgs to which the key has access. No changes are made, since only GET endpoints are called, and the data is written to local CSV output files. |
67
+
68
+
## AsyncIO
69
+
**asyncio** is a library to write concurrent code using the **async/await** syntax. Special thanks to Heimo Stieg ([@coreGreenberet](https://github.com/coreGreenberet)) who has ported the API to asyncio.
70
+
71
+
The usage is similiar to the sequential version above. However it has has some differences.
72
+
73
+
1. Export your API key as an [environment variable](https://www.twilio.com/blog/2017/01/how-to-set-environment-variables.html), for example:
2. Alternatively, define your API key as a variable in your source code; this method is not recommended due to its inherent insecurity.
80
+
81
+
3. Single line of code to import and use the library goes at the top of your script:
82
+
83
+
```python
84
+
import meraki.aio
85
+
```
86
+
87
+
4. Instantiate the client (API consumer class), optionally specifying any of the parameters available to set:
88
+
89
+
```python
90
+
async with meraki.aio.AsyncDashboardAPI() as aiomeraki:
91
+
```
92
+
The **async with** statement is important here to make sure, that the client sessions will be closed after using the api.
93
+
94
+
5. Make dashboard API calls in your source code, using the format await _client.section.operation_, where _client_ is the name you defined in the previous step (**aiomeraki** above), _section_ is the corresponding group (or tag from the OpenAPI spec) from the [API docs](https://developer.cisco.com/meraki/api/#/rest), and _operation_ is the name (or operation ID from OpenAPI) of the API endpoint. For example, to make a call to get the list of organizations accessible by the API key defined in step 1, use this function call:
| **aio_org_wide_clients.py** | That code is a asyncio port from org_wide_clients.py and collects the clients of all networks, in all orgs to which the key has access. No changes are made, since only GET endpoints are called, and the data is written to local CSV output files. |
118
+
| **aio_ips2firewall.py** | That code will collect the source IP of security events and creates L7 firewall rules to block them. `usage: aio_ips2firewall.py [-h] -o ORGANIZATIONS [ORGANIZATIONS ...] [-f FILTER] [-s] [-d DAYS]` |
0 commit comments