Skip to main content

Synchronize items bi-directionally between two different sources

Project description

Item Synchronizer

logo

pre-commit PyPI version Downloads Code style: black

Description

Synchronize items from two different sources in a bidirectional manner.

This library aims to offer an abstract and versatile way to create, update and/or delete items to keep two "sources" in sync.

These "items" may range from Calendar entries, TODO task lists, or whatever else you want as long as the user registers the appropriate functions/methods to convert from one said item to another.

Usage

The Synchronizer class requires the following Callables to be given, for each one of the sides. See the most up-to-date python types here

  • Insertion callable: when called with the contents of an item it should create and return the ID of the newly added item on the other source

  • Update callable: update an item given by the item ID, using the (possibly partial) new contents specified by Item

  • Deletion callable: Delete the item given by the specified ID

  • Conversion callable: convert an item from the format of one source to the format of another.

  • Item Getter callable: Given the ID of an Item of one source return the corresponding item on the other source.

  • A_to_B bidict

    • This should be a bidict mapping IDs of A to the corresponding IDs of B and vice-versa. Given this the item_synchronizer is responsible for keeping it up to date on insertion, update and deletion events. The contents of this bidict should be persistent across the various runs, thus, consider pickle-ing and unpickling its contents to disk

Additionally item_synchronizer needs to know what items (their IDs) were inserted, updated and deleted during the call to its main method, sync(). This is dependent on your application at hand. You could either cache the items and their content after each run and compare them with the latest state in the current run. Or, the API of the calendar/task manager, etc. that you are using may allow you to query the items that were modified/inserted/deleted since the last run.

Examples

Let's say you want to bi-directionally synchronize your calendar events with your TODO Task Manager tasks. This way, when you remove calendar event, the correspoding task will be deleted, when you add a new task in your task manager, a new calendar event will be created and when you update the task (e.g., change its description or start time) the changes will reflect in the corresponding calendar entry.

Thus, you have the following and you want to sync the A and B items.

sync0

As described in the previous section, item_synchronizer requires a set of functions which it will call when it needs to insert, update or delete an item from the corresponding side. It also requires an A_to_B bidict persistent across its runs with the item mappings between the two sides before the very latest changes. Notice that, item_synchonizer will be responsible for updating entries in this A_to_B bidict, you do not need to do that manually. You only need to make it persist across the different runs of the Synchronizer.sync() call (e.g., by pickle-ing and unpickle-ing it every time your application exits and starts again.)

Thus, this is the situation that item_synchronizer expects at its first run.

sync1

After the first call to sync() here's the expected results. After this call each event of one side will have a counterpart on the other side and that's also going to be reflected in the provided A_to_B bidict.

sync2

Subsequent calls to sync() will pick up the changes and will insert any new items from each side to the other side accordingly.

Now let's say that item 2 was modified from side A, item 3 from side B and item 21 was deleted from side A.

update-n-delete0

In the subsequent call to sync(), item_synchronizer will forward these changes to the other side appropriately.

update-n-delete1

If there was a conflict, e.g., an item removed from one side and updated from the other, then item_synchronizer supports a series of resolution strategies for handling such conflicts.

resolution-strategy

Installation

Add it as a dependency to either your requirements.txt or to pyproject.toml

[tool.poetry.dependencies]
...
item_synchronizer = "^1.0"
...

Or simply install it with pip if you want to use it locally:

pip3 install item_synchronizer

Projects using it

Projects using this:

Notes

  • Currently IDs of items on either side should be of str type.

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

item_synchronizer-1.1.2.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

item_synchronizer-1.1.2-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file item_synchronizer-1.1.2.tar.gz.

File metadata

  • Download URL: item_synchronizer-1.1.2.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.0 Linux/5.11.0-1021-azure

File hashes

Hashes for item_synchronizer-1.1.2.tar.gz
Algorithm Hash digest
SHA256 c092374ac9cfde3d43f47346ae69795b4b0b1e7b884dc2f3a1e09bf5b2ab766b
MD5 fd1b275f3bf8ef63672c7d0a998d834e
BLAKE2b-256 d55e5617e490fa97729a5f6ba87ead660d0c18e4d9c86f426459539fb0ef203c

See more details on using hashes here.

File details

Details for the file item_synchronizer-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: item_synchronizer-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.0 Linux/5.11.0-1021-azure

File hashes

Hashes for item_synchronizer-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 92afb150f4738b139bddb05a2dc66319794cce18235f75a4ed15f5c17b749841
MD5 2fbe4f563632f03ab591568504790e56
BLAKE2b-256 cab43a77d5e30d76b8847e91b1c440e00f7711ba86778e5c181bbf3c9dc5858d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page