A library for replicating your python class between multiple servers, based on raft protocol
A library for replicating your python class between multiple servers, based on raft protocol
PySyncObj is a python library for building fault-tolerant distributed systems. It provides the ability to replicate your application data between multiple servers. It has following features:
PySyncObj itself:
pip install pysyncobjCryptography for encryption (optional):
pip install cryptographyConsider 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.__counterSo, to transform your class into a replicated one:
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.@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.__counterAnd thats all! Now you can call incCounter on serverA, and check counter value on serverB - they will be synchronized.
If you just need some distributed data structures - try built-in "batteries". Few examples:
…from pysyncobj import SyncObj
from pysyncobj.batteries import ReplLockManager
lockManager = ReplLockManager(autoUnlockTime=75) # Lock will be released if connection dropped for more than 75 seconds
syncObj = SyncObj('serverA:4321', ['serverB:4321', 'serverC:4321'], consumers=[lockManager])
if lockManager.tryAcquire('testLockName', sync=True):
# do some actions
lockManager.release('testLockName')You can look at batteries implementation, examples and unit-tests for more use-cases. Also there is an API documentation. Feel free to create proposals and/or pull requests with new batteries, features, etc. Join our gitter chat if you have any questions.
No open issues yet, or sync has not completed.