• Stars
    star
    144
  • Rank 254,017 (Top 6 %)
  • Language
    Python
  • License
    Other
  • Created about 4 years ago
  • Updated 26 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A utility library for comparing and synchronizing different datasets.

DiffSync

DiffSync is a utility library that can be used to compare and synchronize different datasets.

For example, it can be used to compare a list of devices from 2 inventory systems and, if required, synchronize them in either direction.

Primary Use Cases

DiffSync is at its most useful when you have multiple sources or sets of data to compare and/or synchronize, and especially if any of the following are true:

  • If you need to repeatedly compare or synchronize the data sets as one or both change over time.
  • If you need to account for not only the creation of new records, but also changes to and deletion of existing records as well.
  • If various types of data in your data set naturally form a tree-like or parent-child relationship with other data.
  • If the different data sets have some attributes in common and other attributes that are exclusive to one or the other.

Overview of DiffSync

DiffSync acts as an intermediate translation layer between all of the data sets you are diffing and/or syncing. In practical terms, this means that to use DiffSync, you will define a set of data models as well as the “adapters” needed to translate between each base data source and the data model. In Python terms, the adapters will be subclasses of the DiffSync class, and each data model class will be a subclass of the DiffSyncModel class.

Diffsync Components

Once you have used each adapter to load each data source into a collection of data model records, you can then ask DiffSync to “diff” the two data sets, and it will produce a structured representation of the difference between them. In Python, this is accomplished by calling the diff_to() or diff_from() method on one adapter and passing the other adapter as a parameter.

Diffsync Diff Creation

You can also ask DiffSync to “sync” one data set onto the other, and it will instruct your adapter as to the steps it needs to take to make sure that its data set accurately reflects the other. In Python, this is accomplished by calling the sync_to() or sync_from() method on one adapter and passing the other adapter as a parameter.

Diffsync Sync

Simple Example

A = DiffSyncSystemA()
B = DiffSyncSystemB()

A.load()
B.load()

# Show the difference between both systems, that is, what would change if we applied changes from System B to System A
diff_a_b = A.diff_from(B)
print(diff_a_b.str())

# Update System A to align with the current status of system B
A.sync_from(B)

# Update System B to align with the current status of system A
A.sync_to(B)

You may wish to peruse the diffsync GitHub topic for examples of projects using this library.

Documentation

The documentation is available on Read The Docs.

Installation

Option 1: Install from PyPI.

$ pip install diffsync

Option 2: Install from a GitHub branch, such as main as shown below.

$ pip install git+https://github.com/networktocode/diffsync.git@main

Contributing

Pull requests are welcomed and automatically built and tested against multiple versions of Python through GitHub Actions.

The project is following Network to Code software development guidelines and are leveraging the following:

  • Black, Pylint, Bandit, flake8, and pydocstyle, mypy for Python linting, formatting and type hint checking.
  • pytest, coverage, and unittest for unit tests.

You can ensure your contribution adheres to these checks by running invoke tests from the CLI. The command invoke build builds a docker container with all the necessary dependencies (including the redis backend) locally to facilitate the execution of these tests.

Questions

Please see the documentation for detailed documentation on how to use diffsync. For any additional questions or comments, feel free to swing by the Network to Code slack channel (channel #networktocode). Sign up here

More Repositories

1

awesome-network-automation

Curated Awesome list about Network Automation
2,230
star
2

ntc-templates

TextFSM templates for parsing show commands of network devices
Python
1,072
star
3

ntc-ansible

Multi-vendor network modules
Python
278
star
4

ntc-netbox-plugin-onboarding

A plugin for NetBox to easily onboard new devices.
Python
245
star
5

netutils

Python library that is a collection of functions and objects for common network automation tasks.
Python
214
star
6

pyntc

Python library focused on tasks related to device level and OS management.
Python
169
star
7

network-importer

The network importer is a tool/library to analyze and/or synchronize an existing network with a Network Source of Truth (SOT), it's designed to be idempotent and by default it's only showing the difference between the running network and the remote SOT.
Python
166
star
8

yangify

Library to help parsing/translating YANG models from/to native text/structures
Python
113
star
9

ntc-rosetta

The missing bridge between industry standard CLIs and YANG
Python
102
star
10

circuit-maintenance-parser

Python library to parse circuit maintenances from network service providers.
HTML
71
star
11

fortimanager-ansible

Ansible Modules to manage Fortinet FortiManager
Python
65
star
12

schema-enforcer

Schema Enforcer provides a framework for testing structured data against schema definitions.
Python
46
star
13

netbox_day_2020

NetBox Day 2020 Content
41
star
14

ntc-netbox-plugin-metrics-ext

NetBox Plugin to improve the instrumentation of NetBox and expose additional metrics (Application Metrics, RQ Worker).
Python
38
star
15

ntc-soteria

ACL/Flow Auditing Tool based on Batfish
Python
30
star
16

anit

Ansible Network Infrastructure Testing Framework
Python
28
star
17

interop2020-slides

Network Automation Summit Slides
25
star
18

jdiff

Python
21
star
19

pynxos

A library for managing Cisco NX-OS devices through NX-API.
Python
17
star
20

netbox-training

Examples and demos from Network to Code's NetBox training
Jupyter Notebook
16
star
21

interop2020-ansible-molecule

Ansible Molecule demo for Network Automation
Python
14
star
22

2022-ntc-content

Content from NTCers at conferences, blogs, videos, and other events in 2022.
Python
14
star
23

nso-restconf-postman-examples

12
star
24

netscaler-ansible

Ansible Modules to manage Citrix Netscaler devices
Python
11
star
25

ansible-replay

A way to play captured Ansible output in a way that looks like a real ansible-playbook was ran
Python
10
star
26

bsn-ansible

Ansible modules for automating Big Switch Networks' products
Python
9
star
27

clemea-demo

For Cisco Live Amsterdam workshop
Python
8
star
28

cisco-test-modules

Python
6
star
29

ntc-rosetta-conf

Restconf interface for rosetta
Python
5
star
30

meetups

Relevant code and slides for Network-to-Coders meetups
5
star
31

flowtracker

Trace a flow through a data center fabric of Nexus switches
Python
5
star
32

ntc-yang-models

Usable and relevant YANG models for everyone
Python
5
star
33

arista-atd

Python
5
star
34

interop2020-batfish

4
star
35

ntc-misc

General repository used for sharing misc one-off projects
Python
4
star
36

clus-2018

Python
3
star
37

inog9

Slides and labs from iNOG 9 in Dublin
HTML
3
star
38

ntc-sample-pbs

General Testing of Playbooks
2
star
39

nornir-pyntc

Pyntc Plugin for Nornir
Python
2
star
40

nautobot-example-dns-manager

Python
2
star
41

ntc-tesuto

Menu-driven application to manage Tesuto emulations
Python
2
star
42

test-api

1
star
43

python-checker

Docker image for checking Python code easily
Shell
1
star
44

cicd-testing

1
star