File: README.rst

package info (click to toggle)
python-etcd3 0.12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 640 kB
  • sloc: python: 2,111; makefile: 165
file content (84 lines) | stat: -rw-r--r-- 2,001 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
============
python-etcd3
============


Python client for the etcd API v3, supported under python 2.7, 3.4 and 3.5.

**Warning: the API is mostly stable, but may change in the future**

If you're interested in using this library, please get involved.

* Free software: Apache Software License 2.0
* Documentation: https://python-etcd3.readthedocs.io.

Basic usage:

.. code-block:: python

    import etcd3

    etcd = etcd3.client()

    etcd.get('foo')
    etcd.put('bar', 'doot')
    etcd.delete('bar')

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

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

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

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

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

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

    # cancel watch
    etcd.cancel_watch(watch_id)

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

    watch_id = etcd.add_watch_prefix_callback("/doot/watch/prefix/", watch_callback)

    # cancel watch
    etcd.cancel_watch(watch_id)