Skip to main content

Network topology visualization and analysis tool with comprehensive data validation

Project description

Netwlens - Network Topology Visualization Tool

PyPI version Python 3.11+ License: MIT IP Fabric

A Python package for network topology visualization and analysis that integrates with IP Fabric. Features comprehensive data validation, automatic root device selection, intelligent topology discovery, and robust error handling with clear feedback.

๐Ÿ—๏ธ Development Setup

Prerequisites

  • Python 3.11 or higher
  • IP Fabric instance with API access
  • Graphviz (for visualization)

Installation (end users)

# From PyPI (recommended)
pip install netwlens
# or with uv
uv pip install netwlens

Installation for Development

# Clone the repository
git clone https://gitlab.com/ip-fabric/integrations/netwlens.git
cd netwlens

# Sync the project + dev dependencies into a local .venv (uv-managed)
uv sync --group dev

# Or with pip (creates .venv yourself)
python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"   # see [dependency-groups] in pyproject.toml

# Install Graphviz
# macOS: brew install graphviz
# Ubuntu/Debian: sudo apt-get install graphviz
# Windows: Download from https://graphviz.org/download/

Environment Configuration

Create a .env file in the project root:

IPF_URL=https://your-ipfabric-instance.com
IPF_TOKEN=your-api-token
SNAPSHOT_ID=your-snapshot-id # or $last
SITE_NAME=your-site-name # Optional: default site for data collection
# Optional: IPF_VERIFY=false  # for self-signed certificates

Development Workflow

# Activate the uv-managed virtual environment
. .venv/bin/activate

# Run the CLI tool directly from source
python -m netwlens.cli

# Or run the standalone scripts
python collect_data.py
python visualize_topology.py

Quick Test Run

# Test site-specific data collection
netwlens collect --site London-3X --protocol cdp --output test-site

# Test all inventory data collection
netwlens collect --protocol cdp --output test-all

# Test collection using SITE_NAME from .env (NEW!)
netwlens collect --protocol cdp --output test-env

# Test visualization with automatic root selection
netwlens visualize --input netwlens_data/test-site

# Test visualization with manual root selection
netwlens visualize --input netwlens_data/test-site --root s3xasw02

๐Ÿ“ Project Structure

netwlens/
โ”œโ”€โ”€ netwlens/                     # Main package
โ”‚   โ”œโ”€โ”€ __init__.py              # Package exports (DataCollector, TopologyVisualizer)
โ”‚   โ”œโ”€โ”€ cli.py                   # CLI interface
โ”‚   โ”œโ”€โ”€ data_collector.py        # DataCollector class
โ”‚   โ”œโ”€โ”€ topology_visualizer.py   # TopologyVisualizer class
โ”‚   โ”œโ”€โ”€ docs/                    # Package documentation
โ”‚   โ”‚   โ””โ”€โ”€ topology_graphviz.md # Detailed API docs
โ”‚   โ””โ”€โ”€ src/                     # Core modules
โ”‚       โ”œโ”€โ”€ extract_ipfabric_data.py # IP Fabric data extraction
โ”‚       โ”œโ”€โ”€ topology_graphviz.py     # Graphviz visualization engine
โ”‚       โ””โ”€โ”€ validator.py             # Comprehensive validation system
โ”œโ”€โ”€ collect_data.py              # Standalone data collection script
โ”œโ”€โ”€ visualize_topology.py        # Standalone visualization script
โ”œโ”€โ”€ pyproject.toml               # Package configuration (PEP 621 + hatchling)
โ”œโ”€โ”€ uv.lock                      # Resolved dependency lockfile
โ””โ”€โ”€ README.md                    # This file

Output Data Structure

When users run the tool, data is organized as:

netwlens_data/
โ”œโ”€โ”€ mynetwork/                    # Data collection output
โ”‚   โ”œโ”€โ”€ inventory.json            # Device inventory
โ”‚   โ”œโ”€โ”€ connections_raw.json      # Raw connections from IP Fabric
โ”‚   โ”œโ”€โ”€ connections_normalized.json # Processed connections (enriched + deduplicated)
โ”‚   โ””โ”€โ”€ topology/                 # Visualization output
โ”‚       โ”œโ”€โ”€ topology_hierarchical.svg
โ”‚       โ””โ”€โ”€ view_svg_topology.html

๐Ÿ—๏ธ Architecture

Core Classes

DataCollector (netwlens/data_collector.py)

  • High-level interface for IP Fabric data collection with comprehensive validation
  • IP Fabric connection validation (detects VPN/connectivity issues)
  • Site name validation with helpful error messages
  • Parameter precedence handling (CLI overrides ENV variables)
  • Wraps the core extraction functions from src/extract_ipfabric_data.py
  • Handles output directory management and data processing pipeline

