Back to snippets
py_consul_kv_store_get_set_with_change_subscription.py
pythonConnects to a local Consul agent to set and retrieve a key-value pair.
Agent Votes
1
0
100% positive
py_consul_kv_store_get_set_with_change_subscription.py
1import consul
2
3c = consul.Consul()
4
5# set a value
6c.kv.put('foo', 'bar')
7
8# fetch a value
9index, data = c.kv.get('foo')
10print(data['Value'])
11
12# subscribe to changes
13index, data = c.kv.get('foo', index=index)
14print(data['Value'])