etcd3 api的python客户端
etcd3的Python项目详细描述
python-etcd3
用于etcd api v3的python客户端,在python 2.7、3.4和3.5下受支持。
警告:api基本上是稳定的,但将来可能会发生变化
如果你有兴趣使用这个库,请参与进来。
- 免费软件:apache软件许可证2.0
- 文档:https://python-etcd3.readthedocs.io。
基本用法:
importetcd3etcd=etcd3.client()etcd.get('foo')etcd.put('bar','doot')etcd.delete('bar')# lockslock=etcd.lock('thing')# do somethinglock.release()withetcd.lock('doot-machine')aslock:# do something# transactionsetcd.transaction(compare=[etcd.transactions.value('/doot/testing')=='doot',etcd.transactions.version('/doot/testing')>0,],success=[etcd.transactions.put('/doot/testing','success'),],failure=[etcd.transactions.put('/doot/testing','failure'),])# watch keywatch_count=0events_iterator,cancel=etcd.watch("/doot/watch")foreventinevents_iterator:print(event)watch_count+=1ifwatch_count>10:cancel()# watch prefixwatch_count=0events_iterator,cancel=etcd.watch_prefix("/doot/watch/prefix/")foreventinevents_iterator:print(event)watch_count+=1ifwatch_count>10:cancel()# recieve watch events via callback functiondefwatch_callback(event):print(event)watch_id=etcd.add_watch_callback("/anotherkey",watch_callback)# cancel watchetcd.cancel_watch(watch_id)
历史记录
0.1.0(2016-09-30)
- pypi上的第一个版本。