Skip to content
Visit booth 3171 at Google Cloud Next to see how to unlock real-time decisions at scaleMore info

Connecting

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

Import the module

To import the Aerospike Python client module into your application:

import aerospike

Configure a client

A client configuration may specify 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.
  • User authentication: key-value pairs of user and password data.

Explore the full client configuration.

The following example creates a sample client configuration:

config = {
'hosts': [
( '127.0.0.1', 3000 )
],
'policies': {
'timeout': 1000 # milliseconds
}
# if user authentication is enabled
'user': user,
'password': password
}

Create a client

To create a new client:

client = aerospike.client(config)

Calling the aerospike.client constructor establishes the connection.

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

It’s not necessary to call client.connect() unless client.close() has run previously. connect() is a no-op function unless an existing connection has already closed.

References

Read the following APIs for more information:

Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?