Skip to main content

Connecting with the Aerospike Python Client

Use the Aerospike Python client APIs to connect to the Aerospike database.

Import the Module

To import the Aerospike Python client module in to your application:

import aerospike

Configuring a Client

To create a configuration for the client that specifies various options, including:

  • hosts An array of (address, port) tuples that describe the cluster (only one tuple is required).
  • policies A dict of policies to set defaults along with read and write flexibility.

Explore the full client configuration.

This example connects to an Aerospike cluster:

config = {
'hosts': [
( '127.0.0.1', 3000 )
],
'policies': {
'timeout': 1000 # milliseconds
}
}

Creating a Client

To create a new client:

client = aerospike.client(config)

Once the client is created, you can connect and execute operations against the cluster.

Connecting to the Cluster

To connect to the cluster:

client.connect()

A failed connection results in an exception. On success, your application can execute database operations.

References

Read the following APIs for more information: