Skip to main content

A Client library for the Consul

Project description

Consulate is a Python client library and set of application for the Consul service discovery and configuration system.

Version Downloads Status Coverage License

Installation

Consulate is available via via pypi and can be installed with easy_install or pip:

pip install consulate

Command Line Utilities

Consulate comes with two command line utilities that make working with Consul easier from a management perspective. The consulate application provides a cli wrapper for common tasks performed.

The passport application has been moved to a stand-alone application and is available at https://github.com/gmr/passport.

consulate

The consulate application provides a CLI interface for registering a service, backing up and restoring the contents of the KV database, and actions for getting, setting, and deleting keys from the KV database.

usage: consulate [-h] [--api-host API_HOST] [--api-port API_PORT]
                 [--datacenter DATACENTER]
                 {register,kv} ...

optional arguments:
  -h, --help            show this help message and exit
  --api-host API_HOST   The consul host to connect on
  --api-port API_PORT   The consul API port to connect to
  --datacenter DATACENTER
                        The datacenter to specify for the connection

Commands:
  {register,kv}
    register            Register a service for this node
    kv                  Key/Value Database Utilities

Service Registration Help:

usage: consulate register [-h] [-s SERVICE_ID] [-t TAGS]
                          {check,no-check,ttl} ... name port

positional arguments:
  name                  The service name
  port                  The port the service runs on

optional arguments:
  -h, --help            show this help message and exit
  -s SERVICE_ID, --service-id SERVICE_ID
                        Specify a service ID
  -t TAGS, --tags TAGS  Specify a comma delimited list of tags

Service Check Options:
  {check,no-check,ttl}
    check               Define an external script-based check
    no-check            Do not enable service monitoring
    ttl                 Define a duration based TTL check

KV Database Utilities Help:

usage: consulate kv [-h] {backup,restore,get,set,del} ...

optional arguments:
  -h, --help            show this help message and exit

Key/Value Database Utilities:
  {backup,restore,get,set,del}
    backup              Backup to a JSON file
    restore             Restore from a JSON file
    get                 Get a key from the database
    set                 Set a key in the database
    del                 Delete a key from the database

API Usage Examples

The following examples highlight the usage of Consulate and does not document the scope of the full Consulate API.

Using Consulate with the Consul kv database:

session = consulate.Session()

# Set the key named release_flag to True
session.kv['release_flag'] = True

# Get the value for the release_flag, if not set, raises AttributeError
try:
    should_release_feature = session.kv['release_flag']
except AttributeError:
    should_release_feature = False

# Delete the release_flag key
del session.kv['release_flag']

# Find all keys that start with "fl"
session.kv.find('fl')

# Find all keys that start with "feature_flag" terminated by "/" separator
session.kv.find('feature_flag', separator='/')

# Check to see if a key called "foo" is set
if "foo" in session.kv:
    print 'Already Set'

# Return all of the items in the key/value store
session.kv.items()

Working with the Consulate.agent API:

session = consulate.Session()

# Get all of the service checks for the local agent
checks = session.agent.checks()

# Get all of the services registered with the local agent
services = session.agent.services()

# Add a service to the local agent
session.agent.service.register('redis',
                               port=6379,
                               tags=['master'],
                               ttl='10s')

Fetching health information from Consul:

session = consulate.Session()

# Get the health of a individual node
health = session.health.node('my-node')

# Get all checks that are critical
checks = session.heath.state('critical')

For more examples, check out the Consulate documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

consulate-0.3.0.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

consulate-0.3.0-py2-none-any.whl (13.9 kB view details)

Uploaded Python 2

File details

Details for the file consulate-0.3.0.tar.gz.

File metadata

  • Download URL: consulate-0.3.0.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for consulate-0.3.0.tar.gz
Algorithm Hash digest
SHA256 bf64eaddea9d20150d44c05391d83171fa0bab3fdd634098d72e9bd529271496
MD5 b09bea7e28ab7a2bedf7a4bd40922d76
BLAKE2b-256 1ddaa9c73b964c90ab35ea8170c254b4dad96e3517d509047ccb3fd2f2834a1f

See more details on using hashes here.

File details

Details for the file consulate-0.3.0-py2-none-any.whl.

File metadata

File hashes

Hashes for consulate-0.3.0-py2-none-any.whl
Algorithm Hash digest
SHA256 a9fe4d8293f4dd2632dd109230f59c41d934c21ad1dd3b0531b2472921c38ec1
MD5 28552a611d7d388be74c4a79a7bada75
BLAKE2b-256 b95bd3965ef72b3b5a3b8f63b9dc17145571baf6d626df9db9b86bc8c623a8fc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page