{"id":14837,"library":"python-consul2","title":"Python Consul 2 Client (Abandoned)","description":"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.","status":"abandoned","version":"0.1.5","language":"en","source_language":"en","source_url":"https://github.com/poppyred/python-consul2","tags":["consul","service-discovery","kv-store","distributed-systems","abandoned"],"install":[{"cmd":"pip install python-consul2","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Used for HTTP communication with the Consul API.","package":"requests","optional":false}],"imports":[{"note":"Despite the package name `python-consul2`, the top-level import module is `consul`.","wrong":"from python_consul2 import Consul","symbol":"Consul","correct":"from consul import Consul"}],"quickstart":{"code":"import os\nimport consul\n\n# Configuration for Consul connection\nCONSUL_HOST = os.environ.get('CONSUL_HOST', 'localhost')\nCONSUL_PORT = int(os.environ.get('CONSUL_PORT', '8500'))\n\ntry:\n    # Initialize Consul client\n    c = consul.Consul(host=CONSUL_HOST, port=CONSUL_PORT)\n\n    # Example 1: Put a key-value pair\n    key = 'my-app/config/feature-flag'\n    value = 'true'\n    success = c.kv.put(key, value)\n    if success:\n        print(f\"Successfully set key '{key}' to '{value}'\")\n\n    # Example 2: Get a key-value pair\n    index, data = c.kv.get(key)\n    if data:\n        retrieved_value = data['Value'].decode('utf-8')\n        print(f\"Retrieved key '{key}': '{retrieved_value}'\")\n    else:\n        print(f\"Key '{key}' not found.\")\n\n    # Example 3: List keys under a prefix\n    index, data = c.kv.get('my-app/', recurse=True)\n    if data:\n        print(f\"Keys under 'my-app/':\")\n        for item in data:\n            print(f\"  - {item['Key']}: {item['Value'].decode('utf-8') if item['Value'] else 'N/A'}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Ensure Consul agent is running and accessible at {CONSUL_HOST}:{CONSUL_PORT}\")","lang":"python","description":"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)."},"warnings":[{"fix":"Migrate to the `python-consul` library (`pip install python-consul`). Be aware of potential minor API differences.","message":"This 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.","severity":"breaking","affected_versions":"0.1.0 - 0.1.5"},{"fix":"Always use `from consul import Consul` or `import consul`.","message":"The 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`.","severity":"gotcha","affected_versions":"0.1.0 - 0.1.5"},{"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.","message":"Due 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.","severity":"gotcha","affected_versions":"All versions (0.1.0-0.1.5) when used with modern Consul installations."}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Change your import statement to `from consul import Consul`.","cause":"Attempting to import the library using `from python_consul2 import Consul` instead of the correct `from consul import Consul`.","error":"ModuleNotFoundError: No module named 'python_consul2'"},{"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.","cause":"The Consul agent is not running, is not accessible from the client, or is running on a different host/port than configured.","error":"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'))"},{"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.","cause":"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.","error":"AttributeError: 'Consul' object has no attribute 'agent'"}],"ecosystem":"pypi"}