Skip to main content

Python asyncio based client for the etcd API v3

Project description

Build Status Coverage report Documentation PyPI Version Supported Python Versions License

Installation

$ python3 -m pip install aetcd3

Basic usage

import aetcd3

etcd = aetcd3.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)

Acknowledgements

This project is a fork of etcd3aio, which itself is a fork of python-etcd3. python-etcd3 was originally written by kragniz. asyncio suppport was contributed by hron and based on the previous work by gjcarneiro. Kudos to all the people involved in the projects.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

aetcd-0.1.0a7-py3-none-any.whl (50.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page