summaryrefslogtreecommitdiff
path: root/README.rst
blob: bcb6a51be3a9e50e0a87616bc0aa4e77969ec885 (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
python-etcd documentation
=========================

A python client for Etcd https://github.com/coreos/etcd

Official documentation: http://python-etcd.readthedocs.org/

.. image:: https://api.travis-ci.org/jplana/python-etcd.png
   :target: https://travis-ci.org/jplana/python-etcd

Installation
------------

Pre-requirements
~~~~~~~~~~~~~~~~

Install etcd

From source
~~~~~~~~~~~

.. code:: bash

    $ python setup.py install

Usage
-----

Create a client object
~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

    import etcd

    client = etcd.Client() # this will create a client against etcd server running on localhost on port 4001
    client = etcd.Client(port=4002)
    client = etcd.Client(host='127.0.0.1', port=4003)
    client = etcd.Client(host='127.0.0.1', port=4003, allow_redirect=False) # wont let you run sensitive commands on non-leader machines, default is true

Set a key
~~~~~~~~~

.. code:: python

    client.set('/nodes/n1', 1)
    # with ttl
    client.set('/nodes/n2', 2, ttl=4)  # sets the ttl to 4 seconds

Get a key
~~~~~~~~~

.. code:: python

    client.get('/nodes/n2').value

Delete a key
~~~~~~~~~~~~

.. code:: python

    client.delete('/nodes/n1')

Test and set
~~~~~~~~~~~~

.. code:: python

    client.test_and_set('/nodes/n2', 2, 4) # will set /nodes/n2 's value to 2 only if its previous value was 4

Watch a key
~~~~~~~~~~~

.. code:: python

    client.watch('/nodes/n1') # will wait till the key is changed, and return once its changed

List sub keys
~~~~~~~~~~~~~

.. code:: python

    # List nodes in the cluster
    client.get('/nodes')

    # List keys under /subtree
    client.get('/subtree')

Get machines in the cluster
~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

    client.machines

Get leader of the cluster
~~~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

    client.leader

Development setup
-----------------

To create a buildout,

.. code:: bash

    $ python bootstrap.py
    $ bin/buildout

to test you should have etcd available in your system path:

.. code:: bash

    $ bin/test

to generate documentation,

.. code:: bash

    $ cd docs
    $ make

Release HOWTO
-------------

To make a release

    1) Update release date/version in NEWS.txt and setup.py
    2) Run 'python setup.py sdist'
    3) Test the generated source distribution in dist/
    4) Upload to PyPI: 'python setup.py sdist register upload'