Python client for etcd v3 (Using gRPC-JSON-Gateway)
Notice: The authentication header through gRPC-JSON-Gateway only supported in etcd v3.3.0+
Install
$ pip install 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
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.
To install etcd3-py, run this command in your terminal:
$ pip install etcd3
This is the preferred method to install etcd3-py, as it will always install the most recent stable release.
If you don’t have pip installed, this Python installation guide can guide you through the process.
The sources for etcd3-py can be downloaded from the Github repo.
You can either clone the public repository:
$ git clone git://github.com/revolution1/etcd3
Or download the tarball:
$ curl -OL https://github.com/revolution1/etcd3/tarball/master
Once you have a copy of the source, you can install it with:
$ python setup.py install
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Report bugs at https://github.com/revolution1/etcd3/issues.
If you are reporting a bug, please include:
Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.
Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.
etcd3-py could always use more documentation, whether as part of the official etcd3-py docs, in docstrings, or even on the web in blog posts, articles, and such.
The best way to send feedback is to file an issue at https://github.com/revolution1/etcd3/issues.
If you are proposing a feature:
Ready to contribute? Here’s how to set up etcd3 for local development.
Fork the etcd3 repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/etcd3.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ mkvirtualenv etcd3
$ cd etcd3/
$ python setup.py develop
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:
$ flake8 etcd3 tests
$ python setup.py test or py.test
$ tox
To get flake8 and tox, just pip install them into your virtualenv.
Commit your changes and push your branch to GitHub:
$ git add .
$ git commit -m "Your detailed description of your changes."
$ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Before you submit a pull request, check that it meets these guidelines:
None yet. Why not be the first?
You can try it at dev environment
synchronous client
etcd3.baseclient.
BaseModelizedStreamResponse
[source]¶Bases: object
Model of a stream response
etcd3.baseclient.
BaseClient
(host='127.0.0.1', port=2379, protocol='http', cert=(), verify=None, timeout=None, headers=None, user_agent=None, pool_size=30, username=None, password=None, token=None, server_version='3.3.0', cluster_version='3.3.0')[source]¶Bases: etcd3.apis.auth.AuthAPI
, etcd3.apis.cluster.ClusterAPI
, etcd3.apis.kv.KVAPI
, etcd3.apis.lease.LeaseAPI
, etcd3.apis.maintenance.MaintenanceAPI
, etcd3.apis.watch.WatchAPI
, etcd3.apis.extra.ExtraAPI
, etcd3.apis.lock.LockAPI
__init__
(host='127.0.0.1', port=2379, protocol='http', cert=(), verify=None, timeout=None, headers=None, user_agent=None, pool_size=30, username=None, password=None, token=None, server_version='3.3.0', cluster_version='3.3.0')[source]¶Initialize self. See help(type(self)) for accurate signature.
baseurl
¶Returns: | baseurl from protocol, host, self |
---|
call_rpc
(method, data=None, stream=False, encode=True, raw=False, **kwargs)[source]¶call ETCDv3 RPC and return response object
Parameters: |
|
---|---|
Returns: | Etcd3RPCResponseModel or Etcd3StreamingResponse |
auth
(username=None, password=None)[source]¶call auth.authenticate and save the token
Parameters: |
|
---|
Lease
(ttl, ID=0, new=True)[source]¶Initialize a Lease
Parameters: |
|
---|
Watcher
(key=None, range_end=None, max_retries=-1, start_revision=None, progress_notify=None, prev_kv=None, prefix=None, all=None, no_put=False, no_delete=False)[source]¶Initialize a Watcher
Parameters: |
|
---|---|
Returns: | Watcher |
synchronous client
etcd3.client.
ModelizedStreamResponse
(client, method, resp, decode=True)[source]¶Bases: etcd3.baseclient.BaseModelizedStreamResponse
Model of a stream response
raw
¶etcd3.client.
iter_response
(resp)[source]¶yield response content by every json object we don’t yield by line, because the content of etcd’s gRPC-JSON-Gateway stream response does not have a delimiter between each object by default. (only one line)
https://github.com/grpc-ecosystem/grpc-gateway/pull/497/files
Parameters: | resp – Response |
---|---|
Returns: | dict |
etcd3.client.
Client
(host='127.0.0.1', port=2379, protocol='http', cert=(), verify=None, timeout=None, headers=None, user_agent=None, pool_size=30, username=None, password=None, token=None, max_retries=0, server_version='3.3.0', cluster_version='3.3.0')[source]¶Bases: etcd3.baseclient.BaseClient
__init__
(host='127.0.0.1', port=2379, protocol='http', cert=(), verify=None, timeout=None, headers=None, user_agent=None, pool_size=30, username=None, password=None, token=None, max_retries=0, server_version='3.3.0', cluster_version='3.3.0')[source]¶Parameters: | max_retries – The maximum number of retries each connection
should attempt. Note, this applies only to failed DNS lookups, socket
connections and connection timeouts, never to requests where data has
made it to the server. By default, Requests does not retry failed
connections. If you need granular control over the conditions under
which we retry a request, import urllib3’s Retry class and pass
that instead. |
---|
call_rpc
(method, data=None, stream=False, encode=True, raw=False, **kwargs)[source]¶call ETCDv3 RPC and return response object
Parameters: |
|
---|---|
Returns: | Etcd3RPCResponseModel or Etcd3StreamingResponse |
asynchronous client
etcd3.aio_client.
ModelizedStreamResponse
(client, method, resp, decode=True)[source]¶Bases: etcd3.baseclient.BaseModelizedStreamResponse
Model of a stream response
connection
¶resp_iter
¶etcd3.aio_client.
ResponseIter
(resp)[source]¶Bases: object
yield response content by every json object we don’t yield by line, because the content of etcd’s gRPC-JSON-Gateway stream response does not have a delimiter between each object by default. (only one line)
https://github.com/grpc-ecosystem/grpc-gateway/pull/497/files
Parameters: | resp – aiohttp.ClientResponse |
---|---|
Returns: | dict |
etcd3.aio_client.
AioClient
(host='127.0.0.1', port=2379, protocol='http', cert=(), verify=None, timeout=None, headers=None, user_agent=None, pool_size=30, username=None, password=None, token=None, server_version='3.3.0', cluster_version='3.3.0')[source]¶Bases: etcd3.baseclient.BaseClient
__init__
(host='127.0.0.1', port=2379, protocol='http', cert=(), verify=None, timeout=None, headers=None, user_agent=None, pool_size=30, username=None, password=None, token=None, server_version='3.3.0', cluster_version='3.3.0')[source]¶Initialize self. See help(type(self)) for accurate signature.
call_rpc
(method, data=None, stream=False, encode=True, raw=False, **kwargs)[source]¶call ETCDv3 RPC and return response object
Parameters: |
|
---|---|
Returns: | Etcd3RPCResponseModel or Etcd3StreamingResponse |
Sync lease util
etcd3.stateful.lease.
Lease
(client, ttl, ID=0, new=True)[source]¶Bases: object
__init__
(client, ttl, ID=0, new=True)[source]¶Parameters: |
|
---|
ID
¶Property: the id of the granted lease
Returns: | int |
---|
grant
()[source]¶Grant the lease if new is set to False or it just inherit the lease of the specified id
When granting new lease if ID is set to 0, the lessor will chooses an ID.
time_to_live
(keys=False)[source]¶Retrieves lease information.
Parameters: | keys (bool) – whether return the keys that attached to the lease |
---|
refresh
()¶Call keepalive for once to refresh the ttl of the lease
keepalive
(keep_cb=None, cancel_cb=None)[source]¶Start a daemon thread to constantly keep the lease alive
Parameters: |
|
---|
etcd3.stateful.transaction.
Txn
(client, compare=None, success=None, failure=None)[source]¶Bases: object
Txn (transaction) util provides a human friendly way to build kv.txn request Usage:
>>> from etcd3 import Client, Txn
>>> txn = Txn(Client())
>>> 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)))])
From google paxosdb paper:
Our implementation hinges around a powerful primitive which we call MultiOp. All other database operations except for iteration are implemented as a single call to MultiOp. A MultiOp is applied atomically and consists of three components:
__init__
(client, compare=None, success=None, failure=None)[source]¶Parameters: |
|
---|
compare
(compareOp)[source]¶Add a test to the transaction guard component
Parameters: | compareOp – TxnCompareOp |
---|---|
Returns: | self |
If
(compareOp)¶Add a test to the transaction guard component
Parameters: | compareOp – TxnCompareOp |
---|---|
Returns: | self |
Then
(successOp)¶Add a database operation to the transaction success component
Else
(failureOp)¶Add a database operation to the transaction failure component
key
(key=None, range_end=None, prefix=None, all=None)[source]¶Get the TxnCompareOp of a key
Parameters: |
|
---|---|
Returns: | TxnCompareOp |
range
(key=None, range_end=None, limit=0, revision=None, serializable=False, keys_only=False, count_only=False, min_mod_revision=None, max_mod_revision=None, min_create_revision=None, max_create_revision=None, sort_order=<RangeRequestSortOrder.NONE: 'NONE'>, sort_target=<RangeRequestSortTarget.KEY: 'KEY'>, prefix=None, all=None)[source]¶Operation of keys in the range from the key-value store.
Parameters: |
|
---|
put
(key, value, lease=0, prev_kv=False, ignore_value=False, ignore_lease=False)[source]¶Operation of puts the given key into the key-value store. A put request increments the revision of the key-value store and generates one event in the event history.
Parameters: |
|
---|
delete
(key=None, range_end=None, prev_kv=False, prefix=None, all=None)[source]¶Operation of deletes the given range from the key-value store. A delete request increments the revision of the key-value store and generates a delete event in the event history for every deleted key.
Parameters: |
|
---|
etcd3.stateful.transaction.
TxnCompareOp
(key, range_end=None)[source]¶Bases: object
The operator of transaction’s compare part
value
¶represents the value of the key
mod
¶represents the mod_revision of the key
version
¶represents the version of the key
create
¶represents the create_revision of the key
lease
¶represents the lease_id of the key
etcd3.stateful.watch.
KeyValue
(data)[source]¶Bases: object
Model of the key-value of the event
etcd3.stateful.watch.
Event
(data, header=None)[source]¶Bases: etcd3.stateful.watch.KeyValue
Watch event
etcd3.stateful.watch.
Watcher
(client, max_retries=-1, key=None, range_end=None, start_revision=None, progress_notify=None, prev_kv=None, prefix=None, all=None, no_put=False, no_delete=False)[source]¶Bases: object
__init__
(client, max_retries=-1, key=None, range_end=None, start_revision=None, progress_notify=None, prev_kv=None, prefix=None, all=None, no_put=False, no_delete=False)[source]¶Initialize a watcher
Parameters: |
|
---|
set_default_timeout
(timeout)[source]¶Set the default timeout of watch request
Parameters: | timeout (int) – timeout in seconds |
---|
get_filter
(filter)[source]¶Get the event filter function
Parameters: | filter (callable or regex string or EventType or None) – will generate a filter function from this param |
---|---|
Returns: | callable |
onEvent
(filter_or_cb, cb=None)[source]¶Add a callback to a event that matches the filter
If only one param is given, which is filter_or_cb, it will be treated as the callback. If any event comes, it will be called.
Parameters: |
|
---|
dispatch_event
(event)[source]¶Find the callbacks, if callback’s filter fits this event, call the callback
Parameters: | event – Event |
---|
cancel
()¶Stop watching, close the watch stream and exit the daemon thread
etcd3.stateful.lock.
Lock
(client, lock_name, lock_ttl=60, reentrant=None, lock_prefix='_locks')[source]¶Bases: object
Locking recipe for etcd, inspired by the kazoo recipe for zookeeper
DEFAULT_LOCK_TTL
= 60¶HOST
= 'host'¶PROCESS
= 'process'¶THREAD
= 'thread'¶__init__
(client, lock_name, lock_ttl=60, reentrant=None, lock_prefix='_locks')[source]¶Parameters: |
|
---|
is_acquired
¶if the lock is acquired
acquired
¶if the lock is acquired
acquire
(block=True, lock_ttl=None, timeout=None, delete_key=True)[source]¶Acquire the lock.
Parameters: |
|
---|
etcd3.apis.auth.
AuthAPI
[source]¶Bases: etcd3.apis.base.BaseAPI
authenticate
(name, password)[source]¶Authenticate processes an authenticate request.
Parameters: |
|
---|
role_add
(name)[source]¶RoleAdd adds a new role.
Parameters: | name (str) – name is the name of the role to add to the authentication system. |
---|
role_grant_permission
(name, key=None, permType=<authpbPermissionType.READ: 'READ'>, range_end=None, prefix=False, all=False)[source]¶RoleGrantPermission grants a permission of a specified key or range to a specified role.
Parameters: |
|
---|
role_revoke_permission
(role, key=None, range_end=None, prefix=False, all=False)[source]¶RoleRevokePermission revokes a key or range permission of a specified role.
Parameters: |
|
---|
user_add
(name, password)[source]¶UserAdd adds a new user.
Parameters: |
|
---|
user_change_password
(name, password)[source]¶UserChangePassword changes the password of a specified user.
Parameters: |
|
---|
user_delete
(name)[source]¶UserDelete deletes a specified user.
Parameters: | name (str) – name is the name of the user to delete. |
---|
user_get
(name)[source]¶UserGet gets detailed user information.
Parameters: | name (str) – name is the name of the user to get. |
---|
etcd3.apis.cluster.
ClusterAPI
[source]¶Bases: etcd3.apis.base.BaseAPI
member_add
(peerURLs)[source]¶MemberAdd adds a member into the cluster.
Parameters: | peerURLs (list of str) – peerURLs is the list of URLs the added member will use to communicate with the cluster. |
---|
etcd3.apis.kv.
KVAPI
[source]¶Bases: etcd3.apis.base.BaseAPI
compact
(revision, physical=False)[source]¶Compact compacts the event history in the etcd key-value store. The key-value store should be periodically compacted or the event history will continue to grow indefinitely.
Parameters: |
|
---|
delete_range
(key=None, range_end=None, prev_kv=False, prefix=False, all=False, txn_obj=False)[source]¶DeleteRange deletes the given range from the key-value store. A delete request increments the revision of the key-value store and generates a delete event in the event history for every deleted key.
Parameters: |
|
---|
put
(key, value, lease=0, prev_kv=False, ignore_value=False, ignore_lease=False, txn_obj=False)[source]¶Put puts the given key into the key-value store. A put request increments the revision of the key-value store and generates one event in the event history.
Parameters: |
|
---|
range
(key=None, range_end=None, limit=0, revision=None, serializable=False, keys_only=False, count_only=False, min_mod_revision=None, max_mod_revision=None, min_create_revision=None, max_create_revision=None, sort_order=<RangeRequestSortOrder.NONE: 'NONE'>, sort_target=<RangeRequestSortTarget.KEY: 'KEY'>, prefix=False, all=False, txn_obj=False)[source]¶Range gets the keys in the range from the key-value store.
Parameters: |
|
---|
txn
(compare, success, failure)[source]¶Txn processes multiple requests in a single transaction. A txn request increments the revision of the key-value store and generates events with the same revision for every completed request. It is not allowed to modify the same key several times within one txn.
Parameters: |
|
---|
etcd3.apis.lease.
LeaseAPI
[source]¶Bases: etcd3.apis.base.BaseAPI
lease_revoke
(ID)[source]¶LeaseRevoke revokes a lease. All keys attached to the lease will expire and be deleted.
Parameters: | ID (int) – ID is the lease ID to revoke. When the ID is revoked, all associated keys will be deleted. |
---|
lease_time_to_live
(ID, keys=False)[source]¶LeaseTimeToLive retrieves lease information.
Parameters: |
|
---|
lease_grant
(TTL, ID=0)[source]¶LeaseGrant creates a lease which expires if the server does not receive a keepAlive within a given time to live period. All keys attached to the lease will be expired and deleted if the lease expires. Each expired key generates a delete event in the event history.
Parameters: |
|
---|
lease_keep_alive
(data)[source]¶PLEASE USE THE TRANSACTION UTIL
LeaseKeepAlive keeps the lease alive by streaming keep alive requests from the client to the server and streaming keep alive responses from the server to the client.
Parameters: | data – ID stream inputs of the lease to keep alive. which not works for now |
---|
lease_keep_alive_once
(ID)[source]¶this api only send keep alive once instead of streaming send multiple IDs
LeaseKeepAlive keeps the lease alive by streaming keep alive requests from the client to the server and streaming keep alive responses from the server to the client.
Parameters: | ID (int) – ID is the lease ID for the lease to keep alive. |
---|
etcd3.apis.lock.
LockAPI
[source]¶Bases: etcd3.apis.base.BaseAPI
lock
(name, lease=0)[source]¶Lock acquires a distributed shared lock on a given named lock. On success, it will return a unique key that exists so long as the lock is held by the caller. This key can be used in conjunction with transactions to safely ensure updates to etcd only occur while holding lock ownership. The lock is held until Unlock is called on the key or the lease associate with the owner expires.
Parameters: |
|
---|
unlock
(key)[source]¶Unlock takes a key returned by Lock and releases the hold on lock. The next Lock caller waiting for the lock will then be woken up and given ownership of the lock.
Parameters: |
|
---|
etcd3.apis.maintenance.
MaintenanceAPI
[source]¶Bases: etcd3.apis.base.BaseAPI
alarm
(memberID, action=<AlarmRequestAlarmAction.GET: 'GET'>, alarm=<etcdserverpbAlarmType.NONE: 'NONE'>)[source]¶Alarm activates, deactivates, and queries alarms regarding cluster health.
Parameters: |
|
---|
alarm_get
(memberID, alarm)[source]¶Queries alarms regarding cluster health.
Parameters: |
|
---|
alarm_activate
(memberID, alarm)[source]¶Activates alarms regarding cluster health.
Parameters: |
|
---|
alarm_deactivate
(memberID, alarm)[source]¶Deactivates alarms regarding cluster health.
Parameters: |
|
---|
hash
()[source]¶Hash returns the hash of the local KV state for consistency checking purpose. This is designed for testing; do not use this in production when there are ongoing transactions.
etcd3.apis.watch.
WatchAPI
[source]¶Bases: etcd3.apis.base.BaseAPI
watch
(create_request=None, cancel_request=None, **kwargs)[source]¶PLEASE USE THE WATCH UTIL
Watch watches for events happening or that have happened. Both input and output are streams; the input stream is for creating and canceling watchers and the output stream sends events. One watch RPC can watch on multiple key ranges, streaming events for several watches at once. The entire event history can be watched starting from the last compaction revision.
Parameters: |
|
---|
watch_create
(key=None, range_end=None, start_revision=None, progress_notify=None, prev_kv=None, prefix=False, all=False, no_put=False, no_delete=False, **kwargs)[source]¶WatchCreate creates a watch stream on given key or key_range
Parameters: |
|
---|
watch_cancel
(watch_id, **kwargs)[source]¶NOT SUPPORTED UNDER ETCD 3.3-
https://github.com/coreos/etcd/pull/9065
WatchCancel cancels a watch stream
Parameters: | watch_id (int) – watch_id is the watcher id to cancel so that no more events are transmitted. |
---|
from github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes/error.go
etcd3.errors.go_etcd_rpctypes_error.
error_desc
(e)¶etcd3.errors.go_etcd_rpctypes_error.
ErrUnknownError
(error, code, status, response=None)[source]¶etcd3.errors.go_etcd_rpctypes_error.
ErrEmptyKey
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrKeyNotFound
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrValueProvided
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrLeaseProvided
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrTooManyOps
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrDuplicateKey
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrCompacted
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrFutureRev
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrNoSpace
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrLeaseNotFound
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrLeaseExist
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrLeaseTTLTooLarge
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrMemberExist
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrPeerURLExist
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrMemberNotEnoughStarted
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrMemberBadURLs
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrMemberNotFound
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrRequestTooLarge
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrTooManyRequests
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrRootUserNotExist
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrRootRoleNotExist
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrUserAlreadyExist
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrUserEmpty
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrUserNotFound
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrRoleAlreadyExist
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrRoleNotFound
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrAuthFailed
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrPermissionDenied
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrRoleNotGranted
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrPermissionNotGranted
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrAuthNotEnabled
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrInvalidAuthToken
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrInvalidAuthMgmt
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrNoLeader
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrNotLeader
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrNotCapable
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrStopped
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrTimeout
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrTimeoutDueToLeaderFail
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrTimeoutDueToConnectionLost
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrUnhealthy
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶etcd3.errors.go_etcd_rpctypes_error.
ErrCorrupt
(error=None, code=None, status=None, response=None)¶Bases: etcd3.errors.go_etcd_rpctypes_error.Etcd3Exception
__init__
(error=None, code=None, status=None, response=None)¶as_dict
()¶from golang grpc lib: google.golang.org/grpc/codes
etcd3.errors.go_grpc_codes.
GRPCCode
[source]¶Bases: object
OK
= 0¶Canceled
= 1¶Unknown
= 2¶InvalidArgument
= 3¶DeadlineExceeded
= 4¶NotFound
= 5¶AlreadyExists
= 6¶PermissionDenied
= 7¶ResourceExhausted
= 8¶FailedPrecondition
= 9¶Aborted
= 10¶OutOfRange
= 11¶Unimplemented
= 12¶Internal
= 13¶DataLoss
= 15¶Unauthenticated
= 16¶etcd3.models.
AlarmRequestAlarmAction
¶Bases: etcd3.models.EtcdModel
, enum.Enum
ref: #/definitions/AlarmRequestAlarmAction
default: GET
ACTIVATE
= 'ACTIVATE'¶DEACTIVATE
= 'DEACTIVATE'¶GET
= 'GET'¶etcd3.models.
CompareCompareResult
¶Bases: etcd3.models.EtcdModel
, enum.Enum
ref: #/definitions/CompareCompareResult
default: EQUAL
EQUAL
= 'EQUAL'¶GREATER
= 'GREATER'¶LESS
= 'LESS'¶NOT_EQUAL
= 'NOT_EQUAL'¶etcd3.models.
CompareCompareTarget
¶Bases: etcd3.models.EtcdModel
, enum.Enum
ref: #/definitions/CompareCompareTarget
default: VERSION
CREATE
= 'CREATE'¶LEASE
= 'LEASE'¶MOD
= 'MOD'¶VALUE
= 'VALUE'¶VERSION
= 'VERSION'¶etcd3.models.
EventEventType
¶Bases: etcd3.models.EtcdModel
, enum.Enum
ref: #/definitions/EventEventType
default: PUT
DELETE
= 'DELETE'¶PUT
= 'PUT'¶etcd3.models.
RangeRequestSortOrder
¶Bases: etcd3.models.EtcdModel
, enum.Enum
ref: #/definitions/RangeRequestSortOrder
default: NONE
ASCEND
= 'ASCEND'¶DESCEND
= 'DESCEND'¶NONE
= 'NONE'¶etcd3.models.
RangeRequestSortTarget
¶Bases: etcd3.models.EtcdModel
, enum.Enum
ref: #/definitions/RangeRequestSortTarget
default: KEY
CREATE
= 'CREATE'¶KEY
= 'KEY'¶MOD
= 'MOD'¶VALUE
= 'VALUE'¶VERSION
= 'VERSION'¶etcd3.models.
WatchCreateRequestFilterType
¶Bases: etcd3.models.EtcdModel
, enum.Enum
ref: #/definitions/WatchCreateRequestFilterType
default: NOPUT
NODELETE
= 'NODELETE'¶NOPUT
= 'NOPUT'¶etcd3.models.
authpbPermissionType
¶Bases: etcd3.models.EtcdModel
, enum.Enum
ref: #/definitions/authpbPermissionType
default: READ
READ
= 'READ'¶READWRITE
= 'READWRITE'¶WRITE
= 'WRITE'¶etcd3.models.
etcdserverpbAlarmType
¶Bases: etcd3.models.EtcdModel
, enum.Enum
ref: #/definitions/etcdserverpbAlarmType
default: NONE
CORRUPT
= 'CORRUPT'¶NONE
= 'NONE'¶NOSPACE
= 'NOSPACE'¶etcd3.swagger_helper.
swagger_escape
(s)[source]¶/ and ~ are special characters in JSON Pointers, and need to be escaped when used literally (for example, in path names).
etcd3.swagger_helper.
SwaggerSpec
(spec)[source]¶Bases: object
Parse the swagger spec of gRPC-JSON-Gateway to object tree
ref
(ref_path)[source]¶get the node object from absolute reference
Parameters: | ref_path – str |
---|---|
Returns: | SwaggerNode |
example:
>>> spec.ref('#/definitions/etcdserverpbAlarmResponse')
SwaggerSchema(ref='#/definitions/etcdserverpbAlarmResponse')
getPath
(key)[source]¶get a SwaggerPath instance of the path
Parameters: | key (SwaggerNode or str) – receive a SwaggerNode or a $ref string of schema |
---|---|
Return type: | SwaggerNode |
getSchema
(key)[source]¶get a SwaggerSchema instance of the schema
Parameters: | key (SwaggerNode or str) – receive a SwaggerNode or a $ref string of schema |
---|---|
Return type: | SwaggerNode |
getEnum
(key)[source]¶get a Enum instance of the schema
Parameters: | key (SwaggerNode or str) – receive a SwaggerNode or a $ref string of schema |
---|---|
Return type: | SwaggerNode |
etcd3.swagger_helper.
SwaggerNode
(root, node, path, parent=None, name=None)[source]¶Bases: object
the node of swagger_spec object
can represent a path, a schema or a ordinary node
as a schema, it can generate a model object of the definition, decode or encode the payload
__init__
(root, node, path, parent=None, name=None)[source]¶Initialize self. See help(type(self)) for accurate signature.
encode
(data)[source]¶encode the data to as the schema defined
Parameters: | data – data to encode |
---|---|
Returns: | encoded data |
etcd3.utils.
lru_cache
(maxsize=100)[source]¶Least-recently-used cache decorator.
If maxsize is set to None, the LRU features are disabled and the cache can grow without bound.
Arguments to the cached function must be hashable.
View the cache statistics named tuple (hits, misses, maxsize, currsize) with f.cache_info(). Clear the cache and statistics with f.cache_clear(). Access the underlying function with f.__wrapped__.
See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used
etcd3.utils.
memoize
(fn)[source]¶Decorator. Caches a function’s return value each time it is called. If called later with the same arguments, the cached value is returned (not reevaluated).
etcd3.utils.
memoize_in_object
(fn)[source]¶Decorator. Caches a method’s return value each time it is called, in the object instance If called later with the same arguments, the cached value is returned (not reevaluated).
etcd3.utils.
check_param
(at_least_one_of=None, at_most_one_of=None)[source]¶check if at least/most one of params is given
>>> @check_param(at_least_one_of=['a', 'b'])
>>> def fn(a=None, b=None):
... pass
>>> fn()
TypeError: fn() requires at least one argument of a,b
etcd3.utils.
cached_property
(func)[source]¶Bases: object
A property that is only computed once per instance and then replaces itself with an ordinary attribute. Deleting the attribute resets the property.
Source: https://github.com/bottlepy/bottle/blob/0.11.5/bottle.py#L175
etcd3.utils.
iter_json_string
(chunk, start=0, lb=123, rb=125, resp=None, err_cls=<class 'ValueError'>)[source]¶