There's also the Meraki github repo's sleep method. I use this all the time. I've included a sample request so you can see how the whole shebang works...
import time
import requests
from datetime import datetime
# Used for time.sleep(API_EXEC_DELAY). Delay added to avoid hitting
# dashboard API max request rate
API_EXEC_DELAY = 0.21
# connect and read timeouts for the Requests module
REQUESTS_CONNECT_TIMEOUT = 30
REQUESTS_READ_TIMEOUT = 30
# used by merakirequestthrottler(). DO NOT MODIFY
LAST_MERAKI_REQUEST = datetime.now()
def merakirequestthrottler(p_requestcount=1):
"""Add delay to requests to avoid hitting shaper."""
global LAST_MERAKI_REQUEST
if (datetime.now() - LAST_MERAKI_REQUEST).total_seconds() < (API_EXEC_DELAY * p_requestcount):
time.sleep(API_EXEC_DELAY * p_requestcount)
LAST_MERAKI_REQUEST = datetime.now()
return
def printusertext(p_message):
"""Print a line of text meant for the user to read.
Do not process these lines when chaining scripts
"""
print(f'@ {p_message}')
def getnetworklist(p_apikey, p_orgid, p_shardurl):
"""Return list of networks for specified organization."""
merakirequestthrottler()
r = ""
try:
r = requests.get(f"https://{p_shardurl}/api/v0/organizations/{p_orgid}/networks", headers={'X-Cisco-Meraki-API-Key': p_apikey, 'Content-Type': 'application/json'}, timeout=(REQUESTS_CONNECT_TIMEOUT, REQUESTS_READ_TIMEOUT))
except:
printusertext('ERROR 02: Unable to contact Meraki cloud')
sys.exit(2)
rjson = r.json()
return(rjson)