Create a Read-Only Meraki Inventory with Python
The Meraki Dashboard API can provide a current inventory of organizations, networks, and devices available to an administrator. This guide uses the official Python library and read-only GET operations to write a CSV report. It does not change device configuration.
Create a Virtual Environment and Install the SDK
PrerequisitesUse a supported Python 3 installation and a dedicated virtual environment so the Meraki library does not alter system Python packages. Run these commands in a new project directory.
mkdir -p meraki-inventorycd meraki-inventory &&python3 -m venv .venv &&.venv/bin/python -m pip install --upgrade pip &&.venv/bin/python -m pip install meraki❯ Illustrative Output (Results Vary)
Successfully installed meraki-<installed version>Keep the API Key Out of the Script
CredentialsEnable Dashboard API access for the organization and create or use an API identity with the least privileges needed to read inventory. Keep the key out of source files and shell history. The hidden prompt below stores it only in the current shell session; do not enable shell tracing while entering it.
read -r -s -p 'Meraki API key: ' MERAKI_DASHBOARD_API_KEYexport MERAKI_DASHBOARD_API_KEYprintf '\n'❯ Illustrative Output (Results Vary)
The prompt accepts the key without echoing it.No key value should appear in the terminal output.Query Organizations, Networks, and Devices
InventorySave this script as meraki_inventory.py. It checks that the key is present, follows all pages for organizations, networks, and assigned organization devices, and writes selected inventory fields. It uses the organization-scoped devices endpoint rather than the deprecated network-scoped device-list endpoint. Every API operation used here is a read request.
import csvimport osimport sys
import meraki
api_key = os.environ.get("MERAKI_DASHBOARD_API_KEY", "").strip()if not api_key: sys.exit("Set MERAKI_DASHBOARD_API_KEY in this shell before running the report.")
dashboard = meraki.DashboardAPI(api_key, output_log=False, print_console=False)rows = []
for organization in dashboard.organizations.getOrganizations(total_pages="all"): networks = dashboard.organizations.getOrganizationNetworks( organization["id"], total_pages="all" ) network_names = {network["id"]: network.get("name", "") for network in networks} devices = dashboard.organizations.getOrganizationDevices( organization["id"], total_pages="all" ) for device in devices: rows.append( { "organization": organization.get("name", ""), "network": network_names.get(device.get("networkId", ""), ""), "product_type": device.get("productType", ""), "model": device.get("model", ""), "name": device.get("name", ""), "serial": device.get("serial", ""), "tags": ", ".join(device.get("tags", [])), } )
fields = [ "organization", "network", "product_type", "model", "name", "serial", "tags",]# Create a new private file; refuse to overwrite an earlier inventory.report_fd = os.open("meraki_inventory.csv", os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)with os.fdopen(report_fd, "w", newline="", encoding="utf-8") as report: writer = csv.DictWriter(report, fieldnames=fields) writer.writeheader() writer.writerows(rows)
print(f"Wrote {len(rows)} device records to meraki_inventory.csv")❯ Illustrative Output (Results Vary)
Wrote 42 device records to meraki_inventory.csvThe number varies with the API identity's organization permissions.Review the Exported Records
VerifyRun the script from the same shell where the key was loaded. Check the row count and sample the output locally. Confirm the report covers the expected organizations and network count before using it as an inventory baseline.
.venv/bin/python meraki_inventory.py &&head -n 5 meraki_inventory.csv❯ Illustrative Output (Results Vary)
organization,network,product_type,model,name,serial,tagsExample Org,Office,wireless,MRxx,Office AP,Qxxx-XXXX-XXXX,Store the Inventory Securely and Re-run Deliberately
OperationsSet access controls on the CSV and keep it outside public or shared source repositories. The official Meraki Python library supports pagination and retries rate-limit responses using the API’s retry information. If an operation fails, record the request time and status without exposing the API key. The example disables SDK disk and console logging so inventory is not also written into an unprotected log. It creates a new owner-only CSV on Linux and refuses to overwrite an existing report; move a previous report to approved storage before rerunning. On Windows, apply equivalent NTFS access controls. Clear the key from the shell when finished.
chmod 600 meraki_inventory.csv &&unset MERAKI_DASHBOARD_API_KEY❯ Illustrative Output (Results Vary)
Report permissions: owner read/write onlyAPI key: removed from the current shell environment