A Python client library for the Cambium cnMaestro API.
- Client-Credentials Authentication: Handles OAuth2 client credentials token acquisition.
- Resource-Based API: Exposes workflow-oriented resources from a single
CnMaestroCliententry point. - Higher-Level Operations: Includes
find,upsert,get_status, and CLI-driven helpers for cnMatrix workflows. - Keyword-Only Public APIs: Resource methods are keyword-only for clarity and call-site stability.
uv venv
uv sync --extra devOr install the published package:
pip install cambium-cnmaestrofrom cambium_cnmaestro import CnMaestroClient
with CnMaestroClient(
client_id="your-client-id",
client_secret="your-client-secret",
) as client:
devices = client.devices.list()
print(devices)base_url defaults to the cnMaestro cloud anchor (https://cloud.cambiumnetworks.com).
It is only the OAuth2 entry point: the token response returns a redirect_uri
pointing to your tenant's regional API server, and the SDK routes all subsequent
calls there automatically. Set base_url explicitly only for On-Premises or a
fixed regional endpoint.
from cambium_cnmaestro import CnMaestroClient
client = CnMaestroClient(
client_id="your-client-id",
client_secret="your-client-secret",
# base_url="https://cnmaestro.example.com", # defaults to the cloud anchor
# ssl_verify=True,
# timeout_seconds=30.0,
# api_prefix="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/api/v2",
# rate_limit_policy=RECOMMENDED_RATE_LIMIT_POLICY, # see "Rate limiting (429)"
)By default the client waits for exactly as long as the server's own
RateLimit-Reset/Retry-After header says, plus up to a second of jitter, and retries a
few times. That is a poor strategy under concurrent load: a server that reports a reset
time of "now" while still throttling gets sub-second waits, so the whole retry budget is
spent in about a second — and conversely, a far-future hint blocks the call for as long as
the server asks, since there is no ceiling.
Pass a RateLimitPolicy to get exponential backoff with jitter instead, bounded so the
total wait stays inside your own deadline. Set it once at construction and it applies to
every request the client makes, token acquisition included:
from cambium_cnmaestro import CnMaestroClient, RECOMMENDED_RATE_LIMIT_POLICY
client = CnMaestroClient(
client_id="your-client-id",
client_secret="your-client-secret",
rate_limit_policy=RECOMMENDED_RATE_LIMIT_POLICY,
)Or tune it — the values below are the recommended defaults:
from cambium_cnmaestro import RateLimitPolicy
policy = RateLimitPolicy(
max_retries=5, # extra attempts after the first 429
initial_backoff_seconds=1.0,
backoff_coefficient=2.0,
max_backoff_seconds=30.0, # ceiling for any single wait
max_elapsed_seconds=30.0, # ceiling for the total wait within one request
)The server's hint is then treated as a lower bound on each wait rather than the wait itself, so a hint of "now" cannot collapse the backoff.
The default is kept for backwards compatibility. In 1.0.0 the recommended policy becomes
the default and the legacy path is removed — if you need today's defaults beyond that
point, pass an explicit RateLimitPolicy(...) rather than relying on omission.
Use client.devices for device CRUD and device-oriented helpers.
# List devices (supports paging/search via params)
devices_page = client.devices.list(params={"page": 1, "pageSize": 100})
# Get a device by MAC
device_page = client.devices.get(mac="aa:bb:cc:dd:ee:ff")
# Find a single device:
# - by mac: uses GET /devices/{mac}
# - by msn: uses GET /devices?search=<msn> and requires a single match
device = client.devices.find(msn="MSN123")
# Project status fields commonly used by switch workflows
status = client.devices.get_status(msn="MSN123")
print(status.online, status.profile_attached, status.sync_status, status.mac)
# Create-or-update (idempotent helper):
# - resolves existing by mac (if given) else by msn search
# - creates when missing (requires type + msn; sets approved=True; strips create-only "overrides")
result = client.devices.upsert(
msn="MSN123",
device={
"type": "cnmatrix",
"name": "switch-1",
# ... additional cnMaestro device fields ...
},
)
print(result)client.devices.get_interfaces(...) triggers a CLI command on the device, polls for completion, and parses the output into structured interface rows (NAPALM-like fields).
interfaces = client.devices.get_interfaces(msn="MSN123")
for iface in interfaces:
print(iface.name, iface.mac_address, iface.is_up, iface.is_enabled, iface.mtu)Use client.networks for network CRUD and upsert(...). cnMaestro network update is unreliable, so existing networks are treated as a no-op.
# List and get by name
networks = client.networks.list()
corp = client.networks.get(name="corp")
# Create-or-no-op when it already exists
network_result = client.networks.upsert(
network={
"name": "corp",
# ... network fields ...
}
)
print(network_result)Sites are scoped under a network. Use client.sites with network_id (cnMaestro network name/id) and site["name"].
site_result = client.sites.upsert(
network_id="corp",
site={
"name": "building-a",
# ... site fields ...
},
)
print(site_result)Use client.wifi_enterprise for Wi-Fi Enterprise resources:
client.wifi_enterprise.wlansclient.wifi_enterprise.ap_groups
# WLANs (SSIDs)
wlan_result = client.wifi_enterprise.wlans.upsert(
wlan={
"name": "Guest",
# ... WLAN fields ...
}
)
# AP Groups (optionally attach wlans list via upsert helper)
ap_group_result = client.wifi_enterprise.ap_groups.upsert(
ap_group={
"name": "building-a-aps",
# ... AP group fields ...
},
wlans=["Guest"],
)
print(wlan_result, ap_group_result)Use client.cnmatrix for cnMatrix switch group and port workflows:
client.cnmatrix.switch_groupsclient.cnmatrix.switch_groups_portsclient.cnmatrix.ports
# Switch groups: find and upsert
sg = client.cnmatrix.switch_groups.find(name="building-a")
sg_result = client.cnmatrix.switch_groups.upsert(
switch_group={"name": "building-a", "description": "Example"}
)
# Push port config to cnMatrix switches
client.cnmatrix.ports.update(
ports=[
{
"mac": "aa:bb:cc:dd:ee:ff",
"config": {"basic": {"description": "uplink"}},
},
]
)
# Switch-group port lookups
ports_for_group = client.cnmatrix.switch_groups_ports.list_for_switch_group(switch_group_name="building-a")
ports_for_device = client.cnmatrix.switch_groups_ports.get_for_device(
switch_group_name="building-a",
device_mac="aa:bb:cc:dd:ee:ff",
)
print(sg, sg_result, ports_for_group, ports_for_device)Use client.backups to launch and check backups of an On-Premises cnMaestro
instance via the Cloud account-backup API. The serial argument is the
On-Premises instance serial (a UUID-like string), not a device MAC/MSN.
serial = "F47AC10B-58CC-4372-A567-0E02B2C3D479"
# Launch a backup — POST /account/backup/{serial} with an empty body.
# Returns the new job record, e.g. {"jobId": "...", "status": "created"}.
# This call can be slow to respond; it uses a generous default timeout
# (180s) which you can override per call.
job = client.backups.create(serial=serial) # or: create(serial=serial, timeout=240.0)
print(job["jobId"], job["status"])
# Check status — GET /account/backup/{serial}.
# Lifecycle: "created" -> "validating"/"preparing" -> "in_progress" ->
# "completed" (success) or "failed". A run takes ~25-30 minutes.
status = client.backups.get(serial=serial)
print(status["status"])
# Download the completed backup. This blocks until the backup reaches a terminal
# state (wait=True), then streams the .tar.gz to `dest` and returns its Path.
path = client.backups.download(
serial=serial,
dest="cnmaestro-backup.tar.gz",
wait=True, # omit to require the backup to be "completed" already
poll_interval=120, # seconds between status checks
timeout=2400, # give up after this many seconds
)
print("saved:", path)
# Or just get the presigned download URL from a completed backup (or None):
url = client.backups.get_export_url(serial=serial)Notes:
- Backup jobs are not tracked in the generic
/jobscollection, so useclient.backups.get(...)(notclient.jobs) to check status. - On
completed, the status record carriesexportUrl— a presigned S3 URL to the backup.tar.gz(valid ~24h).download(...)fetches it directly from S3 (no auth token is sent to the presigned URL). TreatexportUrlas a short-lived secret; do not log or persist it. - If the account lacks the Business-Continuity backup entitlement, calls raise
CnMaestroHTTPError(HTTP 400, "feature is disabled").