Skip to main content

A tiny tool to diff two graphs

Project description

gpatches

A tool to diff two graphs. This library helps you identify changes between two networkx graphs including added/removed nodes, changed node parameters, and added/removed edges.

Installation

pip install gpatches

Usage

import networkx as nx
from gpatches import diff_graphs

G1 = nx.DiGraph()
G1.add_node("A", x=1, y=2)
G1.add_node("B", foo="bar")
G1.add_edge("A", "B", weight=5)

G2 = nx.DiGraph()
G2.add_node("A", x=1, y=3, z=4)  # Changed y value and added z parameter
G2.add_node("C", color="blue")   # New node
G2.add_edge("A", "C", weight=2)  # New edge

# Diff the graphs
patches = diff_graphs(G1, G2)
print(patches)

The output from the above example would be:

GraphPatch(
    added_nodes={'C': {'color': 'blue'}},
    removed_nodes={'B': {'foo': 'bar'}},
    changed_nodes={
        'A': NodePatch(
            added_params={'z': 4},
            removed_params={},
            changed_params={'y': ParamPatch(old_param_value=2, new_param_value=3)}
        )
    },
    removed_edges={('A', 'B'): {'weight': 5}},
    added_edges={('A', 'C'): {'weight': 2}}
)

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

gpatches-0.1.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

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

gpatches-0.1.1-py3-none-any.whl (2.5 kB view details)

Uploaded Python 3

File details

Details for the file gpatches-0.1.1.tar.gz.

File metadata

  • Download URL: gpatches-0.1.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.12

File hashes

Hashes for gpatches-0.1.1.tar.gz
Algorithm Hash digest
SHA256 788f51b407b4283a713b2815d8a64057d5ce3e5bf6b470b8310da0cadb454b26
MD5 10351363edaa5d663a5ef8aa832e6a4d
BLAKE2b-256 9c45c519ace132459d228128c76d7d3bcf76d2bc67f0d9d24e2ebb2c6e8475d1

See more details on using hashes here.

File details

Details for the file gpatches-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: gpatches-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 2.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.12

File hashes

Hashes for gpatches-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 141b5433840307f76f04a54671f8dd95b290d98521a3e5bbc9d8e406e89c319d
MD5 b9a4f1056a8213e1705147c258ebd3ed
BLAKE2b-256 7ee39b234239bf53e6bc946f2c6624fc67883159a0d98f1a16e8110f99ad86e0

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