- Notifications
You must be signed in to change notification settings - Fork32
A utility library for comparing and synchronizing different datasets.
License
networktocode/diffsync
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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.
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.
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 theAdapter class, and each data model class will be a subclass of theDiffSyncModel class.
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 thediff_to() ordiff_from() method on one adapter and passing the other adapter as a parameter.
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 thesync_to() orsync_from() method on one adapter and passing the other adapter as a parameter.
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 Adiff_a_b=A.diff_from(B)print(diff_a_b.str())# Update System A to align with the current status of system BA.sync_from(B)# Update System B to align with the current status of system AA.sync_to(B)
You may wish to peruse the
diffsyncGitHub topic for examples of projects using this library.
The documentation is availableon Read The Docs.
$ pip install diffsync$ pip install git+https://github.com/networktocode/diffsync.git@mainPull 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 runninginvoke tests from the CLI.The commandinvoke build builds a docker container with all the necessary dependencies (including the redis backend) locally to facilitate the execution of these tests.
Please see thedocumentation for detailed documentation on how to usediffsync. For any additional questions or comments, feel free to swing by theNetwork to Code slack channel (channel #networktocode). Sign uphere
About
A utility library for comparing and synchronizing different datasets.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.


