# Topology Renderer `p4_topology_diagram.py` is an optional Python renderer for P4 server topology. It produces Mermaid, Markdown, AsciiDoc, interactive HTML, and SVG output. For the built-in pure-Go SVG renderer, see the [main README](../README.md#topology). The script runs `p4 servers` and `p4 topology -t 2`, then matches the output. It must be run by a logged-in P4 user with `super` privileges. ## Download Download [p4_topology_diagram.py](https://swarm.workshop.perforce.com/downloads/guest/perforce_software/p4survey/p4_topology_diagram.py). ## Installation The script requires Python 3 and `p4python`: ```bash if ! command -v uv >/dev/null 2>&1; then curl -LsSf "https://astral.sh/uv/install.sh" | sh export PATH="$HOME/.local/bin:$PATH" fi uv python install uv venv .venv source .venv/bin/activate uv pip install p4python ``` `fast-sugiyama` is optional and gives a better automatic SVG layout. Graphviz enables its named layout engines. ```bash uv pip install fast-sugiyama ``` ## Usage Run the script with the current `P4PORT` and `P4USER` environment settings: ```bash ./p4_topology_diagram.py ``` It writes JSON, Mermaid, Markdown, AsciiDoc, HTML, and SVG files by default. To render existing data without contacting P4, use: ```bash ./p4_topology_diagram.py --input-json p4_topology_data.json ``` Use `--layout` to choose `auto`, `sugiyama`, `grid`, or a Graphviz engine such as `dot` or `sfdp`. Run `./p4_topology_diagram.py --help` for the complete option reference. ## Example Produced from [p4_topology.svg](../images/p4_topology.svg): ![Example of a generated SVG diagram that was lightly rearranged and saved](../images/p4_topology.png)