Skip to main content

Calculates a diff of a network topology

Project description Code Health Requirements Status

Netdiff is an experimental Python library that provides utilities for parsing network topologies of open source dynamic routing protocols and calculating changes in these topologies.

It was developed to abstract the differences between the different JSON structures of the open source dynamic routing protocols (like OLSR and batman-advanced).

Install stable version from pypi

Install from pypi:

pip install netdiff

Install development version

Install tarball:

pip install

Alternatively you can install via pip using git:

pip install -e git+git://

If you want to contribute, install your cloned fork:

git clone<your_fork>/netdiff.git
cd netdiff
python develop

Basic Usage Example

Calculate diff of an OLSR 0.6.x topology:

from netdiff import OlsrParser
from netdiff import diff

stored = OlsrParser('./stored-olsr.json')
latest = OlsrParser('telnet://')
diff(stored, latest)

The output will be a dictionary with the following structure:

    "added": []
    "removed": []

In alternative, you can use the subtraction operator:

from netdiff import OlsrParser
from netdiff import diff

stored = OlsrParser('./stored-olsr.json')
latest = OlsrParser('telnet://')
latest - stored

Initialization arguments

data: the only required argument, different inputs are accepted:

  • string representing the topology
  • python dict (or subclass of dict) representing the topology
  • string representing a HTTP URL where the data resides
  • string representing a telnet URL where the data resides
  • string representing a file path where the data resides

timeout: integer representing timeout in seconds for HTTP or telnet requests, defaults to None

verify: boolean indicating to the request library whether to do SSL certificate verification or not


Parsers are classes that extend netdiff.base.BaseParser and implement a parse method which is in charge of converting a python data structure into networkx.Graph object.

Parsers also have a json method which returns valid NetJSON output.

The available parsers are:

Parsers must be initialized with a string which can represent one of the following:

  • path to JSON file
  • HTTP url to JSON file
  • telnet url to JSON file
  • JSON formatted string
  • python dictionary representing a JSON structure

Local file example:

from netdiff import BatmanParser

HTTP example:

from netdiff import NetJsonParser
url = ''

NetJSON output

Netdiff parsers can return a valid NetJSON NetworkGraph object:

from netdiff import OlsrParser

olsr = OlsrParser('telnet://')

# will return a dict

# will return a JSON formatted string


    "type": "NetworkGraph",
    "protocol": "OLSR",
    "version": "0.6.6",
    "revision": "5031a799fcbe17f61d57e387bc3806de",
    "metric": "ETX",
    "nodes": [
            "id": ""
            "id": ""
            "id": ""
    "links": [
            "source": "",
            "target": "",
            "weight": 2.4
            "source": "",
            "target": "",
            "weight": 1.0


All the exceptions are subclasses of netdiff.exceptions.NetdiffException.



Raised when netdiff can’t recognize the format passed to the parser.

Not necessarily an error, should be caught and managed in order to support additional formats.



Raised when the format is recognized but the data is invalid.



Raised when the json method of netdiff.parsers.BaseParser does not have enough data to be compliant with the NetJSON NetworkGraph specification.



Raised when it is not possible to retrieve the topology data (eg: the URL might be temporary unreachable).

Running tests

Install your forked repo:

git clone git://<your_fork>/netdiff
cd netdiff/
python develop

Install test requirements:

pip install -r requirements-test.txt

Run tests with:


Alternatively, you can use the nose command (which has a ton of available options):

nosetests tests.olsr  # run only olsr related tests
nosetests tests/olsr  # variant form of the previous command
nosetests tests.olsr.tests:TestOlsrParser  # variant form of the previous command
nosetests tests.olsr.tests:TestOlsrParser.test_parse  # run specific test

See test coverage with:

coverage run --source=netdiff && coverage report


  1. Join the ninux-dev mailing list
  2. Fork this repo and install it
  3. Follow PEP8, Style Guide for Python Code
  4. Write code
  5. Write tests for your code
  6. Ensure all tests pass
  7. Ensure test coverage is not under 90%
  8. Document your changes
  9. Send pull request

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for netdiff, version 0.3.2
Filename, size File type Python version Upload date Hashes
Filename, size netdiff-0.3.2-py2.py3-none-any.whl (15.2 kB) File type Wheel Python version 3.4 Upload date Hashes View
Filename, size netdiff-0.3.2.tar.gz (66.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page