Skip to main content

Library to easily sync/diff/update 2 different data sources

Project description

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

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

diffsync-1.10.0.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

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

diffsync-1.10.0-py3-none-any.whl (39.5 kB view details)

Uploaded Python 3

File details

Details for the file diffsync-1.10.0.tar.gz.

File metadata

  • Download URL: diffsync-1.10.0.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for diffsync-1.10.0.tar.gz
Algorithm Hash digest
SHA256 a9d7cb8e8ce983b446bf858c1c5c82cf473fcf231db73c0855e8c59ee7cd8370
MD5 4f969378e5a25708f3b28ed283d4bd93
BLAKE2b-256 327dd1e35a05ea048225049c5533e7c7a7423f197190ee0d33aa782199c5d4be

See more details on using hashes here.

File details

Details for the file diffsync-1.10.0-py3-none-any.whl.

File metadata

  • Download URL: diffsync-1.10.0-py3-none-any.whl
  • Upload date:
  • Size: 39.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for diffsync-1.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4368c97162d51eecc7a8e87026c731197a694026cabcf2ab4f16d18d7bdadbd
MD5 98dc671437aac4cd13f6967d39de3475
BLAKE2b-256 10e24e1b6027554ba3326d3f1c2444be04005c135c81815bdd35bb7abf75f3c1

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