bakwc/PySyncObj
bakwc/PySyncObj has 761 GitHub stars and 121 forks. GitHot measured 0 stars in 24 hours and 0 in 7 days. Last checked 2026-11-24 11:36 UTC. Last push 2026-08-30.
측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 기록 수집 중
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
소개
Raft 프로토콜을 기반으로 여러 서버 간에 Python 클래스를 복제하는 라이브러리
개발 도구README.md
OriginalPySyncObj
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:
- raft protocol for leader election and log replication
- Log compaction - it use fork for copy-on-write while serializing data on disk
- Dynamic membership changes - you can do it with syncobj_admin utility or directly from your code
- Zero downtime deploy - no need to stop cluster to update nodes
- In-memory and on-disk serialization - you can use in-memory mode for small data and on-disk for big one
- Encryption - you can set password and use it in external network
- Python2 and Python3 on linux, macos and windows - no dependencies required (only optional one, eg. cryptography)
- Configurable event loop - it can work 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).
Content
Install
PySyncObj itself:
pip install pysyncobj
Cryptography for encryption (optional):
pip install cryptography
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,serverBandserverCand want to use 4321 port, you should use self addressserverA:4321with partners[serverB:4321, serverC:4321]for your application, running atserverA; self addressserverB:4321with partners[serverA:4321, serverC:4321]for your application atserverB; self addressserverC:4321with partners[serverA:4321, serverB:4321]for app atserverC. - Mark all your methods that modifies your class fields with
@replicateddecorator. 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.
Batteries
If you just need some distributed data structures - try built-in "batteries". Few examples:
Counter & Dict
from pysyncobj import SyncObj
from pysyncobj.batteries import ReplCounter, ReplDict
counter1 = ReplCounter()
counter2 = ReplCounter()
dict1 = ReplDict()
syncObj = SyncObj('serverA:4321', ['serverB:4321', 'serverC:4321'], consumers=[counter1, counter2, dict1])
counter1.set(42, sync=True) # set initial value to 42, 'sync' means that operation is blocking
counter1.add(10, sync=True) # add 10 to counter value
counter2.inc(sync=True) # increment counter value by one
dict1.set('testKey1', 'testValue1', sync=True)
dict1['testKey2'] = 'testValue2' # this is basically the same as previous, but asynchronous (non-blocking)
print(counter1, counter2, dict1['testKey1'], dict1.get('testKey2'))
Lock
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.
Performance

Publications
관련 프로젝트 살펴보기
불러오는 중…