Registry / http-networking / python-consul2

python-consul2

JSON →
library0.1.5pypiunverified

python-consul2 is a Python client library for interacting with Consul (http://www.consul.io/), providing an interface for its KV store, agent, and catalog APIs. This library is a fork of python-consul. Its current version is 0.1.5, and it appears to be unmaintained, with no releases or commits since 2018.

pip install python-consul2
INSTALL
IMPORT
SIG · PYTHON-CONSUL2
P
python-consul2
http-networkingenv0.1.5
Install
2.1s avg
Import
582ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.610s · 21.6MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.1s · import 0.553s · 22MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Consul
from consul import Consul
from python_consul2 import Consul
Despite the package name `python-consul2`, the top-level import module is `consul`.

This quickstart demonstrates how to initialize the Consul client, put and get key-value pairs from the KV store, and list keys by prefix. Ensure a Consul agent is running and accessible at the specified host and port (default: localhost:8500).

import os import consul # Configuration for Consul connection CONSUL_HOST = os.environ.get('CONSUL_HOST', 'localhost') CONSUL_PORT = int(os.environ.get('CONSUL_PORT', '8500')) try: # Initialize Consul client c = consul.Consul(host=CONSUL_HOST, port=CONSUL_PORT) # Example 1: Put a key-value pair key = 'my-app/config/feature-flag' value = 'true' success = c.kv.put(key, value) if success: print(f"Successfully set key '{key}' to '{value}'") # Example 2: Get a key-value pair index, data = c.kv.get(key) if data: retrieved_value = data['Value'].decode('utf-8') print(f"Retrieved key '{key}': '{retrieved_value}'") else: print(f"Key '{key}' not found.") # Example 3: List keys under a prefix index, data = c.kv.get('my-app/', recurse=True) if data: print(f"Keys under 'my-app/':") for item in data: print(f" - {item['Key']}: {item['Value'].decode('utf-8') if item['Value'] else 'N/A'}") except Exception as e: print(f"An error occurred: {e}") print("Ensure Consul agent is running and accessible at {CONSUL_HOST}:{CONSUL_PORT}")
Debug
Known issues
breakingThis library (`python-consul2`) is an abandoned fork of `python-consul`. It has not been updated since 2018, leading to potential compatibility issues with newer Python versions, Consul API changes, and lack of critical bug fixes or security updates. It is strongly recommended to use the actively maintained `python-consul` library instead.
fix
Migrate to the `python-consul` library (`pip install python-consul`). Be aware of potential minor API differences.
affects: 0.1.0 - 0.1.5
gotchaThe package is installed as `python-consul2` but the correct import statement is `from consul import Consul`. Trying to import directly from `python_consul2` will result in a `ModuleNotFoundError`.
fix
Always use `from consul import Consul` or `import consul`.
affects: 0.1.0 - 0.1.5
gotchaDue to its abandonment, `python-consul2` may not support features or API changes introduced in Consul versions released after 2018 (e.g., Consul 1.5+). Attempting to use newer Consul features might result in `AttributeError` or unexpected behavior.
fix
Use the actively maintained `python-consul` library which keeps up-to-date with Consul API changes, or ensure you are running an older Consul version compatible with this client.
affects: All versions (0.1.0-0.1.5) when used with modern Consul installations.
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'python_consul2'
Attempting to import the library using `from python_consul2 import Consul` instead of the correct `from consul import Consul`.
fix
Change your import statement to `from consul import Consul`.
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8500): Max retries exceeded with url: /v1/kv/my-key?token= (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at ...>: Failed to establish a new connection: [Errno 111] Connection refused'))
The Consul agent is not running, is not accessible from the client, or is running on a different host/port than configured.
fix
Verify that your Consul agent is running and listening on the expected host and port (default: `localhost:8500`). Check firewall rules if connecting remotely. Ensure `CONSUL_HOST` and `CONSUL_PORT` environment variables or constructor arguments are correct.
AttributeError: 'Consul' object has no attribute 'agent'
This specific error might occur if the library version is extremely old or if you're mixing `python-consul2` with expectations from `python-consul`. More commonly, it signifies attempting to call an API method that does not exist in the version of the client library you are using, or it has been renamed/removed.
fix
Consult the `python-consul2` source code or documentation (if any) for available methods. If using an older Consul API, consider migrating to `python-consul` for better compatibility with current Consul versions and a more actively maintained API surface.
Upgrade
Version history
0.1.5latest on PyPI · released Oct 20, 2020
Audit
Dependencies
requestsrequiredUsed for HTTP communication with the Consul API.
Agent activity
2 hits · last 30 days
node
2
Resources

No resource links recorded.

python-consul2 — pip install python-consul2 · libregistry