TopologyVisualizer (netwlens/topology_visualizer.py)

  • High-level interface for topology visualization
  • Wraps the Graphviz engine from src/topology_graphviz.py
  • Manages output formats and layout algorithms

๐Ÿ›ก๏ธ Enhanced Validation System

Netwlens includes comprehensive validation to prevent silent failures and provide clear feedback:

Connection Validation

  • IP Fabric connectivity check - Detects VPN disconnections or API issues
  • Early failure detection - Validates connection before data collection begins
  • Clear error messages - Actionable feedback for connection problems

Site Validation

  • Site existence verification - Checks if specified site exists in IP Fabric
  • Available sites listing - Shows valid site names when validation fails
  • Parameter precedence - CLI --site parameter overrides SITE_NAME environment variable

Data Validation

  • Empty data detection - Validates collected inventory and connections
  • Actionable error messages - Clear guidance when data collection fails
  • Success confirmation - Visible feedback when validation passes

Error Handling

  • Clean error output - Minimal, user-friendly error messages
  • Fast failure - Stops processing early when validation fails
  • No verbose tracebacks - Clean exit with helpful error information

API Design

from netwlens import DataCollector, TopologyVisualizer

# Collect site-specific data with validation
collector = DataCollector()
data_dir = collector.collect_data(
    site="London-3X",  # Automatically validated against IP Fabric
    protocol="cdp",
    output="my-network"
)

# Or collect all inventory data
data_dir = collector.collect_data(
    site=None,  # None = all inventory
    protocol="cdp",
    output="all-network"
)

# Create visualization with automatic root selection
visualizer = TopologyVisualizer()
viz_path = visualizer.create_visualization(
    input_dir=data_dir,
    # root_device automatically selected based on connection count
    output_format="svg"
)

# Or specify root device manually
viz_path = visualizer.create_visualization(
    input_dir=data_dir,
    root_device="s3xasw02",
    output_format="svg"
)

CLI Commands

Data Collection with Validation

# Site-specific data collection (validates site exists)
netwlens collect --site London-3X --protocol cdp

# All inventory data collection
netwlens collect --protocol cdp

# Use SITE_NAME from .env file (validates connection and site)
netwlens collect --protocol cdp --output env-site

# Custom output directory
netwlens collect --site London-3X --protocol cdp --output my-site

# Available protocols: cef, cdp, lldp
netwlens collect --site London-3X --protocol lldp

Visualization

# Basic visualization with automatic root device selection
netwlens visualize --input netwlens_data/London-3X

# With manual root device specification
netwlens visualize --input netwlens_data/London-3X --root s3xasw02

# Different formats and layouts
netwlens visualize --input netwlens_data/London-3X --output_format png --layout tree

Standalone Scripts

# Site-specific collection (with validation)
python collect_data.py --site London-3X --protocol cdp

# All inventory collection
python collect_data.py --protocol cdp

# Collection using SITE_NAME from environment
python collect_data.py --protocol cdp --output env-data

# Visualization with auto root selection
python visualize_topology.py --input netwlens_data/London-3X

# Visualization with manual root selection
python visualize_topology.py --input netwlens_data/London-3X --root s3xasw02

๐Ÿ› ๏ธ Features

Data Collection with Validation

  • IP Fabric Integration: Direct API connection to extract inventory and connections
  • Connection Validation: Automatic IP Fabric connectivity check before data collection
  • Site Validation: Verifies site names exist in IP Fabric with helpful error messages
  • Parameter Precedence: CLI parameters override environment variables (SITE_NAME)
  • Clean Error Handling: Minimal, actionable error messages without verbose tracebacks
  • Protocol Support: CDP, LLDP, and CEF protocols
  • Flexible Site Filtering: Extract data for specific sites or all inventory
  • Data Processing: Automatic enrichment and normalization of connection data
  • JSON Export: Clean, structured data files for analysis
  • Comprehensive Data Validation: Multi-layer validation ensures data quality (NEW!)
  • Backward Compatibility: Preserves existing API while adding new capabilities

Visualization

  • Automatic Root Selection: Intelligently selects device with most connections as root
  • Data Validation: Automatic validation before visualization with detailed error reporting (NEW!)
  • Quality Assurance: Connectivity analysis, device relationship validation, protocol consistency checks (NEW!)
  • Clean Diagrams: Orthogonal layouts with 90-degree connections only
  • Multiple Formats: SVG, PNG, and PDF output formats
  • Interactive Viewers: HTML viewers for easy sharing and presentation
  • Hierarchical Layouts: Root-based topology with proper device positioning
  • Color Coding: Device types distinguished by colors and shapes
  • Interface Labels: Clear labeling of connection interfaces
  • Smart Logging: Detailed connection analysis and validation summary

