Skip to main content

etcd3-py

pypi travis codecov doc updates python3

Python client for etcd v3 (Using gRPC-JSON-Gateway)

Notice: The authentication header through gRPC-JSON-Gateway only supported in etcd v3.3+

Features

  • [x] Support python2.7 and python3.5+

  • [x] Sync client based on requests

  • [x] Async client based on aiohttp

  • [x] Support etcd3 gRPC-JSON-Gateway including stream

  • [x] Response modelizing based on etcd3’s swagger spec

  • [x] Generate code from swagger spec

  • [ ] TLS Connection

  • [x] support APIs

    • [x] Auth

    • [x] KV

    • [x] Watch

    • [x] Cluster

    • [x] Lease

    • [x] Maintenance

    • [x] Extra APIs

  • [x] stateful utilities

    • [x] Watch

    • [x] Lease

    • [x] Transaction

    • [x] Lock

Quick Start

Install

$ pip install etcd3-py

Sync Client

>>> from etcd3 import Client
>>> client = Client('127.0.0.1', 2379)
>>> client.version()
EtcdVersion(etcdserver='3.3.0-rc.4', etcdcluster='3.3.0')
>>> client.put('foo', 'bar')
etcdserverpbPutResponse(header=etcdserverpbResponseHeader(cluster_id=11588568905070377092, member_id=128088275939295631, revision=15433, raft_term=4))
>>> client.range('foo').kvs
[mvccpbKeyValue(key=b'foo', create_revision=15429, mod_revision=15433, version=5, value=b'bar')]

Async Client (Python3.5+)

>>> import asyncio
>>> from etcd3 import AioClient
>>> client = AioClient('127.0.0.1', 2379)
>>> async def getFoo():
...     await client.put('foo', 'bar')
...     r = await client.range('foo')
...     print('key:', r.kvs[0].key, 'value:', r.kvs[0].value)
>>> loop = asyncio.get_event_loop()
>>> loop.run_until_complete(getFoo())
key: b'foo' value: b'bar'

Transaction Util

>>> from etcd3 import Client
>>> txn = Client().Txn()
>>> txn.compare(txn.key('foo').value == 'bar')
>>> txn.success(txn.put('foo', 'bra'))
>>> txn.commit()
etcdserverpbTxnResponse(header=etcdserverpbResponseHeader(cluster_id=11588568905070377092, member_id=128088275939295631, revision=15656, raft_term=4), succeeded=True, responses=[etcdserverpbResponseOp(response_put=etcdserverpbPutResponse(header=etcdserverpbResponseHeader(revision=15656)))])

Lease Util

>>> from etcd3 import Client
>>> client = Client()
>>> with client.Lease(ttl=5) as lease:
...     client.put('foo', 'bar', lease=lease.ID)
...     client.put('fizz', 'buzz', lease=lease.ID)
...     r = lease.time_to_live(keys=True)
...     assert set(r.keys) == {b'foo', b'fizz'}
...     assert lease.alive()

Watch Util

>>> from etcd3 import Client
>>> client = Client()
>>> watcher = c.Watcher(all=True, progress_notify=True, prev_kv=True)
>>> w.onEvent('f.*', lambda e: print(e.key, e.value))
>>> w.runDaemon()
>>> # etcdctl put foo bar
>>> # etcdctl put foz bar
b'foo' b'bar'
b'foz' b'bar'
>>> w.stop()

Lock Util

>>> import time
>>> from threading import Thread
>>> from etcd3 import Client
>>> client = Client()
>>> name = 'lock_name'
>>> def user1():
...     with client.Lock(name, lock_ttl=5):
...         print('user1 got the lock')
...         time.sleep(5)
...         print('user1 releasing the lock')
>>> def user2():
...     with client.Lock(name, lock_ttl=5):
...         print('user2 got the lock')
...         time.sleep(5)
...         print('user2 releasing the lock')
>>> t1 = Thread(target=user1, daemon=True)
>>> t2 = Thread(target=user2, daemon=True)
>>> t1.start()
>>> t2.start()
>>> t1.join()
>>> t2.join()
user1 got the lock
user1 releasing the lock
user2 got the lock
user2 releasing the lock

TODO

  • [ ] benchmark

  • [ ] python-etcd(etcd v2) compatible client

  • [ ] etcd browser

History

0.0.1 (2018-01-26)

  • First release on PyPI.

Metadata

Release files for etcd3-py 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for etcd3-py 0.1.5
File Size Uploaded Provenance Actions
etcd3-py-0.1.5.tar.gz 90.1 kB Without provenance Details for etcd3-py-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for etcd3-py 0.1.5
File Interpreter ABI Platform Actions
etcd3_py-0.1.5-py2.py3-none-any.whl Python 2, Python 3 none any Details for etcd3_py-0.1.5-py2.py3-none-any.whl

Total release size: 176.7 kB

Release files / etcd3-py-0.1.5.tar.gz

Download URL etcd3-py-0.1.5.tar.gz
Size 90.1 kB
Tags Source
SHA-256 checksum
How to use checksums
82cd609c4a7638dfc5366dd50ec145aa5bb92f57f16dbf8177d556386b407ffa
BLAKE2b-256 checksum
How to use checksums
4e8e9b2efa2427cd7acf94536d51c4fdb8a7926307650602e0b238330d88b6c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / etcd3_py-0.1.5-py2.py3-none-any.whl

Download URL etcd3_py-0.1.5-py2.py3-none-any.whl
Size 86.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
f653c6f4d16dc6a8b7a07adf66bbe22a9429f94c0af6d6e69985de845a3bf6ca
BLAKE2b-256 checksum
How to use checksums
6f20f96e5c6df257b457726265e9f30673689414f5031716f950ff8ecb14f4be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for etcd3-py 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page