All Projects → Revolution1 → etcd3-py

Revolution1 / etcd3-py

Licence: other
Pure python client for etcd v3 (Using gRPC-JSON-Gateway)

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to etcd3-py

etcdv3-ruby
Etcd v3 Ruby Client
Stars: ✭ 48 (-50.52%)
Mutual labels:  etcd, etcd-client, etcd3
etcdv3-browser
etcd v3 browser - web UI client for browsing (and optionally, editing) etcd3 contents
Stars: ✭ 20 (-79.38%)
Mutual labels:  etcd, etcd3
Swarmstack
A Docker swarm-based starting point for operating highly-available containerized applications.
Stars: ✭ 181 (+86.6%)
Mutual labels:  etcd
sshproxy
Proxy SSH connections on a gateway
Stars: ✭ 75 (-22.68%)
Mutual labels:  etcd
Gosiris
An actor framework for Go
Stars: ✭ 222 (+128.87%)
Mutual labels:  etcd
Dcmp
基于etcd的配置管理系统 (etcd v2)
Stars: ✭ 200 (+106.19%)
Mutual labels:  etcd
Mgmt
Next generation distributed, event-driven, parallel config management!
Stars: ✭ 2,708 (+2691.75%)
Mutual labels:  etcd
Pifpaf
Python fixtures and daemon managing tools for functional testing
Stars: ✭ 161 (+65.98%)
Mutual labels:  etcd
coinbasepro
A Python API for Coinbase Pro
Stars: ✭ 52 (-46.39%)
Mutual labels:  python-client
Constructr
Coordinated (etcd, ...) cluster construction for dynamic (cloud, containers) environments
Stars: ✭ 219 (+125.77%)
Mutual labels:  etcd
perseus
Perseus is a set of scripts (docker+javascript) to investigate a distributed database's responsiveness when one of its three nodes is isolated from the peers
Stars: ✭ 49 (-49.48%)
Mutual labels:  etcd
Skipper
An HTTP router and reverse proxy for service composition, including use cases like Kubernetes Ingress
Stars: ✭ 2,606 (+2586.6%)
Mutual labels:  etcd
Remco
remco is a lightweight configuration management tool
Stars: ✭ 200 (+106.19%)
Mutual labels:  etcd
Etcdhcp
A DHCP server backed by etcd
Stars: ✭ 250 (+157.73%)
Mutual labels:  etcd
Go Flagz
Dynamic flag management for Go.
Stars: ✭ 191 (+96.91%)
Mutual labels:  etcd
cetcd
Cetcd is a C client library for etcd with full features support
Stars: ✭ 66 (-31.96%)
Mutual labels:  etcd
Docker Compose
一些基础服务的docker-compose配置文件,方便在一台新电脑上快速开始工作
Stars: ✭ 163 (+68.04%)
Mutual labels:  etcd
Dbtester
Distributed database benchmark tester
Stars: ✭ 214 (+120.62%)
Mutual labels:  etcd
Forest
分布式任务调度平台,分布式,任务调度,schedule,scheduler
Stars: ✭ 231 (+138.14%)
Mutual labels:  etcd
api
Tendrl API
Stars: ✭ 16 (-83.51%)
Mutual labels:  etcd

etcd3-py

pypi travis Codacy Badge 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.0+

Features

  • Support python2.7 and python3.5+ (aiohttp requires python3.5.2+)
  • Sync client based on requests
  • Async client based on aiohttp
  • TLS Connection
  • support APIs
    • Auth
    • KV
    • Watch
    • Cluster
    • Lease
    • Lock
    • Maintenance
    • Extra APIs
  • stateful utilities
    • Watch
    • Lease
    • Transaction
    • Lock

Quick Start

Install

$ pip install --upgrade etcd3-py

Sync Client

>>> from etcd3 import Client
>>> client = Client('127.0.0.1', 2379, cert=(CERT_PATH, KEY_PATH), verify=CA_PATH)
>>> 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

Start a single-node etcd using docker

export NODE1=0.0.0.0
export ETCD_VER=v3.3
docker run -d \
-p 2379:2379 \
-p 2380:2380 \
--volume=/tmp/etcd3-data:/etcd-data \
--name etcd3 quay.io/coreos/etcd:$ETCD_VER \
/usr/local/bin/etcd \
--data-dir=/etcd-data --name node1 \
--initial-advertise-peer-urls http://${NODE1}:2380 --listen-peer-urls http://${NODE1}:2380 \
--advertise-client-urls http://${NODE1}:2379 --listen-client-urls http://${NODE1}:2379 \
--initial-cluster node1=http://${NODE1}:2380

FAQ

Q: authentication seems not working? Try calling api of a auth-enabled etcd server returned error "ErrUserEmpty error:'etcdserver: user name is empty'"

A: Take a look at #41, currently etcd3-py dose not authenticate automatically, you need to call client.auth() by yourself.

TODO

  • human friendly middle level apis
  • able to expose json or raw response to user
  • add election api
  • benchmark
  • python-etcd(etcd v2) compatible client
  • etcd browser
  • support etcd v3.4.x
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].