Christian Manivong e040280ce9 fix: a switch or access point is read once at open
With an API key and a known MAC, opening sent no request at all: a refused
key, a redirect or a device the controller does not know showed only at the
first getter. Open now reads the device and closes again when that fails.
2026-12-05 17:07:27 +01:00

napalm-ubiquiti

NAPALM drivers for Ubiquiti UniFi, built on napalm-device-types.

Driver Class Role
unifi_switch UnifiSwitchDriver SwitchDriver: a UniFi switch (USW)
unifi_ap UnifiAccessPointDriver AccessPointDriver: a UniFi access point (UAP, U6, U7)
unifi_network UnifiNetworkDriver NetworkControllerDriver: the UniFi Network application itself

Each switch and access point is a device of its own. It is read through the controller that manages it, or over SSH when there is none (or none to be trusted with the key). The controller is a device too: it names what it manages, so the layer above can link or add those devices.

Tested against

What Versions
Classic API answers US-16-150W, US-8 and UAP-AC-Pro on 4.0.x, USW Flex Mini 1.8.4: recorded answers from aiounifi's test data
Device over SSH US-24 (Gen1) on 7.1.26: recorded output from abates/napalm-unifi's test data
Integration API Network 10.6.106: answer shapes from Ubiquiti's published OpenAPI description

Not yet against a device or a controller of our own (see tests/fixtures/README.md).

Connection

A switch or access point through its controller

from napalm import get_network_driver

driver = get_network_driver("unifi_switch")
args = {"controller_url": "https://192.0.2.1", "token_value": "<API key>"}
with driver("192.0.2.20", "", "", optional_args=args) as switch:
    print(switch.get_vlans_detail())

The hostname is the device's management address; it finds the device on the controller, or mac names it.

Controller URL Credential
UniFi OS console (UDM, UCG, Cloud Key Gen2+, UniFi OS Server), Network 9.0.108 and later https://<console> an API key (Settings → Control Plane → Integrations), as token_value or api_secret
Same, older https://<console> a local admin's username and password
Standalone Network application https://<host>:8443 a local admin's username and password

A cloud account with multi-factor authentication cannot log in through the API. Use a local admin or an API key. Logins are rate-limited by the controller. After too many, the driver raises RateLimited with the wait and does not retry.

A switch or access point over SSH

Without controller_url, the driver reads the device over SSH with the device SSH credentials its controller gave it (the controller's Device SSH Authentication setting), or the factory login of a device never adopted. Over SSH it only reads. A switch over SSH reports each port's untagged VLAN, but not the VLANs a port carries tagged.

The controller

driver = get_network_driver("unifi_network")
with driver("192.0.2.1", "", "", optional_args={"token_value": "<API key>"}) as controller:
    print(controller.get_managed_devices())

Optional args

Arg Drivers
controller_url switch, AP the controller; without it the device is read over SSH
transport switch, AP controller or ssh, to override that default
token_value / api_secret all the controller's API key
controller_username / controller_password switch, AP a controller login separate from the device's own
site all the site's short name (default). For a device: the site it is in. For the controller: only that site's devices
mac switch, AP the device's MAC on the controller, instead of finding it by its address
port controller 443 (UniFi OS, default) or 8443 (standalone)
ssh_username, ssh_password, ssh_private_key_str, ssh_port, key_file switch, AP the SSH login, when it is not the driver's username and password
tls_fingerprints, tls_certificate_observer, ssl_verify all the controller's certificate: trusted on first use and pinned, or checked against a CA too
ssh_host_keys, ssh_host_key_observer switch, AP the device's SSH host key: trusted on first use, a changed one refused before any login

Supported

Getter Switch AP Controller
get_facts ✓ ✓ the Network application's version
get_interfaces, get_interfaces_ip ports as Port <n>, plus Management same none: its ports are its devices'
get_lldp_neighbors, get_lldp_neighbors_detail ✓ ✓ –
get_mac_address_table over SSH (a controller does not report the tables) – –
get_poe_status ✓ – –
get_vlans_detail, get_vlans through the controller: port overrides, port profiles, defaults; over SSH: untagged only – –
get_ssids – ✓, with security from the controller –
get_radio_status, get_wireless_clients – ✓ –
get_managed_devices – – Integration API (with devices waiting for adoption on 10.x), else the classic API
Discovery Ubiquiti OUIs Ubiquiti OUIs the web page on 443/8443

Not supported (yet)

Writes (VLANs, WLANs, port VLANs) are not supported. Also missing: gateways (UDM/UCG/USG as routers), UniFi Protect, Access and Talk, adoption, firmware upgrades, and devices without SSH (USW Flex Mini, USW Ultra), which can only be read through a controller.

Development

The rules are in STANDARDS.md. How UniFi stores a port's VLANs is in docs/PORT_VLANS.md.

python -m venv .venv && .venv/bin/pip install -e ".[dev]"
.venv/bin/pytest --cov

License

Apache-2.0

S
Description
NAPALM drivers for Ubiquiti UniFi: switches, access points and the UniFi Network controller
Readme
160 KiB
0 Stars 1 Watchers 0 Forks
Languages
Python 99.8%
Dockerfile 0.2%