Skip to content
This repository was archived by the owner on Jun 11, 2022. It is now read-only.
/ etcd3aio Public archive
forked from hron/etcd3aio

Python asyncio client for the etcd gRPC API v3

License

Notifications You must be signed in to change notification settings

mk-fg/etcd3aio

 
 

Repository files navigation

Deprecation Notice

This module is abandoned, overcomplicated for what does and no longer necessary, and martyanov/aetcd should be much simplier and better fit for what it does - please use that instead.

This repository is preserved here for historical purposes and because old code might still rely on it, but again, there should be no reason to use it in any new projects.

etcd3aio - etcd client for asyncio

This project is a fork of hron/etcd3aio, which is based on python-etcd3.

It's a python 3.8+ module that implements modern asyncio grpclib-based client for etcd3.

This fork has couple local fixes on top of hron/etcd3aio, but does not use testing setup and code from the source repo, as I didn't bother figuring out how to use it, so it's probably broken here.

Basic usage

import etcd3aio

etcd = etcd3aio.client()
await etcd.get('foo')
await etcd.put('bar', 'doot')
await etcd.delete('bar')

# locks
lock = etcd.lock('thing')
await lock.acquire()
# do something
await lock.release()

async with etcd.lock('doot-machine') as lock:
  # do something

# transactions
await etcd.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 key
watch_count = 0
events_iterator, cancel = await etcd.watch("/doot/watch")
async for event in events_iterator:
  print(event)
  watch_count += 1
  if watch_count > 10:
    await cancel()

# watch prefix
watch_count = 0
events_iterator, cancel = await etcd.watch_prefix("/doot/watch/prefix/")
async for event in events_iterator:
  print(event)
  watch_count += 1
  if watch_count > 10:
    await cancel()

# receive watch events via callback function
def watch_callback(event):
  print(event)

watch_id = await etcd.add_watch_callback("/anotherkey", watch_callback)

# cancel watch
await etcd.cancel_watch(watch_id)

# receive watch events for a prefix via callback function
def watch_callback(event):
  print(event)

About

Python asyncio client for the etcd gRPC API v3

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.6%
  • Dockerfile 0.4%