Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Official Dashboard API library (SDK) for Python

License

NotificationsYou must be signed in to change notification settings

meraki/dashboard-api-python

Repository files navigation

The Meraki Dashboard API Python library provides all currentMerakidashboard API calls to interface with the Cisco Merakicloud-managed platform. Meraki generates the library based on dashboard API's OpenAPI spec to keep it up to date withthe latest API releases, and provides the full source code for the library including the tools used to generate thelibrary, if you are participating in the Early Access program or would like to contribute to the development of thelibrary. Meraki welcomes constructive pull requests that maintain backwards compatibility with prior versions. Thelibrary requires Python 3.10+, receives support from the community, and you can install itviaPyPI:

pip install --upgrade meraki

If you participateinour Early Access programand would like to use early access features via the library,you'llfind 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 clientlibrary can make it easier for you to focus on your specific use case, without the overhead of having to write functionsto handle the dashboard API calls. The Python library can also take care of error handling, logging, retries, and otherconvenient processes and options for you automatically.

  • Support for all API endpoints, as it uses theOpenAPI specification togenerate source code
  • Log all API requests made to a local file as well as on-screen console
  • Automatic retries upon 429 rate limit errors, usingtheRetry-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

  1. Enable API access in your Meraki dashboard organization and obtain an APIkey (instructions)

  2. Keep your API key safe and secure, as it is similar to a password for your dashboard. If publishing your Python codeto a wider audience, please research secure handling of API keys.

  3. Install the latest version of Python 3

  4. Usepip (or an alternative such aseasy_install) to install the library from thePythonPackage Index:

    • pip install meraki
    • If you have both Python3 and Python2 installed, you may need to usepip3 (sopip3 install meraki) alongwithpython3 on your system
    • Ifmeraki was previously installed, you can upgrade to the latest non-beta releasewithpip install --upgrade meraki
  5. The library supports Meraki dashboard API v1. You can also specify the version of the library when installing withpip:

    • See the fullrelease history to pick the version you want, orusepip install meraki== without including a version number to display the list of available versions
    • Versions begin with1 (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 withpip show meraki
    • End-of-life v0 versions of the Python library begin with0 (0.x.y) and are not supported norrecommended.

Usage

  1. Export your API key asanenvironment variable, for example:

    export MERAKI_DASHBOARD_API_KEY=YOUR_KEY_HERE
  2. Alternatively, define your API key as a variable in your source code; this method is not recommended due to itsinherent insecurity.

  3. Single line of code to import and use the library goes at the top of your script:

    importmeraki
  4. Instantiate the client (API consumer class), optionally specifying any of the parameters available to set:

    dashboard=meraki.DashboardAPI()
  5. Make dashboard API calls in your source code, using the formatclient.scope.operation, whereclient is the nameyou defined in the previous step (dashboard above),scope is the corresponding scope that represents the firsttag from the OpenAPI spec, andoperation is the operation of the API endpoint. For example, to make a call to getthe 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 theexamples folder.

ScriptPurpose
org_wide_clients.pyThat 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 theasync/await syntax. Special thanks to HeimoStieg (@coreGreenberet) who has ported the API to asyncio.

Installation on macOS

If you use a Mac, then you may need to takeadditional Python installation steps that aren't required on other platforms. Thisisa limitation of macOS and not the library. This step isnot required on Windows.

Usage

The usage is similiar to the sequential version above. However it has has some differences.

  1. Export your API key asanenvironment variable, for example:

    export MERAKI_DASHBOARD_API_KEY=YOUR_KEY_HERE
  2. Alternatively, define your API key as a variable in your source code; this method is not recommended due to itsinherent insecurity.

  3. Single line of code to import and use the library goes at the top of your script:

    importmeraki.aio
  4. Instantiate the client (API consumer class), optionally specifying any of the parameters available to set:

    asyncwithmeraki.aio.AsyncDashboardAPI()asaiomeraki:

    Theasync with statement is important here to make sure, that the client sessions will be closed after using theapi.

  5. Make dashboard API calls in your source code, using the format awaitclient.section.operation, whereclient isthe name you defined in the previous step (aiomeraki above),section is the corresponding group (or tag fromthe OpenAPI spec) from theAPI docs, andoperation is the name (oroperation ID from OpenAPI) of the API endpoint. For example, to make a call to get the list of organizationsaccessible by the API key defined in step 1, use this function call:

    my_orgs=awaitaiomeraki.organizations.getOrganizations()
  6. Run everything inside an event loop.

importasyncioif__name__=="__main__":# replace my_async_entry_point with the name of your entry point methodasyncio.run(my_async_entry_point())

Examples

You can find fully working example scripts in theexamples folder.

ScriptPurpose
aio_org_wide_clients.pyThat 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.pyThat 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 APIrequest that you make. You can easily do this automatically just by following the format definedinconfig.py and passing the sessionkwarg:

MERAKI_PYTHON_SDK_CALLER

Unless you are an ecosystem partner, this identifier is optional.

  1. If you are an ecosystem partner and you have questions about this requirement, please reach out to your ecosystemrep.
  2. If you have any questions about the formatting, please ask your question by opening an issue in this repo.

[8]ページ先頭

©2009-2025 Movatter.jp