Architecture

  • Object-Oriented Design: Clean DataCollector and DataVisualizer classes
  • Comprehensive Validation: Dedicated DataValidator class with multi-layer validation (NEW!)
  • Modular Structure: Separate concerns for data collection, validation, and visualization
  • CLI Integration: Modern subcommand-based CLI interface with built-in validation
  • Package Installation: Proper Python package with pip install
  • Extensible: Easy to add new protocols, formats, layouts, and validation rules

๐Ÿ“– API Reference

DataCollector Class

class DataCollector:
    def collect_site_data(site: str, protocol: str = "cef", output: str = None) -> str
    def extract_inventory(site: str) -> dict
    def extract_connections(site: str, protocol: str) -> dict
    def get_client_info() -> dict

TopologyVisualizer Class

class TopologyVisualizer:
    def create_topology(input_dir: str, root_device: str = None, format_type: str = "svg") -> str
    def create_hierarchical_topology(input_dir: str, root_device: str) -> str
    def create_tree_topology(input_dir: str) -> str
    def get_available_formats() -> list
    def get_available_layouts() -> list

๐Ÿ”ง Requirements

  • Python: 3.11+
  • Dependencies:
    • ipfabric>=7.0.0 - IP Fabric API client
    • loguru>=0.6.0 - Logging
    • graphviz>=0.20.0 - Graph visualization
    • python-dotenv>=1.0.0 - Environment variables
  • System: Graphviz binaries installed
  • Access: IP Fabric instance with API token
  • Package Management: Poetry (recommended) or pip

๐ŸŽจ Examples

Complete Workflow

# 1. Collect data for London-3X site using CDP
netwlens collect --site London-3X --protocol cdp --output london-network

# 2. Create hierarchical visualization with s3xasw02 as root
netwlens visualize --input netwlens_data/london-network --root s3xasw02 --output_format svg

# Output files:
# - netwlens_data/london-network/inventory.json
# - netwlens_data/london-network/connections_*.json
# - netwlens_data/london-network/topology/topology_hierarchical.svg
# - netwlens_data/london-network/topology/view_svg_topology.html

Python Integration

from netwlens import DataCollector, DataVisualizer
import os

# Collect data for multiple sites
collector = DataCollector()
sites = ["London-3X", "Paris-2X", "Berlin-1X"]

for site in sites:
    print(f"Collecting data for {site}...")
    data_dir = collector.collect_site_data(
        site=site,
        protocol="cdp",
        output=site.lower()
    )

    # Create visualization
    visualizer = DataVisualizer()
    viz_path = visualizer.create_topology(
        input_dir=data_dir,
        format_type="svg"
    )
    print(f"Visualization saved: {viz_path}")

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

๐Ÿ‘จโ€๐Ÿ’ป Author

Milan Zapletal

๐Ÿ“„ License

MIT License

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

netwlens-1.3.3.tar.gz (599.8 kB view details)

Uploaded Source

Built Distribution

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

netwlens-1.3.3-py3-none-any.whl (606.1 kB view details)

Uploaded Python 3

File details

Details for the file netwlens-1.3.3.tar.gz.

File metadata

  • Download URL: netwlens-1.3.3.tar.gz
  • Upload date:
  • Size: 599.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for netwlens-1.3.3.tar.gz
Algorithm Hash digest
SHA256 cdcd4a27fe2503725af6a9e67851185f74f8ce9e26b808be4b1be4de2137837b
MD5 d8d4334c1fcbdc4bf2504601672d7ba5
BLAKE2b-256 6ae532838debd8962b9cfcb94440203bbdb6f1a2f0585f722953c14aaa7f9f31

See more details on using hashes here.

File details

Details for the file netwlens-1.3.3-py3-none-any.whl.

File metadata

  • Download URL: netwlens-1.3.3-py3-none-any.whl
  • Upload date:
  • Size: 606.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for netwlens-1.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8d19b6ef68c6d9bcd1fe4dda4db6ce53f9f2375f100ef4d84089e6f722194696
MD5 5b9248f3a3fa091c98d8acc863319006
BLAKE2b-256 a75683bdb711e02781fe88163521ebb8c78c3b30fc27ca3c683017119d2fadc8

See more details on using hashes here.

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