Skip to content
forked from vdloo/consul-kv

Python 3 client for the Consul key/value store

License

Notifications You must be signed in to change notification settings

sronsiek/consul-kv

 
 

Repository files navigation

Build Status

consul-kv

Python 3 client for the consul key/value store.

Installation

Get it from pypi

pip install consul_kv

Or install directly from GitHub

pip install git+https://github.com/vdloo/consul-kv.git@master#egg=consul_kv

Note: this library is rolling release and does not employ semantic versioning.

Do not depend on the master or update to a new release without checking the changelog, there may be breaking changes. If you want to ensure nothing breaks when a new version is released, pin your pip requirements like for example consul_kv==0.7.2.

Usage

Instantiate a client

from consul_kv import Connection
conn = Connection(endpoint='http://localhost:8500/v1/')

PUT a key

conn.put('the/key', 'the_value')

Atomically PUT a list of keys and values (transaction).

mapping = {
    'a/key': 'a_value',
    'another/k': 'another_value'
}
conn.put_mapping(mapping)

Atomically PUT a dictionary

dictionary = {
    'a': {
        'key': 'a_value'
    },
    'another': {
        'k': 'another_value'
    }
}
conn.put_dict(dictionary)

GET a key

conn.get('the/key')
{'the/key': 'the_value'}

GET all keys under a path

conn.get('the', recurse=True)
{'the/key': 'the_value', 'the/other_key': 'the_other_value'}

# or
conn.get_mapping('the')
{'the/key': 'the_value', 'the/other_key': 'the_other_value'}

GET a dictionary based on all keys under a path

conn.get_dict('the')
{'the': {'key': 'the_value', 'other_key': 'the_other_value'}}

DELETE a key

conn.delete('the/key')

DELETE all keys under a path

conn.delete('the', recurse=True)

GET information about the agent from the Agent HTTP API

conn.get_meta('agent/self')

Development

Create a virtualenv

mkvirtualenv -a $(pwd) -p /usr/bin/python3 consul_kv
echo "PYTHONPATH=`pwd`" >> $VIRTUAL_ENV/bin/postactivate
pip3 install pip --upgrade
pip3 install -r requirements/development.txt

Run the tests

./runtests.sh -1

About

Python 3 client for the Consul key/value store

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 98.2%
  • Shell 1.8%