etcpy

etcpy

etcpy: Interface to etcd for python

class etcpy.Etcd(addr, port=4001, client_cert=None, server_ca=None, secure=True)[source]

Represents an Etcd cluster with which operations can be performed against

auto_create(key, val, dir=False, ttl=None)[source]

Create a key in a directory and let etcd handle name generation

can be handy to avoid race conditions when creatign key names client side The generated keys are unique and will not be in conflict with each other

Parameters:
  • key (str) – The directory to create the key in
  • val – The value to be written to the key
  • dir (bool) – Should the created key be a directory
  • ttl (int) – The expiry time (in seconds) of the newly created entry
create(key, val, ttl=None, dir=False, old_value=None, old_index=None)[source]

Only create a key if it did not previously exist

This is a convience function around Etcd.set()

Parameters:
  • key (str) – The key to set
  • val – The value to set
  • ttl (int) – The expiry time (in seconds) of the newly created entry
  • dir (bool) – Should a directory be created
  • old_value – The old value for compare and swap operations
  • old_index (int) – The old index for compare and swap operations
delete(key, dir=False, recursive=False)[source]

Delete a key from etcd

Parameters:
  • key (str) – The key to delete
  • dir (bool) – Must be set to True to delete directories
  • recursive (bool) – Recursively delete keys under the specified directory
get(key, recursive=False, wait=None, index=None)[source]

Retrive a value from etcd

Parameters:
  • key (str) – The key to lookup
  • recursive (bool) – Retrive the specified key and all its subkeys (dir only)
  • wait (bool) – Wait for a change on the specified key (can be used with recursive)
  • index (int) – If supplied along with wait=True, return/wait on changes since the index specified and not the latest value
make_dir(key, ttl=None)[source]

Make a directory

This is a convience function around Etcd.set()

Parameters:
  • key (str) – The directory to create the key in
  • ttl (int) – The expiry time (in seconds) of the newly created entry
set(key, val, ttl=None, dir=False, old_value=None, old_index=None, exists=None)[source]

Set a value in etcd

Parameters:
  • key (str) – The key to set
  • val – The value to set
  • ttl (int) – The expiry time (in seconds) of the newly created entry
  • dir (bool) – Should a directory be created
  • old_value – The old value for compare and swap operations
  • old_index (int) – The old index for compare and swap operations
  • exists (bool) – Should the key be created if it previously exists? use None for “Do not care”
update(key, val, ttl=None, dir=False, old_value=None, old_index=None)[source]

Only update a value, do not create it if it does not exist

This is a convience function around Etcd.set()

Parameters:
  • key (str) – The key to set
  • val – The value to set
  • ttl (int) – The expiry time (in seconds) of the newly created entry
  • dir (bool) – Should a directory be created
  • old_value – The old value for compare and swap operations
  • old_index (int) – The old index for compare and swap operations
watch(key, recursive=False, index=None)[source]

Block and Watch a file or directory for changes

This is a convience function around Etcd.get()

Returns the change that was made

Parameters:
  • key (str) – The directory to create the key in
  • recursive (bool) – Retrive the specified key and all its subkeys (dir only)
  • index (int) – If supplied along with wait=True, return/wait on changes since the index specified and not the latest value
class etcpy.EtcdDir[source]

Represents a result back from an Etcd server for a node representing a directory (eg a GET)

Parameters:
  • key (str) – The key this object represents
  • nodes (EtcdValue) – A list of EtcdDir and EtcdValue objects representing the contents of the directory
  • modified_index (int) – The modifiedIndex filed returned by the server
  • created_index (int) – The createdIndex field returned by the server
  • ttl (int) – If not None, the amount of seconds until this key expires
  • expiration (str) – The time that this key will expire
dir = True
class etcpy.EtcdValue[source]

Represents a value stored on the server

Parameters:
  • key (str) – The key this object represents
  • value – The raw value stored on the server
  • modified_index (int) – The modifiedIndex filed returned by the server
  • created_index (int) – The createdIndex field returned by the server
  • ttl (int) – If not None, the amount of seconds until this key expires
  • expiration (str) – The time that this key will expire
dir = False
etcpy.join(start, *path)[source]

Join 2 or more path components, if any component begins with ‘/’, this will discard input up to that point and replace it with the tokens from that point forward

>>> join('temp1', 'temp2')
'temp1/temp2'
>>> join('temp1', '/temp2')
'/temp2'
etcpy.main()[source]
etcpy.make_query_string(vals)[source]

Take a dictonary of query string values and convert them to a string for appending to a url

Parameters:vals (dict) – The dict of values to be converted
Returns:string to append to the url

Table Of Contents

Previous topic

Welcome to etcpy’s documentation!

Next topic

Errors

This Page