{"id":9726,"library":"etcd-sdk-python","title":"etcd-sdk-python Client","description":"etcd-sdk-python is a Python client for the etcd v3 API, supporting Python versions >= 3.8. It provides a simple interface for interacting with etcd, a distributed reliable key-value store. The library is actively maintained with minor releases focusing on enhancements and dependency updates.","status":"active","version":"0.0.7","language":"en","source_language":"en","source_url":"https://github.com/XuanYang-cn/pyetcd","tags":["etcd","key-value store","distributed","grpc","client"],"install":[{"cmd":"pip install etcd-sdk-python","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for gRPC communication with etcd server.","package":"grpcio","optional":false},{"reason":"Used for gRPC code generation, often installed with the client.","package":"grpcio-tools","optional":false},{"reason":"Protocol Buffers are used for serializing structured data in gRPC.","package":"protobuf","optional":false}],"imports":[{"note":"The package name is `etcd-sdk-python` but the import path uses `etcd_sdk` (underscore instead of hyphen).","wrong":"from etcd_sdk_python import Client","symbol":"Client","correct":"from etcd_sdk import Client"},{"note":"This is for the older `python-etcd` library which supports etcd v2 API.","wrong":"import etcd","symbol":"Client","correct":"from etcd_sdk import Client"},{"note":"This is for the `python-etcd3` library, another etcd v3 client.","wrong":"import etcd3","symbol":"Client","correct":"from etcd_sdk import Client"}],"quickstart":{"code":"from etcd_sdk import Client\nimport os\n\n# Configure etcd connection (use environment variables for production)\nhost = os.environ.get('ETCD_HOST', '127.0.0.1')\nport = int(os.environ.get('ETCD_PORT', 2379))\n\n# Establish connection\ntry:\n    client = Client(host=host, port=port)\n    print(f\"Connected to etcd at {host}:{port}\")\n\n    # Put a key-value pair\n    key = 'mykey'\n    value = 'myvalue'\n    client.put(key=key, value=value)\n    print(f\"Put '{key}': '{value}'\")\n\n    # Get a key-value pair\n    retrieved_value, meta = client.get(key=key)\n    print(f\"Get '{key}': value='{retrieved_value}', revision={meta.revision}\")\n\n    # Delete a key\n    client.delete(key=key)\n    print(f\"Deleted '{key}'\")\n\n    # Try to get after deletion\n    deleted_value, deleted_meta = client.get(key=key)\n    print(f\"Get '{key}' after deletion: value='{deleted_value}', revision={deleted_meta.revision}\") # Value will be empty/None\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure an etcd server is running at the specified host and port.\")\n","lang":"python","description":"This quickstart demonstrates how to connect to an etcd server, and perform basic put, get, and delete operations. It includes error handling for connection issues."},"warnings":[{"fix":"Always use `from etcd_sdk import Client` for importing the main client.","message":"The import path for the library is `etcd_sdk` (with an underscore) despite the PyPI package name being `etcd-sdk-python` (with a hyphen). Using `from etcd_sdk_python import Client` will result in a `ModuleNotFoundError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your etcd server is running version 3.x. Refer to the etcd documentation for migration from v2 to v3 if necessary.","message":"This library is designed exclusively for the etcd v3 API. Attempting to connect to an etcd v2 server or use v2 API methods (e.g., `client.read()`, `client.write()`) will result in connection failures or `AttributeError`.","severity":"breaking","affected_versions":"All versions"},{"fix":"Use a virtual environment to manage dependencies. If conflicts occur, try upgrading or downgrading `grpcio` and `protobuf` to versions within the specified ranges, or using `pip install --no-deps etcd-sdk-python` and manually installing compatible `grpcio` and `protobuf`.","message":"Potential `grpcio` version conflicts. The library specifies a compatible `grpcio` version range, but conflicts can arise if other dependencies require a different, incompatible version.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement retry logic for transient errors and ensure your etcd server is accessible. Consider using `try-except` blocks around etcd operations, specifically catching `grpc.RpcError`.","message":"For robust applications, proper connection management and error handling are crucial. `etcd-sdk-python` uses gRPC, and network issues or server unavailability can lead to `_InactiveRpcError` or `grpc.RpcError`.","severity":"gotcha","affected_versions":"All versions"}],"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 from `from etcd_sdk_python import Client` to `from etcd_sdk import Client`.","cause":"Incorrect import path. The PyPI package name `etcd-sdk-python` does not match the importable package name `etcd_sdk`.","error":"ModuleNotFoundError: No module named 'etcd_sdk_python'"},{"fix":"Install `etcd-sdk-python` and use `from etcd_sdk import Client`. If you need etcd v2 support, install `python-etcd` instead, but note it's deprecated.","cause":"Attempting to import the old `python-etcd` library, which is a different package for the etcd v2 API.","error":"ModuleNotFoundError: No module named 'etcd'"},{"fix":"Verify that your etcd server is running and accessible from the client machine on the specified host and port (default 2379). Check firewall rules. Ensure etcd server is healthy.","cause":"This error typically indicates that the etcd server is not running, is unreachable, or the connection parameters (host/port) are incorrect. It could also indicate a firewall issue.","error":"grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC ...> Caused by RPC failure for 'etcdserver.KV/Range'"},{"fix":"Use the etcd v3 API methods like `client.get()` for reading. Consult the `etcd-sdk-python` documentation for the correct v3 API equivalents.","cause":"You are attempting to use a method (`read`) that was part of the etcd v2 API client (e.g., `python-etcd`), but `etcd-sdk-python` implements the etcd v3 API.","error":"AttributeError: 'Client' object has no attribute 'read'"}]}