{"id":6495,"library":"aerospike","title":"Aerospike Python Client","description":"aerospike is a package which provides a Python client for Aerospike database clusters. The client enables applications to interact with Aerospike, managing connections and handling database operations like CRUD, queries, and scans. It is a CPython module built on the Aerospike C client. The current version is 19.2.0, and the library maintains an active release cycle with frequent updates and major version increments.","status":"active","version":"19.2.0","language":"en","source_language":"en","source_url":"https://github.com/aerospike/aerospike-client-python","tags":["database","NoSQL","key-value","high-performance"],"install":[{"cmd":"pip install aerospike","lang":"bash","label":"Install Aerospike Python Client"}],"dependencies":[],"imports":[{"symbol":"aerospike","correct":"import aerospike"},{"note":"The `aerospike.client()` function acts as a constructor for the Client class and connects to the cluster upon instantiation.","symbol":"Client","correct":"client = aerospike.client(config)"}],"quickstart":{"code":"import aerospike\nimport sys\n\n# Configure the client to connect to a local Aerospike cluster\nconfig = {\n    'hosts': [\n        ('127.0.0.1', 3000)\n    ]\n}\n\ntry:\n    # Create a client object and connect to the cluster\n    client = aerospike.client(config).connect()\nexcept aerospike.exception.ClientError as e:\n    print(f\"Error: Failed to connect to Aerospike cluster: {e}\", file=sys.stderr)\n    sys.exit(1)\n\n# Define a key: (namespace, set, userkey)\nkey = ('test', 'demo', 'my_key_1')\n\n# Define record bins (data)\nbins = {\n    'name': 'John Doe',\n    'age': 32\n}\n\ntry:\n    # Write a record\n    client.put(key, bins)\n    print(f\"Record written: {key}\")\n\n    # Read the record back\n    (key_read, metadata_read, record_read) = client.get(key)\n    print(f\"Record read: {record_read}\")\n\n    # Update a bin\n    client.put(key, {'age': 33})\n    print(f\"Record updated: {key}\")\n    (key_updated, metadata_updated, record_updated) = client.get(key)\n    print(f\"Record after update: {record_updated}\")\n\nexcept aerospike.exception.AerospikeError as e:\n    print(f\"Aerospike Error: {e}\", file=sys.stderr)\n    sys.exit(1)\nfinally:\n    # Close the connection to the Aerospike cluster\n    if client:\n        client.close()\n        print(\"Client connection closed.\")","lang":"python","description":"This quickstart demonstrates how to connect to an Aerospike cluster, write a record with a key and bins, read the record, update a bin, and finally close the client connection. It assumes an Aerospike database is running on localhost:3000."},"warnings":[{"fix":"Ensure your Aerospike server version is 4.9 or newer before upgrading the Python client.","message":"Aerospike Python client 5.0.0 and up requires Aerospike server 4.9 or later. Attempting to connect to older server versions will result in a '-10, Failed to connect' error.","severity":"breaking","affected_versions":">= 5.0.0"},{"fix":"Always check the official documentation for the supported Python range. The current client (19.x.x) supports Python 3.10 - 3.14.","message":"Support for older Python versions is periodically removed. Python 3.5 support was removed in client 6.0.0. Python 3.8 and 3.9 support was removed in recent major versions (e.g., Python 3.9 in 19.0.0).","severity":"breaking","affected_versions":"Varies by version, Python 3.5 removed in 6.0.0, 3.8/3.9 removed in later major versions (e.g. 19.0.0)"},{"fix":"Use `client.scan()` and `client.query()` methods on an `aerospike.Client` instance instead.","message":"Direct instantiation of `aerospike.Scan()` and `aerospike.Query()` objects is deprecated. These methods now issue a warning and will raise an exception in future major releases.","severity":"deprecated","affected_versions":">= 18.1.0"},{"fix":"Use `info_single_node()` instead.","message":"The `info_node()` method was deprecated and will no longer work when security is enabled due to client authentication changes.","severity":"deprecated","affected_versions":">= 6.0.0"},{"fix":"Ensure all port numbers in the host configuration are integers.","message":"Passing a non-integer value as a port number in a host tuple to `aerospike.client()` currently issues a warning but will raise a `ParamError` exception in the next major client release.","severity":"gotcha","affected_versions":">= 18.0.0"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[{"fix":"Install the Aerospike client using pip: `pip install aerospike`.","cause":"The Aerospike Python client is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'aerospike'"},{"fix":"Rename the script to avoid naming conflicts, e.g., 'aerospike_test.py'.","cause":"The script is named 'aerospike.py', causing a conflict with the Aerospike module import.","error":"AttributeError: 'module' object has no attribute 'client'"},{"fix":"Use the correct method 'info' instead: `client.info('sets')`.","cause":"The method 'info_all' does not exist in the Aerospike Python client.","error":"AttributeError: 'aerospike.Client' object has no attribute 'info_all'"},{"fix":"1. Verify the `hosts` (IP address and port, typically 3000) in your client configuration. 2. Ensure the Aerospike server is running and accessible from the client machine. 3. Check firewall rules blocking the connection. 4. If using Python client version 5.0.0 or newer, ensure your Aerospike server is version 4.9 or later.","cause":"The Python client failed to establish a connection to the Aerospike cluster. Common causes include incorrect host/port configuration, the Aerospike server not running, network connectivity issues (e.g., firewall), or an incompatibility between client and server versions (e.g., Python client 5.0.0+ requires Aerospike server 4.9+).","error":"aerospike.exception.ClientError: (-10, 'Failed to connect')"}]}