Topology Validator
Validate network topologies for security design flaws — with an interactive PBQ-style simulator.
A Python tool that reads network topologies (JSON or plain text) and flags common
security design flaws — databases exposed to the DMZ, missing firewall layers,
single points of failure, and more. Includes a --interactive mode that acts
like a CompTIA/Cisco-style PBQ: build a topology command by command, validate
on demand, and watch your security score change.
Features
- 📄 Two input formats — JSON (structured) or plain text (PBQ-style)
- 🛡️ Six security rules — edge checks + BFS-based path analysis
- 📊 Security score — 0–100 with letter grade (A–F)
- 🖼️ Visualization — color-coded PNG of the topology
- 📤 Multiple report formats — terminal, JSON, self-contained HTML
- ⚡ Interactive REPL — build, modify, validate topologies live
- 🧪 Tested — unit tests for parsers, rules, and scoring
Installation
From PyPI
pip install toposec
This installs a topology-validator command on your PATH.
Quick start
Validate a JSON topology:
topology-validator secure.json
Output:
============================================================
NETWORK TOPOLOGY SECURITY REPORT
============================================================
Total findings: 1
MEDIUM : 1
Security Score: 96 / 100 (Grade: A)
...
Input formats
JSON
{
"devices": [
{"id": "internet", "type": "internet", "zone": "external"},
{"id": "fw1", "type": "firewall", "zone": "dmz"},
{"id": "web1", "type": "web_server", "zone": "dmz"},
{"id": "fw2", "type": "firewall", "zone": "internal"},
{"id": "app1", "type": "app_server", "zone": "internal"},
{"id": "db1", "type": "database", "zone": "internal"}
],
"connections": [
{"from": "internet", "to": "fw1"},
{"from": "fw1", "to": "web1"},
{"from": "web1", "to": "fw2"},
{"from": "fw2", "to": "app1"},
{"from": "app1", "to": "db1"}
]
}
Text (PBQ-style)
device internet internet external
device fw1 firewall dmz
device web1 web_server dmz
device fw2 firewall internal
device app1 app_server internal
device db1 database internal
internet -- fw1
fw1 -- web1
web1 -- fw2
fw2 -- app1
app1 -- db1
Rules
| Rule | What it detects |
|---|---|
rule_database_exposed |
Database directly connected to external/DMZ device |
rule_internet_to_internal |
Direct link between internet and internal zones |
rule_dmz_to_internal |
DMZ host directly connected to internal (no firewall) |
rule_web_to_database |
Web server directly connected to database (missing app tier) |
rule_no_firewall_path |
Any path from internet to DB bypassing all firewalls |
rule_single_point_of_failure |
Devices whose failure disconnects internet from DB |
Scoring
| Severity | Penalty |
|---|---|
| Critical | 25 |
| High | 10 |
| Medium | 4 |
| Low | 1 |
Score = max(0, 100 − total penalties). Grades: A ≥ 90, B ≥ 80, C ≥ 70, D ≥ 60, F < 60.
CLI options
| Flag | Description |
|---|---|
topology_file |
Path to .json or .txt topology |
-i, --interactive |
Launch the PBQ-style REPL |
-v, --visualize |
Render the topology to a PNG |
-f, --format |
text (default), json, or html |
-o, --output |
Output path for json/html reports |
-q, --quiet |
Suppress terminal report; only set exit code |
Exit codes: 0 = clean, 1 = findings present, 2 = error.
Interactive mode
topology-validator -i
> add internet internet external
> add fw1 firewall dmz
> add db1 database internal
> connect internet fw1
> connect fw1 db1
> check
Available commands: add, remove, connect, disconnect, show, check,
score, render, save, load, clear, help, quit.
Examples
Visualize a topology
topology-validator insecure.json --visualize
Generates insecure.png — a color-coded diagram with flagged nodes outlined in red.
Generate an HTML report
topology-validator insecure.json -f html --visualize
Produces a self-contained insecure.report.html with the diagram and findings embedded.
Machine-readable output for CI
topology-validator insecure.json -f json -o report.json || echo "Topology has flaws!"
Development
pip install -e ".[dev]"
pytest
License
MIT — see LICENSE.
Metadata
Release files for toposec 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| toposec-1.0.0.tar.gz | 21.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| toposec-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 42.2 kB
Release files / toposec-1.0.0.tar.gz
| Download URL | toposec-1.0.0.tar.gz |
|---|---|
| Size | 21.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c313e6a81aa661a27949fd9ff61daa13946576b639815921fdd7ca5e09090491
|
|
BLAKE2b-256 checksum How to use checksums |
f2e32f9d785d88f894b6eb96e0bd2978f01f8baeb6fee5df11e24573358ff92b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.
Transparency logRelease files / toposec-1.0.0-py3-none-any.whl
| Download URL | toposec-1.0.0-py3-none-any.whl |
|---|---|
| Size | 20.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e0d7ef917de33b2b4f44ab0ce7e97c4a3a178cc64c3b991f62516dbf24af0cf4
|
|
BLAKE2b-256 checksum How to use checksums |
9c3401c8f52b30510c149b3362ca88092c533ee3f881d1c02502806ae5da73fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.
Transparency log