topolib 0.8.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. topolib-0.8.0/LICENSE +22 -0
  2. topolib-0.8.0/PKG-INFO +148 -0
  3. topolib-0.8.0/README.md +115 -0
  4. topolib-0.8.0/pyproject.toml +49 -0
  5. topolib-0.8.0/topolib/__init__.py +4 -0
  6. topolib-0.8.0/topolib/analysis/__init__.py +4 -0
  7. topolib-0.8.0/topolib/analysis/metrics.py +80 -0
  8. topolib-0.8.0/topolib/analysis/traffic_matrix.py +344 -0
  9. topolib-0.8.0/topolib/assets/AMRES.json +1265 -0
  10. topolib-0.8.0/topolib/assets/Abilene.json +285 -0
  11. topolib-0.8.0/topolib/assets/Bell_canada.json +925 -0
  12. topolib-0.8.0/topolib/assets/Brazil.json +699 -0
  13. topolib-0.8.0/topolib/assets/CESNET.json +657 -0
  14. topolib-0.8.0/topolib/assets/CORONET.json +1957 -0
  15. topolib-0.8.0/topolib/assets/China.json +1135 -0
  16. topolib-0.8.0/topolib/assets/DT-14.json +470 -0
  17. topolib-0.8.0/topolib/assets/DT-17.json +525 -0
  18. topolib-0.8.0/topolib/assets/DT-50.json +1515 -0
  19. topolib-0.8.0/topolib/assets/ES-30.json +967 -0
  20. topolib-0.8.0/topolib/assets/EURO-16.json +455 -0
  21. topolib-0.8.0/topolib/assets/FR-43.json +1277 -0
  22. topolib-0.8.0/topolib/assets/FUNET.json +317 -0
  23. topolib-0.8.0/topolib/assets/GCN-BG.json +855 -0
  24. topolib-0.8.0/topolib/assets/GRNET.json +1717 -0
  25. topolib-0.8.0/topolib/assets/HyperOne.json +255 -0
  26. topolib-0.8.0/topolib/assets/IT-21.json +649 -0
  27. topolib-0.8.0/topolib/assets/India.json +517 -0
  28. topolib-0.8.0/topolib/assets/JPN-12.json +331 -0
  29. topolib-0.8.0/topolib/assets/KOREN.json +287 -0
  30. topolib-0.8.0/topolib/assets/NORDUNet.json +783 -0
  31. topolib-0.8.0/topolib/assets/NSFNet.json +399 -0
  32. topolib-0.8.0/topolib/assets/PANEURO.json +757 -0
  33. topolib-0.8.0/topolib/assets/PAVLOV.json +465 -0
  34. topolib-0.8.0/topolib/assets/PLN-12.json +343 -0
  35. topolib-0.8.0/topolib/assets/SANReN.json +161 -0
  36. topolib-0.8.0/topolib/assets/SERBIA-MONTENEGRO.json +139 -0
  37. topolib-0.8.0/topolib/assets/Telefonica-21.json +637 -0
  38. topolib-0.8.0/topolib/assets/Turk_Telekom.json +551 -0
  39. topolib-0.8.0/topolib/assets/UKNet.json +685 -0
  40. topolib-0.8.0/topolib/assets/Vega_Telecom.json +819 -0
  41. topolib-0.8.0/topolib/elements/__init__.py +5 -0
  42. topolib-0.8.0/topolib/elements/link.py +121 -0
  43. topolib-0.8.0/topolib/elements/node.py +230 -0
  44. topolib-0.8.0/topolib/topology/__init__.py +4 -0
  45. topolib-0.8.0/topolib/topology/path.py +84 -0
  46. topolib-0.8.0/topolib/topology/topology.py +469 -0
  47. topolib-0.8.0/topolib/visualization/__init__.py +1 -0
  48. topolib-0.8.0/topolib/visualization/_qt_screenshot.py +103 -0
  49. topolib-0.8.0/topolib/visualization/_qt_window.py +78 -0
  50. topolib-0.8.0/topolib/visualization/_templates.py +101 -0
  51. topolib-0.8.0/topolib/visualization/mapview.py +316 -0
