Cisco Meraki Dashboard API library
Project description
Meraki Dashboard API Python Library
The Meraki Dashboard API Python library provides all current Meraki dashboard API calls to interface with the Cisco Meraki cloud-managed platform. Meraki generates the library based on dashboard API's OpenAPI spec to keep it up to date with the latest API releases, and provides the full source code for the library including the tools used to generate the library, if you are participating in the Early Access program or would like to contribute to the development of the library. Meraki welcomes constructive pull requests that maintain backwards compatibility with prior versions. The library requires Python 3.10+, receives support from the community, and you can install it via PyPI:
pip install --upgrade meraki
If you participate in our Early Access program and would like to use early access features via the library, you'll find instructions in the generator readme.
Features
While you can make direct HTTP requests to dashboard API in any programming language or REST API client, using a client library can make it easier for you to focus on your specific use case, without the overhead of having to write functions to handle the dashboard API calls. The Python library can also take care of error handling, logging, retries, and other convenient processes and options for you automatically.
- Support for all API endpoints, as it uses the OpenAPI specification to generate source code
- Log all API requests made to a local file as well as on-screen console
- Automatic retries upon 429 rate limit errors, using
the
Retry-After
field within response headers - Get all (or a specified number of) pages of data with built-in pagination control
- Tweak settings such as maximum retries, certificate path, suppress logging, and other options
- Simulate POST/PUT/DELETE calls to preview first, so that network configuration does not get changed
Setup
-
Enable API access in your Meraki dashboard organization and obtain an API key (instructions)
-
Keep your API key safe and secure, as it is similar to a password for your dashboard. If publishing your Python code to a wider audience, please research secure handling of API keys.
-
Install the latest version of Python 3
-
Use pip (or an alternative such as easy_install) to install the library from the Python Package Index:
pip install meraki
- If you have both Python3 and Python2 installed, you may need to use
pip3
(sopip3 install meraki
) along withpython3
on your system - If meraki was previously installed, you can upgrade to the latest non-beta release
with
pip install --upgrade meraki
-
The library supports Meraki dashboard API v1. You can also specify the version of the library when installing with pip:
- See the full release history to pick the version you want, or
use
pip install meraki==
without including a version number to display the list of available versions - Versions begin with 1 (1.0.0bz for beta)
- Specify the version you want with the install command; for example:
pip install meraki==1.34.0
- You can also see the version currently installed with
pip show meraki
- End-of-life v0 versions of the Python library begin with 0 (0.x.y) and are not supported nor recommended.
- See the full release history to pick the version you want, or
use
Usage
-
Export your API key as an environment variable, for example:
export MERAKI_DASHBOARD_API_KEY=YOUR_KEY_HERE
-
Alternatively, define your API key as a variable in your source code; this method is not recommended due to its inherent insecurity.
-
Single line of code to import and use the library goes at the top of your script:
import meraki
-
Instantiate the client (API consumer class), optionally specifying any of the parameters available to set:
dashboard = meraki.DashboardAPI()
-
Make dashboard API calls in your source code, using the format client.scope.operation, where client is the name you defined in the previous step (dashboard above), scope is the corresponding scope that represents the first tag from the OpenAPI spec, and operation is the operation 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:
my_orgs = dashboard.organizations.getOrganizations()
Examples
You can find fully working example scripts in the examples folder.
Script | Purpose |
---|---|
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. |
AsyncIO
asyncio is a library to write concurrent code using the async/await syntax. Special thanks to Heimo Stieg (@coreGreenberet) who has ported the API to asyncio.
Installation on macOS
If you use a Mac, then you may need to take additional Python installation steps that aren't required on other platforms. This is a limitation of macOS and not the library. This step is not required on Windows.
Usage
The usage is similiar to the sequential version above. However it has has some differences.
-
Export your API key as an environment variable, for example:
export MERAKI_DASHBOARD_API_KEY=YOUR_KEY_HERE
-
Alternatively, define your API key as a variable in your source code; this method is not recommended due to its inherent insecurity.
-
Single line of code to import and use the library goes at the top of your script:
import meraki.aio
-
Instantiate the client (API consumer class), optionally specifying any of the parameters available to set:
async with meraki.aio.AsyncDashboardAPI() as aiomeraki:
The async with statement is important here to make sure, that the client sessions will be closed after using the api.
-
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, 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:
my_orgs = await aiomeraki.organizations.getOrganizations()
-
Run everything inside an event loop.
import asyncio
if __name__ == "__main__":
# replace my_async_entry_point with the name of your entry point method
asyncio.run(my_async_entry_point())
Examples
You can find fully working example scripts in the examples folder.
Script | Purpose |
---|---|
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. | |
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] |
Note for application developers and ecosystem partners
We're so glad that you're leveraging our Python library. It's best practice to identify your application with every API request that you make. You can easily do this automatically just by following the format defined in config.py and passing the session kwarg:
MERAKI_PYTHON_SDK_CALLER
Unless you are an ecosystem partner, this identifier is optional.
- If you are an ecosystem partner and you have questions about this requirement, please reach out to your ecosystem rep.
- If you have any questions about the formatting, please ask your question by opening an issue in this repo.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file meraki-1.51.0.tar.gz
.
File metadata
- Download URL: meraki-1.51.0.tar.gz
- Upload date:
- Size: 264.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc95144e2fbaa1efa60e7e27f4db655978e2e23dc4e8064e0d967e3c4bd24b38 |
|
MD5 | d0b70a26a7c5ac2f7c1f9f24995ebe93 |
|
BLAKE2b-256 | b9479e6d8bffbe519dbdb7c3d5ac6661bada9bfaed4f208aea50766bebc01775 |
File details
Details for the file meraki-1.51.0-py3-none-any.whl
.
File metadata
- Download URL: meraki-1.51.0-py3-none-any.whl
- Upload date:
- Size: 295.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 921e2df3d4ee0b93f9cd5cb1a1cafeafab3f2c08977758d654399962a977be4e |
|
MD5 | c34842131835fc6a35cddf5326906bb9 |
|
BLAKE2b-256 | 1ab34118ddd054c8013a25738672a0d09b51ccd0bc8e4d48367cda461317b567 |