Python Data Mappings

How Python types map to server types

Default Behavior

By default, the Client maps the supported Python types to Aerospike server types. When an unsupported type is encountered by the module:

  1. When sending data to the server, it does not serialize the type and will throw an error.

  2. When reading AS_BYTES_PYTHON types from the server, it returns the raw bytes as a bytearray. To deserialize this data, the application must use cPickle instead of relying on the client to do it automatically.

Serializers

However, the functions set_serializer() and set_deserializer() allow for user-defined functions to handle serialization. The serialized data is stored in the server with generic encoding (AS_BYTES_BLOB). This type allows the storage of binary data readable by Aerospike Clients in other languages. The serialization config parameter of aerospike.client() registers an instance-level pair of functions that handle serialization.

Warning

Aerospike is introducing a new boolean data type in server version 5.6.

In order to support cross client compatibility and rolling upgrades, Python client version 6.x comes with a new client config, send_bool_as. It configures how the client writes Python booleans and allows for opting into using the new boolean type. It is important to consider how other clients connected to the Aerospike database write booleans in order to maintain cross client compatibility. For example, if there is a client that reads and writes booleans as integers, then another Python client working with the same data should do the same thing.

send_bool_as can be set so the client writes Python booleans as integers or the Aerospike native boolean type.

All versions before 6.x wrote Python booleans as AS_BYTES_PYTHON.

Data Mappings

The following table shows which Python types map directly to Aerospike server types.

For server 7.1 and higher, map keys can only be of type string, bytes, and integer.

Note

KeyOrderedDict is a special case. Like dict, KeyOrderedDict maps to the Aerospike map data type. However, the map will be sorted in key order before being sent to the server (see Map Order).

It is possible to nest these datatypes. For example a list may contain a dictionary, or a dictionary may contain a list as a value.