topolib-0.8.0/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+
2
+ MIT License
3
+
4
+ Copyright (c) 2025 Danilo Bórquez-Paredes
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
topolib-0.8.0/PKG-INFO ADDED
@@ -0,0 +1,148 @@
1
+ Metadata-Version: 2.4
2
+ Name: topolib
3
+ Version: 0.8.0
4
+ Summary: A compact Python library for modeling, analyzing, and visualizing optical network topologies.
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Keywords: network,topology,optical,analysis,visualization
8
+ Author: Danilo Bórquez-Paredes
9
+ Author-email: danilo.borquez.p@uai.cl
10
+ Requires-Python: >=3.10
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Dist: PyQt6 (>=6.0)
23
+ Requires-Dist: PyQt6-WebEngine (>=6.0)
24
+ Requires-Dist: folium (>=0.14.0)
25
+ Requires-Dist: jsonschema (>=4.0)
26
+ Requires-Dist: networkx (>=2.6)
27
+ Requires-Dist: numpy (>=1.21)
28
+ Project-URL: Documentation, https://topolib.readthedocs.io/
29
+ Project-URL: Homepage, https://gitlab.com/DaniloBorquez/topolib
30
+ Project-URL: Repository, https://gitlab.com/DaniloBorquez/topolib
31
+ Description-Content-Type: text/markdown
32
+
33
+ # Topolib 🚀
34
+
35
+ [![Python Version](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/)
36
+ [![License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](LICENSE)
37
+ [![Issues](https://img.shields.io/badge/issues-on%20GitLab-blue.svg)](https://gitlab.com/DaniloBorquez/topolib/-/issues)
38
+ [![Develop coverage](https://gitlab.com/DaniloBorquez/topolib/badges/develop/coverage.svg)](https://gitlab.com/DaniloBorquez/topolib/-/pipelines?ref=develop)
39
+ [![Release coverage](https://gitlab.com/DaniloBorquez/topolib/badges/release/coverage.svg)](https://gitlab.com/DaniloBorquez/topolib/-/pipelines?ref=release)
40
+ [![Documentation Status](https://readthedocs.org/projects/topolib/badge/?version=latest)](https://topolib.readthedocs.io/en/latest/?badge=latest)
41
+
42
+ > **Topolib** is a compact, modular Python library for modeling, analyzing, and visualizing optical network topologies.
43
+ > **Goal:** Provide researchers and engineers with a simple, extensible toolkit for working with nodes, links, metrics, and map-based visualizations.
44
+ >
45
+ > 🌐 **Model** | 📊 **Analyze** | 🗺️ **Visualize** | 🧩 **Extend**
46
+
47
+ ---
48
+
49
+ ## 📂 Examples
50
+
51
+
52
+ Explore ready-to-run usage examples in the [`examples/`](examples/) folder!
53
+
54
+ - [Show topology on a map](examples/show_topology_in_map.py) 🗺️
55
+ - [Show default topology in map](examples/show_default_topology_in_map.py) 🗺️
56
+ - [Export topology as PNG](examples/export_topology_png.py) 🖼️
57
+ - [Export topology to CSV and JSON](examples/export_csv_json.py) 📄
58
+ - [Export topology and k-shortest paths for FlexNetSim](examples/export_flexnetsim.py) 🔀
59
+ - [Generate traffic demand matrices](examples/traffic_matrices.py) 📊
60
+
61
+ ---
62
+
63
+ ## 🧭 Overview
64
+
65
+ Topolib is organized into four main modules:
66
+
67
+ - 🧱 **Elements:** `Node`, `Link` — basic building blocks
68
+ - 🕸️ **Topology:** `Topology`, `Path` — manage nodes, links, paths, and adjacency
69
+ - 📈 **Analysis:** `Metrics`, `TrafficMatrix` — compute node degree, link stats, connection matrices, and traffic demand matrices
70
+ - 🖼️ **Visualization:** `MapView` — interactive maps with Folium and PyQt6, clean PNG exports
71
+
72
+ ---
73
+
74
+ ## ✨ Features
75
+
76
+ - Modular, extensible design
77
+ - Easy-to-use classes for nodes, links, and paths
78
+ - Built-in metrics and analysis helpers
79
+ - Traffic demand matrix generation with three models (gravitational, DC/IXP, distribution probability)
80
+ - Returns NumPy arrays for efficient mathematical operations
81
+ - Interactive map visualization with Folium and PyQt6
82
+ - Clean PNG export without external dependencies (no Selenium required)
83
+ - Resource caching for faster map rendering
84
+ - JSON import/export and interoperability
85
+ - Ready for Sphinx, Read the Docs, and PyPI
86
+
87
+ ---
88
+
89
+ ## ⚡ Quickstart
90
+
91
+ ```bash
92
+ python -m venv .venv
93
+ source .venv/bin/activate
94
+ pip install -U pip
95
+ pip install topolib
96
+ ```
97
+
98
+ ---
99
+
100
+ ## 📚 Documentation
101
+
102
+ Full documentation: [https://topolib.readthedocs.io/](https://topolib.readthedocs.io/)
103
+
104
+ ---
105
+
106
+ ## 📝 Basic usage
107
+
108
+ ### Creating a topology
109
+
110
+ ```python
111
+ from topolib.elements.node import Node
112
+ from topolib.topology.topology import Topology
113
+
114
+ n1 = Node(1, 'A', 10.0, 20.0)
115
+ n2 = Node(2, 'B', 11.0, 21.0)
116
+ topo = Topology(nodes=[n1, n2])
117
+ # Add links, compute metrics, visualize, etc.
118
+ ```
119
+
120
+ ### Generating traffic matrices
121
+
122
+ ```python
123
+ from topolib.topology import Topology
124
+ from topolib.analysis import TrafficMatrix
125
+
126
+ # Load a topology
127
+ topo = Topology.load_default_topology("DT-14")
128
+
129
+ # Generate traffic matrix using gravitational model
130
+ matrix = TrafficMatrix.gravitational(topo, rate=0.015)
131
+ # Returns NumPy array: matrix[i, j] = traffic from node i to j (Gbps)
132
+
133
+ # Export to CSV
134
+ TrafficMatrix.to_csv(matrix, topo, "traffic_matrix.csv")
135
+ ```
136
+
137
+ ---
138
+
139
+ ## 🛠️ Development
140
+
141
+ See [`CONTRIBUTING.md`](CONTRIBUTING.md) for development guidelines, commit message rules, and pre-commit setup.
142
+
143
+ ---
144
+
145
+ ## 📄 License
146
+
147
+ MIT — see [`LICENSE`](LICENSE) for details.
148
+
@@ -0,0 +1,115 @@
1
+ # Topolib 🚀
2
+
3
+ [![Python Version](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/)
4
+ [![License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](LICENSE)
5
+ [![Issues](https://img.shields.io/badge/issues-on%20GitLab-blue.svg)](https://gitlab.com/DaniloBorquez/topolib/-/issues)
6
+ [![Develop coverage](https://gitlab.com/DaniloBorquez/topolib/badges/develop/coverage.svg)](https://gitlab.com/DaniloBorquez/topolib/-/pipelines?ref=develop)
7
+ [![Release coverage](https://gitlab.com/DaniloBorquez/topolib/badges/release/coverage.svg)](https://gitlab.com/DaniloBorquez/topolib/-/pipelines?ref=release)
8
+ [![Documentation Status](https://readthedocs.org/projects/topolib/badge/?version=latest)](https://topolib.readthedocs.io/en/latest/?badge=latest)
9
+
10
+ > **Topolib** is a compact, modular Python library for modeling, analyzing, and visualizing optical network topologies.
11
+ > **Goal:** Provide researchers and engineers with a simple, extensible toolkit for working with nodes, links, metrics, and map-based visualizations.
12
+ >
13
+ > 🌐 **Model** | 📊 **Analyze** | 🗺️ **Visualize** | 🧩 **Extend**
14
+
15
+ ---
16
+
17
+ ## 📂 Examples
18
+
19
+
20
+ Explore ready-to-run usage examples in the [`examples/`](examples/) folder!
21
+
22
+ - [Show topology on a map](examples/show_topology_in_map.py) 🗺️
23
+ - [Show default topology in map](examples/show_default_topology_in_map.py) 🗺️
24
+ - [Export topology as PNG](examples/export_topology_png.py) 🖼️
25
+ - [Export topology to CSV and JSON](examples/export_csv_json.py) 📄
26
+ - [Export topology and k-shortest paths for FlexNetSim](examples/export_flexnetsim.py) 🔀
27
+ - [Generate traffic demand matrices](examples/traffic_matrices.py) 📊
28
+
29
+ ---
30
+
31
+ ## 🧭 Overview
32
+
33
+ Topolib is organized into four main modules:
34
+
35
+ - 🧱 **Elements:** `Node`, `Link` — basic building blocks
36
+ - 🕸️ **Topology:** `Topology`, `Path` — manage nodes, links, paths, and adjacency
37
+ - 📈 **Analysis:** `Metrics`, `TrafficMatrix` — compute node degree, link stats, connection matrices, and traffic demand matrices
38
+ - 🖼️ **Visualization:** `MapView` — interactive maps with Folium and PyQt6, clean PNG exports
39
+
40
+ ---
41
+
42
+ ## ✨ Features
43
+
44
+ - Modular, extensible design
45
+ - Easy-to-use classes for nodes, links, and paths
46
+ - Built-in metrics and analysis helpers
47
+ - Traffic demand matrix generation with three models (gravitational, DC/IXP, distribution probability)
48
+ - Returns NumPy arrays for efficient mathematical operations
49
+ - Interactive map visualization with Folium and PyQt6
50
+ - Clean PNG export without external dependencies (no Selenium required)
51
+ - Resource caching for faster map rendering
52
+ - JSON import/export and interoperability
53
+ - Ready for Sphinx, Read the Docs, and PyPI
54
+
55
+ ---
56
+
57
+ ## ⚡ Quickstart
58
+
59
+ ```bash
60
+ python -m venv .venv
61
+ source .venv/bin/activate
62
+ pip install -U pip
63
+ pip install topolib
64
+ ```
65
+
66
+ ---
67
+
68
+ ## 📚 Documentation
69
+
70
+ Full documentation: [https://topolib.readthedocs.io/](https://topolib.readthedocs.io/)
71
+
72
+ ---
73
+
74
+ ## 📝 Basic usage
75
+
76
+ ### Creating a topology
77
+
78
+ ```python
79
+ from topolib.elements.node import Node
80
+ from topolib.topology.topology import Topology
81
+
82
+ n1 = Node(1, 'A', 10.0, 20.0)
83
+ n2 = Node(2, 'B', 11.0, 21.0)
84
+ topo = Topology(nodes=[n1, n2])
85
+ # Add links, compute metrics, visualize, etc.
86
+ ```
87
+
88
+ ### Generating traffic matrices
89
+
90
+ ```python
91
+ from topolib.topology import Topology
92
+ from topolib.analysis import TrafficMatrix
93
+
94
+ # Load a topology
95
+ topo = Topology.load_default_topology("DT-14")
96
+
97
+ # Generate traffic matrix using gravitational model
98
+ matrix = TrafficMatrix.gravitational(topo, rate=0.015)
99
+ # Returns NumPy array: matrix[i, j] = traffic from node i to j (Gbps)
100
+
101
+ # Export to CSV
102
+ TrafficMatrix.to_csv(matrix, topo, "traffic_matrix.csv")
103
+ ```
104
+
105
+ ---
106
+
107
+ ## 🛠️ Development
108
+
109
+ See [`CONTRIBUTING.md`](CONTRIBUTING.md) for development guidelines, commit message rules, and pre-commit setup.
110
+
111
+ ---
112
+
113
+ ## 📄 License
114
+
115
+ MIT — see [`LICENSE`](LICENSE) for details.
@@ -0,0 +1,49 @@
1
+
2
+ [tool.poetry]
3
+ name = "topolib"
4
+ # Poetry requires a version field, but poetry-dynamic-versioning will override it
5
+ version = "0.8.0"
6
+ description = "A compact Python library for modeling, analyzing, and visualizing optical network topologies."
7
+ authors = ["Danilo Bórquez-Paredes <danilo.borquez.p@uai.cl>"]
8
+ license = "MIT"
9
+ readme = "README.md"
10
+ repository = "https://gitlab.com/DaniloBorquez/topolib"
11
+ documentation = "https://topolib.readthedocs.io/"
12
+ homepage = "https://gitlab.com/DaniloBorquez/topolib"
13
+ keywords = ["network", "topology", "optical", "analysis", "visualization"]
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Operating System :: OS Independent",
17
+ "Intended Audience :: Science/Research",
18
+ "Topic :: Scientific/Engineering :: Information Analysis",
19
+ "Topic :: Software Development :: Libraries :: Python Modules"
20
+ ]
21
+ packages = [
22
+ { include = "topolib" }
23
+ ]
24
+
25
+ [tool.poetry.dependencies]
26
+ python = ">=3.10"
27
+ numpy = ">=1.21"
28
+ networkx = ">=2.6"
29
+ folium = ">=0.14.0"
30
+ jsonschema = ">=4.0"
31
+ PyQt6 = ">=6.0"
32
+ PyQt6-WebEngine = ">=6.0"
33
+
34
+ [tool.poetry.group.dev.dependencies]
35
+ pytest = "*"
36
+ pytest-cov = "*"
37
+ PyQt6 = ">=6.0"
38
+ PyQt6-WebEngine = ">=6.0"
39
+
40
+ [build-system]
41
+ requires = ["poetry-core>=1.0.0"]
42
+ build-backend = "poetry.core.masonry.api"
43
+
44
+ [tool.poetry-dynamic-versioning]
45
+ enable = false
46
+ vcs = "git"
47
+ style = "pep440"
48
+ pattern = '(?P<base>\d+\.\d+\.\d+)'
49
+
@@ -0,0 +1,4 @@
1
+ try:
2
+ from ._version import __version__
3
+ except ImportError:
4
+ __version__ = "unknown"
@@ -0,0 +1,4 @@
1
+ from .metrics import Metrics
2
+ from .traffic_matrix import TrafficMatrix
3
+
4
+ __all__ = ["Metrics", "TrafficMatrix"]
@@ -0,0 +1,80 @@
1
+ """
2
+ Metrics module for network topology analysis.
3
+ """
4
+
5
+ from typing import List, Dict, Optional
6
+
7
+
8
+ from topolib.topology import Topology
9
+
10
+
11
+ class Metrics:
12
+ """
13
+ Provides static methods for computing metrics on network topologies.
14
+
15
+ All methods receive a Topology instance.
16
+
17
+ Methods
18
+ -------
19
+ node_degree(topology)
20
+ Calculates the degree of each node.
21
+ link_length_stats(topology)
22
+ Calculates statistics (min, max, avg) of link lengths.
23
+ connection_matrix(topology)
24
+ Builds the adjacency matrix.
25
+ """
26
+
27
+ @staticmethod
28
+ def node_degree(topology: "Topology") -> Dict[int, int]:
29
+ """
30
+ Calculates the degree of each node in the topology.
31
+
32
+ :param topology: Instance of topolib.topology.topology.Topology.
33
+ :type topology: topolib.topology.topology.Topology
34
+ :return: Dictionary {node_id: degree}
35
+ :rtype: dict[int, int]
36
+ """
37
+ degree = {n.id: 0 for n in topology.nodes}
38
+ for link in topology.links:
39
+ degree[link.source.id] += 1
40
+ degree[link.target.id] += 1
41
+ return degree
42
+
43
+ @staticmethod
44
+ def link_length_stats(topology: "Topology") -> Dict[str, Optional[float]]:
45
+ """
46
+ Calculates the minimum, maximum, and average link lengths.
47
+
48
+ :param topology: Instance of topolib.topology.topology.Topology.
49
+ :type topology: topolib.topology.topology.Topology
50
+ :return: Dictionary with keys 'min', 'max', 'avg'.
51
+ :rtype: dict[str, float | None]
52
+ """
53
+ lengths = [l.length for l in topology.links]
54
+ if not lengths:
55
+ return {"min": None, "max": None, "avg": None}
56
+ return {
57
+ "min": min(lengths),
58
+ "max": max(lengths),
59
+ "avg": sum(lengths) / len(lengths),
60
+ }
61
+
62
+ @staticmethod
63
+ def connection_matrix(topology: "Topology") -> List[List[int]]:
64
+ """
65
+ Builds the adjacency matrix of the topology.
66
+
67
+ :param topology: Instance of topolib.topology.topology.Topology.
68
+ :type topology: topolib.topology.topology.Topology
69
+ :return: Adjacency matrix (1 if connected, 0 otherwise).
70
+ :rtype: list[list[int]]
71
+ """
72
+ id_to_idx = {n.id: i for i, n in enumerate(topology.nodes)}
73
+ size = len(topology.nodes)
74
+ matrix = [[0] * size for _ in range(size)]
75
+ for link in topology.links:
76
+ i = id_to_idx[link.source.id]
77
+ j = id_to_idx[link.target.id]
78
+ matrix[i][j] = 1
79
+ matrix[j][i] = 1
80
+ return matrix