Python library for UniFi network topology discovery and SVG rendering
Project description
unifi-topology
Python library for UniFi network topology discovery and SVG diagram rendering.
Extracted from unifi-network-maps to provide a clean library API for programmatic use, including the Home Assistant integration.
Installation
pip install unifi-topology
Quick Start
from unifi_topology import (
Config,
fetch_devices,
fetch_networks,
normalize_devices,
build_topology,
extract_wan_info,
render_svg,
resolve_svg_themes,
SvgOptions,
)
# Connect to UniFi controller
config = Config.from_env()
api_devices = fetch_devices(config)
networks = fetch_networks(config)
# Build topology model
devices = normalize_devices(api_devices)
result = build_topology(devices, include_ports=True, only_unifi=False)
wan_info = extract_wan_info(devices, list(networks))
# Render SVG
theme = resolve_svg_themes(theme_name="unifi")
options = SvgOptions(include_ports=True)
svg = render_svg(result.devices, result.edges, theme=theme, options=options, wan_info=wan_info)
API Overview
Adapters
Config-- Configuration from environment variables (UNIFI_URL,UNIFI_USER,UNIFI_PASS, etc.)fetch_devices(config)-- Fetch device list from UniFi controllerfetch_clients(config)-- Fetch active clientsfetch_networks(config)-- Fetch network/VLAN configurationfetch_firewall_zones(config)-- Fetch firewall zone definitionsfetch_firewall_policies(config)-- Fetch zone-based firewall policiesfetch_firewall_groups(config)-- Fetch firewall address/port groupsresolve_hostnames(ips, dns_server)-- Reverse DNS resolution
Model
normalize_devices(raw)-- Convert raw API data toDeviceobjectsnormalize_firewall_zones(raw)-- Convert raw zone data toFirewallZoneobjectsnormalize_firewall_policies(raw)-- Convert raw policy data toFirewallPolicyobjectsnormalize_firewall_groups(raw)-- Convert raw group data toFirewallGroupobjectsbuild_topology(devices, ...)-- Build topology graph (TopologyResultwith devices + edges)build_device_inventory(devices)-- Build device info table (list[DeviceInfo])extract_wan_info(devices, networks)-- Extract WAN upstream info
Rendering
render_svg(devices, edges, theme, options, ...)-- Orthogonal SVG diagramrender_svg_isometric(devices, edges, theme, options, ...)-- Isometric 3D-style SVGrender_dual(devices, edges, themes, options, ...)-- Dual light/dark theme SVGresolve_svg_themes(theme_name, theme_file)-- Load built-in or custom SVG theme
Built-in themes: unifi, unifi-dark, minimal, minimal-dark, classic, classic-dark
Development
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
make lint # ruff check
make format # ruff format
make typecheck # pyright
make test # pytest
make ci # all checks
Contributing
See CONTRIBUTING.md for development setup and guidelines.
License
MIT -- see LICENSE. Third-party licenses in LICENSES.md.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unifi_topology-1.0.7.tar.gz.
File metadata
- Download URL: unifi_topology-1.0.7.tar.gz
- Upload date:
- Size: 319.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e281bf717697692e09477c45a32cdebde41773aeb8ea869e0a0c7f144716dbc
|
|
| MD5 |
dd5a1cef9deb0ec96da54734ea75f6ba
|
|
| BLAKE2b-256 |
b3d5ca1ae89bf3c831f393cef48441b319f19d3ac82927666d80fd379c588c48
|
Provenance
The following attestation bundles were made for unifi_topology-1.0.7.tar.gz:
Publisher:
publish.yml on merlijntishauser/unifi-topology
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unifi_topology-1.0.7.tar.gz -
Subject digest:
6e281bf717697692e09477c45a32cdebde41773aeb8ea869e0a0c7f144716dbc - Sigstore transparency entry: 1066521780
- Sigstore integration time:
-
Permalink:
merlijntishauser/unifi-topology@0217d6b50e638c2d41b67a5097efbc688df6900c -
Branch / Tag:
refs/tags/v1.0.7 - Owner: https://github.com/merlijntishauser
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0217d6b50e638c2d41b67a5097efbc688df6900c -
Trigger Event:
push
-
Statement type:
File details
Details for the file unifi_topology-1.0.7-py3-none-any.whl.
File metadata
- Download URL: unifi_topology-1.0.7-py3-none-any.whl
- Upload date:
- Size: 350.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8bd53c1f3b0efdc9817b3530353deede45536f853cf138b9ad489e5b1b47a15
|
|
| MD5 |
8947e2ce9e8d505023ae9682034497aa
|
|
| BLAKE2b-256 |
3c221154168b390a8c499709c12dea331897b7317b7bdac2a1cd4e3d2b2d3b45
|
Provenance
The following attestation bundles were made for unifi_topology-1.0.7-py3-none-any.whl:
Publisher:
publish.yml on merlijntishauser/unifi-topology
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
unifi_topology-1.0.7-py3-none-any.whl -
Subject digest:
d8bd53c1f3b0efdc9817b3530353deede45536f853cf138b9ad489e5b1b47a15 - Sigstore transparency entry: 1066521784
- Sigstore integration time:
-
Permalink:
merlijntishauser/unifi-topology@0217d6b50e638c2d41b67a5097efbc688df6900c -
Branch / Tag:
refs/tags/v1.0.7 - Owner: https://github.com/merlijntishauser
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0217d6b50e638c2d41b67a5097efbc688df6900c -
Trigger Event:
push
-
Statement type: