NetGraph can be used in two ways:
- Using the Docker Container with JupyterLab: This is the easiest way to get started with NetGraph, as it provides a pre-configured environment with JupyterLab and all dependencies installed.
- Using the Python Package: If you prefer to use NetGraph in your own Python environment, you can install the package using pip and use it in your Python code.
Prerequisites:
- Docker installed on your machine.
Steps:
-
Clone the repository:
git clone https://github.com/networmix/NetGraph
-
Build the Docker image:
cd NetGraph ./run.sh build -
Start the container with JupyterLab server:
./run.sh run
-
Open the JupyterLab URL in your browser:
http://127.0.0.1:8788/
-
Jupyter will show the content of
notebooksdirectory and you can start using the provided notebooks (e.g., open scenario_dc.ipynb) or create your own.
Note: Docker is instructed to mount the content of NetGraph directory into the /root/env directory inside container, so any changes made to any files in the NetGraph directory will be reflected in the container and vice versa. The ngraph package is installed in the container in editable mode, so you can make changes to the code and leverage them immediately in JupyterLab. But don't forget to restart the JupyterLab kernel after making changes to the package code to see the effects in the running notebook.
To exit the JupyterLab server, press Ctrl+C in the terminal where the server is running. To stop the remaining Docker container, run:
./run.sh stopPrerequisites:
- Python 3.11 or higher installed on your machine.
!!! note
Don't forget to use a virtual environment (e.g., `venv`) to avoid conflicts with other Python packages. See [Python Virtual Environments](https://docs.python.org/3/library/venv.html) for more information.
Steps:
-
Install the package using pip:
pip install ngraph
-
Use the package in your Python code:
from ngraph.scenario import Scenario scenario_yaml = """ network: name: "Two-Tier Clos Fabric" groups: leaf: node_count: 4 name_template: "leaf-{node_num}" spine: node_count: 2 name_template: "spine-{node_num}" adjacency: - source: /leaf target: /spine pattern: mesh link_params: capacity: 10 cost: 1 """ scenario = Scenario.from_yaml(scenario_yaml) network = scenario.network print(f"Created Clos fabric with {len(network.nodes)} nodes and {len(network.links)} links")
- Quick Tutorial - Build your first network scenario
- DSL Reference - YAML syntax reference
- API Reference - Explore the Python API in detail