Kazoo is a higher-level Python client for Apache ZooKeeper, providing robust abstractions for common distributed coordination tasks like locks, leader election, and queues. Version 2.11.0 is the latest stable release, with development active and releases occurring periodically, often driven by Python version support updates and bug fixes.
pip install kazooVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to connect to Apache ZooKeeper using Kazoo, set up a connection state listener, create an ephemeral node, and retrieve its data. Remember to have a ZooKeeper instance running and set the `ZOOKEEPER_HOSTS` environment variable accordingly.
Refer to the latest Kazoo release notes or documentation for current Python compatibility. For example, Kazoo 2.10.0 dropped support for Python 3.7, now supporting Python 3.8-3.12.
Implement a connection state listener using `@zk.add_listener` and structure your logic to react to connection events. Ensure `zk.start()` is called and the client has connected before attempting Zookeeper operations.
Always provide the Zookeeper host string in the correct `host:port,host:port` format. Validate the string if it's sourced from configuration or environment variables.
Verify that the Zookeeper server (or ensemble) is running and accessible from the client's host and network on the configured port (default 2181). Check firewall rules, network connectivity, and ensure the Zookeeper service is active.
Ensure your Zookeeper server is running, accessible from the client's network, and configured to listen on the `host:port` provided to `KazooClient`. Verify network connectivity (e.g., using `telnet` or `nc`) to the Zookeeper server's address and port from the client's environment. Check Zookeeper server logs for binding or startup errors.
pip install kazoo
Implement a connection listener to handle state changes (KazooState.SUSPENDED, KazooState.LOST, KazooState.CONNECTED) and consider using `kazoo.retry.KazooRetry` for operations that should be reattempted upon transient connection issues.
Verify that the ZooKeeper server is running and accessible from the client. Consider increasing the `timeout` parameter during `KazooClient` initialization or in the `start()` method if network latency or server startup time is a factor.
Ensure the node path is correct. If the node may or may not exist, use methods like `client.exists(path)` to check before operating, or `client.ensure_path(path)` to create parent nodes if missing before creating a child node.
Ensure the correct `auth_data` (scheme and credentials) is provided to the `KazooClient` during initialization or added via `client.add_auth()` to match the ZooKeeper server's authentication requirements.
No dependency data recorded yet.