Christian Manivong 1f85a419b7
driver / lint (pull_request) Successful in 16s
driver / standard (pull_request) Successful in 19s
driver / types (pull_request) Successful in 1m0s
driver / lowest (pull_request) Successful in 46s
driver / test (3.12) (pull_request) Successful in 1m12s
driver / test (3.13) (pull_request) Successful in 1m11s
driver / build (pull_request) Successful in 31s
driver / security (pull_request) Failing after 55s
CI / driver (pull_request) Failing after 2m0s
driver / publish (pull_request) Skipped
refactor: keep the VLAN and encryption parsers under the complexity limit
The standard's ratchet counted 12 for parse_vlans_detail_classic and 11 for
_encryption. Placing one port in its VLANs and naming a PSK's encryption are
functions of their own now; nothing changes in what they return.
2026-12-05 17:26:51 +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). Every driver runs against the simulator in sim/ (a controller on HTTPS, a switch on SSH, both from these fixtures) in the test suite, over real TLS and SSH. The versions it plays are 9.1, 10.x and a standalone controller.

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. Each adopted switch and AP names its driver and the args that reach it through this controller
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%