Network topology visualization and analysis tool with comprehensive data validation
Project description
Netwlens - Network Topology Visualization Tool
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
--siteparameter overridesSITE_NAMEenvironment 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
DataCollectorandDataVisualizerclasses - Comprehensive Validation: Dedicated
DataValidatorclass 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 clientloguru>=0.6.0- Logginggraphviz>=0.20.0- Graph visualizationpython-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
๐ License
MIT License
Project details
Release history Release notifications | RSS feed
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cdcd4a27fe2503725af6a9e67851185f74f8ce9e26b808be4b1be4de2137837b
|
|
| MD5 |
d8d4334c1fcbdc4bf2504601672d7ba5
|
|
| BLAKE2b-256 |
6ae532838debd8962b9cfcb94440203bbdb6f1a2f0585f722953c14aaa7f9f31
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d19b6ef68c6d9bcd1fe4dda4db6ce53f9f2375f100ef4d84089e6f722194696
|
|
| MD5 |
5b9248f3a3fa091c98d8acc863319006
|
|
| BLAKE2b-256 |
a75683bdb711e02781fe88163521ebb8c78c3b30fc27ca3c683017119d2fadc8
|