Skip to main content

Python library for UniFi network topology discovery and SVG rendering

Project description

unifi-topology

CI PyPI Python License: MIT

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 controller
  • fetch_clients(config) -- Fetch active clients
  • fetch_networks(config) -- Fetch network/VLAN configuration
  • resolve_hostnames(ips, dns_server) -- Reverse DNS resolution

Model

  • normalize_devices(raw) -- Convert raw API data to Device objects
  • build_topology(devices, ...) -- Build topology graph (TopologyResult with 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 diagram
  • render_svg_isometric(devices, edges, theme, options, ...) -- Isometric 3D-style SVG
  • render_dual(devices, edges, themes, options, ...) -- Dual light/dark theme SVG
  • resolve_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

unifi_topology-1.0.3.tar.gz (314.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unifi_topology-1.0.3-py3-none-any.whl (347.5 kB view details)

Uploaded Python 3

File details

Details for the file unifi_topology-1.0.3.tar.gz.

File metadata

  • Download URL: unifi_topology-1.0.3.tar.gz
  • Upload date:
  • Size: 314.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for unifi_topology-1.0.3.tar.gz
Algorithm Hash digest
SHA256 2b22d954926f6c36aa456acdd7b2a6b64e07b0bb162092133501ed38e4da4929
MD5 9b1e0fc50912f5ddc215d6383fe4efdb
BLAKE2b-256 757aab9979b7e48d37f1dc8d10022f88750264b3ff09d086830cc93721cbef46

See more details on using hashes here.

Provenance

The following attestation bundles were made for unifi_topology-1.0.3.tar.gz:

Publisher: publish.yml on merlijntishauser/unifi-topology

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file unifi_topology-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: unifi_topology-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 347.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for unifi_topology-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8fdf347fc9e71a106ffef9ce026f34f7f36ce2d7932c069a2afc2dee1d3bdd3f
MD5 9078d3676ae1caabd2fd745cb9d54bda
BLAKE2b-256 1c06b7ec356706e45068a3e36da787e6b9475b7b47f536a83a08f1b7643f6f95

See more details on using hashes here.

Provenance

The following attestation bundles were made for unifi_topology-1.0.3-py3-none-any.whl:

Publisher: publish.yml on merlijntishauser/unifi-topology

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page