In addition to updated endpoints, this release contains the new batch class for easy creation of actions for action batches.
Upgrade with
pip install --upgrade meraki
View the release on PyPi and the API changelog.
Good addition!
I would also like to highlight the new possibility to use iterators in all list methods of the api.
Just add the new parameter to the Async/DashboardAPI object
use_iterator_for_get_pages = True
so in total it might look like this:
meraki.DashboardAPI(
api_key,
base_url="https://api.meraki.com/api/v1",
log_file_prefix=__file__[:-3],
print_console=True,
use_iterator_for_get_pages = True
)
Currently when you are calling e.g. meraki.organizations.getOrganizationNetworks it is split into pages. The API will download each additional page and create a complete list of all entries in each page. As soon as the api has finished all of these calls it will return the whole list.
This creates a few problems:
The iterator version on the other hand will download exactly one page at the time and yield every entry of the page.
As soon as you hit the last entry, then it will download the next page and so on.
The Async implementation is a little bit special here. It will reduce the delay between the pages as it is downloading the next page while you are still iterating over the current page.
As most scripts are just doing a loop over the result of the api call, there won't be any changes needed for the normal api calls.
for x in meraki.organizations.getOrganizationNetworks(organizationId=ORGANIZATION_ID, perPage=perPage, total_pages=-1):
print(f"{x['id']} - {x['name']}")
This will work with use_iterator_for_get_pages = True and False.
For getNetworkEvents there is a difference. The legacy api call would create a dictionary with pageStart/End and an "events" key which holds all events.
The iterator is getting rid of pageStart/End and will just return each event directly.
so the following version has to be changed from this:
result = meraki.networks.getNetworkEvents(networkId=NETWORK_ID, perPage=perPage,total_pages=50,productType="wireless")
for x in result["events"]:
print(f"{x['occurredAt']}")
to this:
for x in meraki.networks.getNetworkEvents(networkId=NETWORK_ID, perPage=perPage,total_pages=50,productType="wireless"):
print(f"{x['occurredAt']}")
To get this with asyncio to work you will need to do a little bit more.
Instead of "await"ing the method you have to use "async for".
e.g. for getOrganizationNetworks:
for x in await aiomeraki.organizations.getOrganizationNetworks(organizationId=ORGANIZATION_ID, perPage=perPage, total_pages=-1):
print(f"{x['id']} - {x['name']}")
becomes this:
async for x in aiomeraki.organizations.getOrganizationNetworks(organizationId=ORGANIZATION_ID, perPage=perPage,total_pages=-1):
print(f"{x['id']} - {x['name']}")
the backend changes are the same for the normal version, so you will also just receive the events itself here.
result = await aiomeraki.networks.getNetworkEvents(networkId=NETWORK_ID, perPage=perPage,total_pages=50,productType="wireless")
for x in result["events"]:
print(f"{x['occurredAt']}")
has to replaced with:
async for x in aiomeraki.networks.getNetworkEvents(networkId=NETWORK_ID, perPage=perPage,total_pages=50,productType="wireless"):
print(f"{x['occurredAt']}")
Great write up and examples.
Now Python SDK 1.7.2 release with new updates 🙂
https://pypi.org/project/meraki/1.7.2/