A library for replicating your python class between multiple servers, based on raft protocol
Project description
PySyncObj is a python library that provides ability to sync your data between multiple servers. - It use raft protocol for leader election and log replication. - It supports log compaction. It use fork for copy-on-write while serializing data on disk. - It supports in-memory and on-disk serialization. You can use in-memory mode for small data and on-disk for big one. - No additional libraries required (you need only python2.7 or python3.4) - Configurable event loop - it can works in separate thread with it’s own event loop - or you can call onTick function inside your own one. - Convenient interface - you can easily transform arbitrary class into a replicated one (see example below).
Install
pip install pysyncobj
Usage
Consider you have a class that implements counter:
class MyCounter(object):
def __init__(self):
self.__counter = 0
def incCounter(self):
self.__counter += 1
def getCounter(self):
return self.__counter
So, to transform your class into a replicated one: - Inherit it from SyncObj - Initialize SyncObj with a self address and a list of partner addresses. Eg. if you have serverA, serverB and serverC and want to use 4321 port, you should use self address serverA:4321 with partners [serverB:4321, serverC:4321] for your application, running at serverA; self address serverB:4321 with partners [serverA:4321, serverC:4321] for your application at serverB; self address serverC:4321 with partners [serverA:4321, serverB:4321] for app at serverC. - Mark all your methods that modifies your class fields with @replicated decorator. So your final class will looks like:
class MyCounter(SyncObj):
def __init__(self):
super(MyCounter, self).__init__('serverA:4321', ['serverB:4321', 'serverC:4321'])
self.__counter = 0
@replicated
def incCounter(self):
self.__counter += 1
def getCounter(self):
return self.__counter
And thats all! Now you can call incCounter on serverA, and check counter value on serverB - they will be synchronized. You can look at examples and syncobj_ut.py for more use-cases.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pysyncobj-0.1.7.tar.gz.
File metadata
- Download URL: pysyncobj-0.1.7.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ab20b380b57eff45cd2c3d4fc8e1da353483224160f9fbbc6b04c6e1c96b1b7
|
|
| MD5 |
dbeb3a1abf47cc1e264517c51f5e3d2c
|
|
| BLAKE2b-256 |
0962e5ceea05cb858948c452e041035c3ccc4bc7e5ac753c3b329eb47e81aefb
|