aerospike — Aerospike Client for Python

Overview

aerospike is a package which provides a Python client for Aerospike database clusters.

The Aerospike client enables you to build an application in Python with an Aerospike cluster as its database. The client manages the connections to the cluster and handles the transactions performed against it.

Methods

Constructors

Client

aerospike.client(config)

Creates a new instance of the Client class and immediately connects to the cluster.

See aerospike.Client — Client Class for more details.

Internally, this is a wrapper function which calls the constructor for the Client class. However, the client may also be constructed by calling the constructor directly.

The client takes on many configuration parameters passed in through a dictionary.

Parameters:

config (dict) – See Client Configuration.

Returns:

an instance of the Client class.

Changed in version 2.0.0.

Simple example:

import aerospike

# Configure the client to first connect to a cluster node at 127.0.0.1
# The client will learn about the other nodes in the cluster from the seed node.
# Also sets a top level policy for read operations
config = {
    'hosts':    [ ('127.0.0.1', 3000) ],
    'policies': {'read': {'total_timeout': 1000}},
}
client = aerospike.client(config)

Connecting using TLS example:

import aerospike
import sys

# NOTE: Use of TLS requires Aerospike Enterprise version >= 3.11
# and client version 2.1.0 or greater
tls_name = "some-server-tls-name"
tls_ip = "127.0.0.1"
tls_port = 4333

# If tls-name is specified,
# it must match the tls-name in the node’s server configuration file
# and match the server’s CA certificate.
tls_host_tuple = (tls_ip, tls_port, tls_name)
hosts = [tls_host_tuple]

# Example configuration which will use TLS with the specified cafile
tls_config = {
    "cafile": "/path/to/cacert.pem",
    "enable": True
}
try:
    client = aerospike.client({
        "hosts": hosts,
        "tls": tls_config
    })
except Exception as e:
    print(e)
    print("Failed to connect")
    sys.exit()

Geospatial

aerospike.geodata([geo_data])

Helper for creating an instance of the GeoJSON class. Used to wrap a geospatial object, such as a point, polygon or circle.

Parameters:

geo_data (dict) – a dict representing the geospatial data.

Returns:

an instance of the aerospike.GeoJSON class.

import aerospike

# Create GeoJSON point using WGS84 coordinates.
latitude = 45.920278
longitude = 63.342222
loc = aerospike.geodata({'type': 'Point',
                         'coordinates': [longitude, latitude]})

New in version 1.0.54.

aerospike.geojson([geojson_str])

Helper for creating an instance of the GeoJSON class from a raw GeoJSON str.

Parameters:

geojson_str (dict) – a str of raw GeoJSON.

Returns:

an instance of the aerospike.GeoJSON class.

import aerospike

# Create GeoJSON point using WGS84 coordinates.
loc = aerospike.geojson('{"type": "Point", "coordinates": [-80.604333, 28.608389]}')

New in version 1.0.54.

Types

aerospike.null()

A type for distinguishing a server-side null from a Python None. Replaces the constant aerospike.null.

Returns:

a type representing the server-side type as_null.

New in version 2.0.1.

aerospike.CDTWildcard()

A type representing a wildcard object. This type may only be used as a comparison value in operations. It may not be stored in the database.

Returns:

a type representing a wildcard value.

import aerospike
from aerospike_helpers.operations import list_operations as list_ops

client = aerospike.client({'hosts': [('localhost', 3000)]})
key = 'test', 'demo', 1

#  get all values of the form [1, ...] from a list of lists.
#  For example if list is [[1, 2, 3], [2, 3, 4], [1, 'a']], this operation will match
#  [1, 2, 3] and [1, 'a']
operations = [list_ops.list_get_by_value('list_bin', [1, aerospike.CDTWildcard()], aerospike.LIST_RETURN_VALUE)]
_, _, bins = client.operate(key, operations)

New in version 3.5.0.

Note

This requires Aerospike Server 4.3.1.3 or greater

aerospike.CDTInfinite()

A type representing an infinite value. This type may only be used as a comparison value in operations. It may not be stored in the database.

Returns:

a type representing an infinite value.

import aerospike
from aerospike_helpers.operations import list_operations as list_ops

client = aerospike.client({'hosts': [('localhost', 3000)]})
key = 'test', 'demo', 1

#  get all values of the form [1, ...] from a list of lists.
#  For example if list is [[1, 2, 3], [2, 3, 4], [1, 'a']], this operation will match
#  [1, 2, 3] and [1, 'a']
operations = [list_ops.list_get_by_value_range('list_bin', aerospike.LIST_RETURN_VALUE, [1],  [1, aerospike.CDTInfinite()])]
_, _, bins = client.operate(key, operations)

New in version 3.5.0.

Note

This requires Aerospike Server 4.3.1.3 or greater

Serialization

Note

If the client’s config dictionary has a serializer and deserializer in the serialization tuple, then it will take precedence over the ones from set_serializer() and set_deserializer().

aerospike.set_serializer(callback)

Register a user-defined serializer available to all Client instances.

Parameters:

callback (callable) – the function to invoke for serialization.

See also

To use this function with Client.put(), the argument to the serializer parameter should be aerospike.SERIALIZER_USER.

def my_serializer(val):
    return json.dumps(val)

aerospike.set_serializer(my_serializer)

New in version 1.0.39.

aerospike.set_deserializer(callback)

Register a user-defined deserializer available to all Client instances.

Once registered, all read methods (such as Client.get()) will run bins containing ‘Generic’ as_bytes of type AS_BYTES_BLOB through this deserializer.

Parameters:

callback (callable) – the function to invoke for deserialization.

aerospike.unset_serializers()

Deregister the user-defined deserializer/serializer available from Client instances.

New in version 1.0.53.

Example

The following example shows the three modes of serialization:

  1. Built-in

  2. Class-level user functions

  3. Instance-level user functions

import aerospike
import marshal
import json

# Serializers and deserializers
# Both local and global serializers use json library
# Functions print which one is being used

def classSerializer(obj):
    print("Using class serializer")
    return json.dumps(obj)

def classDeserializer(bytes):
    print("Using class deserializer")
    return json.loads(bytes)

def localSerializer(obj):
    print("Using local serializer")
    return json.dumps(obj)

def localDeserializer(bytes):
    print("Using local deserializer")
    return json.loads(bytes)

# First client has class-level serializer set in aerospike module
aerospike.set_serializer(classSerializer)
aerospike.set_deserializer(classDeserializer)
config = {
    'hosts': [('127.0.0.1', 3000)]
}
client = aerospike.client(config).connect()

# Second client has instance-level serializer set in client config
config['serialization'] = (localSerializer, localDeserializer)
client2 = aerospike.client(config).connect()

# Keys: foo1, foo2, foo3
keys = [('test', 'demo', f'foo{i}') for i in range(1, 4)]
# Tuple is an unsupported type
tupleBin = {'bin': (1, 2, 3)}

# Use the default, built-in serialization (cPickle)
client.put(keys[0], tupleBin)
(_, _, bins) = client.get(keys[0])
print(bins)

# Expected output:
# {'bin': (1, 2, 3)}

# First client uses class-level, user-defined serialization
# No instance-level serializer was declared
client.put(keys[1], tupleBin, serializer=aerospike.SERIALIZER_USER)
(_, _, bins) = client.get(keys[1])
# Notice that json-encoding a tuple produces a list
print(bins)

# Expected output:
# Using class serializer
# Using class deserializer
# {'bin': [1, 2, 3]}

# Second client uses instance-level, user-defined serialization
# Instance-level serializer overrides class-level serializer
client2.put(keys[2], tupleBin, serializer=aerospike.SERIALIZER_USER)
(_, _, bins) = client2.get(keys[2])
print(bins)

# Expected output:
# Using local serializer
# Using local deserializer
# {'bin': [1, 2, 3]}

# Cleanup
client.batch_remove(keys)
client.close()
client2.close()

Records foo1 and foo2 should have different encodings from each other since they use different serializers. (record foo3 uses the same encoding as foo2) If we read the data for each record using aql, it outputs the following data:

aql> select bin from test.demo where PK='foo1'
+-------------------------------------------------------------+--------+
| bin                                                         | PK     |
+-------------------------------------------------------------+--------+
| 80 04 95 09 00 00 00 00 00 00 00 4B 01 4B 02 4B 03 87 94 2E | "foo1" |
+-------------------------------------------------------------+--------+
1 row in set (0.000 secs)

OK

aql> select bin from test.demo where PK='foo2'
+----------------------------+--------+
| bin                        | PK     |
+----------------------------+--------+
| 5B 31 2C 20 32 2C 20 33 5D | "foo2" |
+----------------------------+--------+
1 row in set (0.001 secs)

OK

Logging

aerospike.set_log_handler(callback)

Enables aerospike log handler

Parameters:

callback (optional callable) – the function used as the logging handler.

Note

The callback function must have the five parameters (level, func, path, line, msg)

import aerospike

from __future__ import print_function import aerospike

aerospike.set_log_level(aerospike.LOG_LEVEL_DEBUG) aerospike.set_log_handler(callback)

aerospike.set_log_level(log_level)

Declare the logging level threshold for the log handler.

Parameters:

log_level (int) – one of the Log Level constant values.

Other

aerospike.calc_digest(ns, set, key) bytearray

Calculate the digest of a particular key. See: Key Tuple.

Parameters:
  • ns (str) – the namespace in the aerospike cluster.

  • set (str) – the set name.

  • key (str, int or bytearray) – the primary key identifier of the record within the set.

Returns:

a RIPEMD-160 digest of the input tuple.

Return type:

bytearray

import aerospike
import pprint

digest = aerospike.calc_digest("test", "demo", 1 )
pp.pprint(digest)

Client Configuration

These are the keys and expected values for the config dictionary passed to aerospike.client().

Only the hosts key is required; the rest of the keys are optional.

config
  • hosts (list)

    A list of tuples identifying a node (or multiple nodes) in the cluster.

    The tuple is in this format: (address, port, [tls-name])

    The client will connect to the first available node in the list called the seed node. From there, it will learn about the cluster and its partition map.

    If tls-name is specified, it must match the tls-name specified in the node’s server configuration file, as well as the server’s CA certificate.

  • user (str)

    (Optional) A defined user with roles in the cluster. See admin_create_user().

  • password (str)

    (Optional) The password will be hashed by the client using bcrypt.

  • lua (dict)

    (Optional) Contains the paths to two types of Lua modules

    • system_path (str)

      The location of the system modules such as aerospike.lua

      Default: /usr/local/aerospike/lua

    • user_path (str)

      The location of the user’s record and stream UDFs .

      Default: ./

  • policies (dict)

    A dict of policies. Note that these policies do not accept expressions.

  • shm (dict)

    Contains optional shared-memory cluster tending parameters

    Shared-memory cluster tending is on if the dict is provided. If multiple clients are instantiated and talking to the same cluster the shm cluster-tending should be used.

    • max_nodes (int)

      Maximum number of nodes allowed.

      Pad this value so new nodes can be added without configuration changes.

      Default: 16

    • max_namespaces (int)

      Maximum number of namespaces allowed.

      Pad this value so new namespaces can be added without configuration changes.

      Default: 8

    • takeover_threshold_sec (int)

      Take over tending if the cluster hasn’t been checked for this many seconds

      Default: 30

    • shm_key

      Explicitly set the shm key for this client.

      If use_shared_connection is not set, or set to False, the user must provide a value for this field in order for shared memory to work correctly.

      If, and only if, use_shared_connection is set to True, the key will be implicitly evaluated per unique hostname, and can be inspected with Client.shm_key() .

      It is still possible to specify a key when using use_shared_connection = True.

      Default: 0xA9000000

      See also

      Shared Memory

  • use_shared_connection (bool)

    Indicates whether this instance should share its connection to the Aerospike cluster with other client instances in the same process.

    Default: False

  • tls (dict)

    Contains optional TLS configuration parameters.

    Note

    TLS usage requires Aerospike Enterprise Edition. See TLS.

    • enable (bool)

      Indicating whether tls should be enabled or not.

      Default: False

    • cafile (str)

      Path to a trusted CA certificate file.

      By default TLS will use system standard trusted CA certificates

    • capath (str)

      Path to a directory of trusted certificates.

      See the OpenSSL SSL_CTX_load_verify_locations manual page for more information about the format of the directory.

    • protocols (str)

      Specifies enabled protocols. This format is the same as Apache’s SSLProtocol documented at https://httpd.apache.org/docs/current/mod/mod_ssl.html#sslprotocol .

      If not specified the client will use “-all +TLSv1.2”.

    • cipher_suite (str)

      Specifies enabled cipher suites.

      The format is the same as OpenSSL’s Cipher List Format documented at https://www.openssl.org/docs/man1.1.1/man1/ciphers.html .

      If not specified, the OpenSSL default cipher suite described in the ciphers documentation will be used. If you are not sure what cipher suite to select, this option is best left unspecified.

    • keyfile (str)

      Path to the client’s key for mutual authentication.

      By default, mutual authentication is disabled.

    • keyfile_pw (str)

      Decryption password for the client’s key for mutual authentication.

      By default, the key is assumed not to be encrypted.

    • cert_blacklist (str)

      Path to a certificate blacklist file.

      The file should contain one line for each blacklisted certificate. Each line starts with the certificate serial number expressed in hex. Each entry may optionally specify the issuer name of the certificate (serial numbers are only required to be unique per issuer).

      Example records: 867EC87482B2 /C=US/ST=CA/O=Acme/OU=Engineering/CN=Test Chain CA E2D4B0E570F9EF8E885C065899886461

    • certfile (str)

      Path to the client’s certificate chain file for mutual authentication.

      By default, mutual authentication is disabled.

    • crl_check (bool)

      Enable CRL checking for the certificate chain leaf certificate.

      An error occurs if a suitable CRL cannot be found.

      By default CRL checking is disabled.

    • crl_check_all (bool)

      Enable CRL checking for the entire certificate chain.

      An error occurs if a suitable CRL cannot be found.

      By default CRL checking is disabled.

    • log_session_info (bool)

      Log session information for each connection.

    • for_login_only (bool)

      Log session information for each connection.

      Use TLS connections only for login authentication. All other communication with the server will be done with non-TLS connections.

      Default: False (Use TLS connections for all communication with server.)

  • send_bool_as (int)

    Configures the client to encode Python booleans as the native Python boolean type, an integer, or the server boolean type.

    Use one of the Send Bool Constants constant values.

    See Python Data Mappings for more information.

    Default: aerospike.AS_BOOL

  • serialization (tuple)

    An optional instance-level tuple of (serializer, deserializer).

    Takes precedence over a class serializer registered with set_serializer().

  • thread_pool_size (int)

    Number of threads in the pool that is used in batch/scan/query commands.

    Default: 16

  • max_socket_idle (int)

    Maximum socket idle in seconds. Connection pools will discard sockets that have been idle longer than the maximum.

    Connection pools are now implemented by a LIFO stack. Connections at the tail of the stack will always be the least used. These connections are checked for max_socket_idle once every 30 tend iterations (usually 30 seconds).

    If server’s proto-fd-idle-ms is greater than zero, then max_socket_idle should be at least a few seconds less than the server’s proto-fd-idle-ms, so the client does not attempt to use a socket that has already been reaped by the server.

    If server’s proto-fd-idle-ms is zero (no reap), then max_socket_idle should also be zero. Connections retrieved from a pool in transactions will not be checked for max_socket_idle when max_socket_idle is zero. Idle connections will still be trimmed down from peak connections to min connections (min_conns_per_node and async_min_conns_per_node) using a hard-coded 55 second limit in the cluster tend thread.

    Default: 0

  • min_conns_per_node (int)

    Minimum number of synchronous connections allowed per server node. Preallocate minimum connections on client node creation. The client will periodically allocate new connections if count falls below min connections.

    Server proto-fd-idle-ms and client max_socket_idle should be set to zero (no reap) if min_conns_per_node is greater than zero. Reaping connections can defeat the purpose of keeping connections in reserve for a future burst of activity.

    Default: 0

  • max_conns_per_node (int)

    Maximum number of pipeline connections allowed for each node

    Default: 100

  • max_error_rate (int)

    Maximum number of errors allowed per node per error_rate_window before backoff algorithm returns MaxErrorRateExceeded for database commands to that node. If max_error_rate is zero, there is no error limit.

    The counted error types are any error that causes the connection to close (socket errors and client timeouts), server device overload and server timeouts.

    The application should backoff or reduce the transaction load until MaxErrorRateExceeded stops being returned.

    Default: 100

  • error_rate_window (int)

    The number of cluster tend iterations that defines the window for max_error_rate. One tend iteration is defined as tend_interval plus the time to tend all nodes. At the end of the window, the error count is reset to zero and backoff state is removed on all nodes.

    Default: 1

  • tend_interval (int)

    Polling interval in milliseconds for tending the cluster

    Default: 1000

  • compression_threshold (int)

    Deprecated: set in the Write Policies dictionary

    Compress data for transmission if the object size is greater than a given number of bytes

    Default: 0, meaning ‘never compress’

  • cluster_name (str)

    Only server nodes matching this name will be used when determining the cluster name.

  • rack_id (int)

    Rack id where this client instance resides.

    rack_aware, POLICY_REPLICA_PREFER_RACK and server rack configuration must also be set to enable this functionality.

    Default: 0

  • rack_ids (list)

    List of preferred racks in order of preference. If rack_ids is set, rack_id is ignored.

    rack_aware, POLICY_REPLICA_PREFER_RACK and server rack configuration must also be set to enable this functionality.

  • rack_aware (bool)

    Track server rack data.

    This is useful for:

    • Directing read operations to run on the same rack as the client.

    • Lowering cloud provider costs when nodes are distributed across different availability zones (represented as racks).

    In order to enable this functionality:

    Default: False

  • use_services_alternate (bool)

    Flag to signify if “services-alternate” should be used instead of “services”.

    Default: False

  • connect_timeout (int)

    Initial host connection timeout in milliseconds. The timeout when opening a connection to the server host for the first time.

    Default: 1000.

  • fail_if_not_connected (bool)

    Flag to signify fail on cluster init if seed node and all peers are not reachable.

    Default: True

Constants

Policy Options

Commit Level Policy Options

Specifies the number of replicas required to be successfully committed before returning success in a write operation to provide the desired consistency guarantee.

aerospike.POLICY_COMMIT_LEVEL_ALL

Return success only after successfully committing all replicas

aerospike.POLICY_COMMIT_LEVEL_MASTER

Return success after successfully committing the master replica

AP Read Mode Policy Options

Read policy for AP (availability) namespaces.

aerospike.POLICY_READ_MODE_AP_ONE

Involve single node in the read operation.

aerospike.POLICY_READ_MODE_AP_ALL

Involve all duplicates in the read operation.

New in version 3.7.0.

SC Read Mode Policy Options

Read policy for SC (strong consistency) namespaces.

aerospike.POLICY_READ_MODE_SC_SESSION

Ensures this client will only see an increasing sequence of record versions. Server only reads from master.

aerospike.POLICY_READ_MODE_SC_LINEARIZE

Ensures ALL clients will only see an increasing sequence of record versions. Server only reads from master.

New in version 3.7.0.

aerospike.POLICY_READ_MODE_SC_ALLOW_REPLICA

Server may read from master or any full (non-migrating) replica. Increasing sequence of record versions is not guaranteed.

aerospike.POLICY_READ_MODE_SC_ALLOW_UNAVAILABLE

Server may read from master or any full (non-migrating) replica or from unavailable partitions. Increasing sequence of record versions is not guaranteed.

Existence Policy Options

Specifies the behavior for writing the record depending whether or not it exists.

aerospike.POLICY_EXISTS_CREATE

Only create a record given it doesn’t exist

aerospike.POLICY_EXISTS_CREATE_OR_REPLACE

Replace a record completely if it exists, otherwise create it

aerospike.POLICY_EXISTS_IGNORE

Update a record if it exists, otherwise create it

aerospike.POLICY_EXISTS_REPLACE

Only replace a record completely if it exists

aerospike.POLICY_EXISTS_UPDATE

Only update a record if it exists

Generation Policy Options

Specifies the behavior of record modifications with regard to the generation value.

aerospike.POLICY_GEN_IGNORE

Write a record regardless of generation

aerospike.POLICY_GEN_EQ

Write a record only if generations are equal

aerospike.POLICY_GEN_GT

Write a record only if local generation is greater than remote generation

Key Policy Options

Specifies the behavior for whether keys or digests should be sent to the cluster.

aerospike.POLICY_KEY_DIGEST

Calculate the digest on the client-side and send it to the server

aerospike.POLICY_KEY_SEND

Send the key in addition to the digest. This policy causes a write operation to store the key on the server

Replica Options

Specifies which partition replica to read from.

aerospike.POLICY_REPLICA_SEQUENCE

Always try node containing master partition first.

If connection fails and the client is configured to retry, it will try the node containing prole partition. Currently restricted to master and one prole.

aerospike.POLICY_REPLICA_MASTER

Read from the partition master replica node

aerospike.POLICY_REPLICA_ANY

Distribute reads across nodes containing key’s master and replicated partition in round-robin fashion.

Currently restricted to master and one prole.

aerospike.POLICY_REPLICA_PREFER_RACK

Try node on the same rack as the client first.

If there are no nodes on the same rack, use POLICY_REPLICA_SEQUENCE instead.

TTL Constants

Specifies the TTL constants.

aerospike.TTL_NAMESPACE_DEFAULT

Use the namespace default TTL.

aerospike.TTL_NEVER_EXPIRE

Set TTL to never expire.

aerospike.TTL_DONT_UPDATE

Do not change the current TTL of the record.

aerospike.TTL_CLIENT_DEFAULT

NOTE: only applies to the policies mentioned below.

Use the applicable policy ttl in write, operate, batch write, and scan policies. If the policy is not defined for the transaction, use the default client-level policy’s ttl.

Auth Mode Constants

Specifies the type of authentication to be used when communicating with the server.

aerospike.AUTH_INTERNAL

Use internal authentication only.

Hashed password is stored on the server. Do not send clear password.

aerospike.AUTH_EXTERNAL

Use external authentication (like LDAP).

Specific external authentication is configured on server. If TLS defined, send clear password on node login via TLS.

Throw exception if TLS is not defined.

aerospike.AUTH_EXTERNAL_INSECURE

Use external authentication (like LDAP).

Specific external authentication is configured on server. Send clear password on node login whether or not TLS is defined.

Warning

This mode should only be used for testing purposes because it is not secure authentication.

Job Constants

aerospike.JOB_SCAN

Scan job type argument for the module parameter of Client.job_info()

aerospike.JOB_QUERY

Query job type argument for the module parameter of Client.job_info()

Job Statuses

aerospike.JOB_STATUS_UNDEF
aerospike.JOB_STATUS_INPROGRESS
aerospike.JOB_STATUS_COMPLETED

New in version 1.0.50.

Serialization Constants

aerospike.SERIALIZER_USER

Use a user-defined serializer to handle unsupported types. Must have been registered for the aerospike class or configured for the Client object

aerospike.SERIALIZER_NONE

Do not serialize bins whose data type is unsupported (default)

New in version 1.0.47.

Send Bool Constants

Specifies how the Python client will write Python booleans.

aerospike.INTEGER

Write Python Booleans as integers.

aerospike.AS_BOOL

Write Python Booleans as as_bools.

This is the Aerospike server’s boolean type.

List

List Write Flags

Flags used by list write flag.

aerospike.LIST_WRITE_DEFAULT

Default. Allow duplicate values and insertions at any index.

aerospike.LIST_WRITE_ADD_UNIQUE

Only add unique values.

aerospike.LIST_WRITE_INSERT_BOUNDED

Enforce list boundaries when inserting. Do not allow values to be inserted at index outside current list boundaries.

Note

Requires server version >= 4.3.0

aerospike.LIST_WRITE_NO_FAIL

Do not raise error if a list item fails due to write flag constraints (always succeed).

Note

Requires server version >= 4.3.0

aerospike.LIST_WRITE_PARTIAL

Allow other valid list items to be committed if a list item fails due to write flag constraints.

List Return Types

Return types used by various list operations.

aerospike.LIST_RETURN_NONE

Do not return any value.

aerospike.LIST_RETURN_INDEX

Return key index order.

aerospike.LIST_RETURN_REVERSE_INDEX

Return reverse key order.

aerospike.LIST_RETURN_RANK

Return value order.

aerospike.LIST_RETURN_REVERSE_RANK

Return reverse value order.

aerospike.LIST_RETURN_COUNT

Return count of items selected.

aerospike.LIST_RETURN_VALUE

Return value for single key read and value list for range read.

aerospike.LIST_RETURN_EXISTS

Return true if count of items selected > 0.

List Order

Flags used by list order.

aerospike.LIST_UNORDERED

List is not ordered. This is the default.

aerospike.LIST_ORDERED

Ordered list.

List Sort Flags

Flags used by list sort.

aerospike.LIST_SORT_DEFAULT

Default. Preserve duplicates when sorting the list.

aerospike.LIST_SORT_DROP_DUPLICATES

Drop duplicate values when sorting the list.

Maps

Map Write Flag

Flags used by map write flag.

Note

Requires server version >= 4.3.0

aerospike.MAP_WRITE_FLAGS_DEFAULT

Default. Allow create or update.

aerospike.MAP_WRITE_FLAGS_CREATE_ONLY

If the key already exists, the item will be denied. If the key does not exist, a new item will be created.

aerospike.MAP_WRITE_FLAGS_UPDATE_ONLY

If the key already exists, the item will be overwritten. If the key does not exist, the item will be denied.

aerospike.MAP_WRITE_FLAGS_NO_FAIL

Do not raise error if a map item is denied due to write flag constraints (always succeed).

aerospike.MAP_WRITE_FLAGS_PARTIAL

Allow other valid map items to be committed if a map item is denied due to write flag constraints.

Map Order

Flags used by map order.

aerospike.MAP_UNORDERED

Map is not ordered. This is the default.

aerospike.MAP_KEY_ORDERED

Order map by key.

aerospike.MAP_KEY_VALUE_ORDERED

Order map by key, then value.

Map Return Types

Return types used by various map operations.

aerospike.MAP_RETURN_NONE

Do not return any value.

aerospike.MAP_RETURN_INDEX

Return key index order.

aerospike.MAP_RETURN_REVERSE_INDEX

Return reverse key order.

aerospike.MAP_RETURN_RANK

Return value order.

aerospike.MAP_RETURN_REVERSE_RANK

Return reserve value order.

aerospike.MAP_RETURN_COUNT

Return count of items selected.

aerospike.MAP_RETURN_KEY

Return key for single key read and key list for range read.

aerospike.MAP_RETURN_VALUE

Return value for single key read and value list for range read.

aerospike.MAP_RETURN_KEY_VALUE

Return key/value items.

Note that key/value pairs will be returned as a list of keys and values next to each other:

[key1, value1, key2, value2, ...]

aerospike.MAP_RETURN_EXISTS

Return true if count of items selected > 0.

aerospike.MAP_RETURN_UNORDERED_MAP

Return unordered map.

For the Python client, this return type returns the same results as aerospike.MAP_RETURN_ORDERED_MAP.

aerospike.MAP_RETURN_ORDERED_MAP

Return ordered map.

Bitwise

Bitwise Write Flags

aerospike.BIT_WRITE_DEFAULT

Allow create or update (default).

aerospike.BIT_WRITE_CREATE_ONLY

If bin already exists the operation is denied. Otherwise the bin is created.

aerospike.BIT_WRITE_UPDATE_ONLY

If bin does not exist the operation is denied. Otherwise the bin is updated.

aerospike.BIT_WRITE_NO_FAIL

Do not raise error if operation failed.

aerospike.BIT_WRITE_PARTIAL

Allow other valid operations to be committed if this operation is denied due to flag constraints. i.e. If the number of bytes from the offset to the end of the existing Bytes bin is less than the specified number of bytes, then only apply operations from the offset to the end.

New in version 3.9.0.

Bitwise Resize Flags

aerospike.BIT_RESIZE_DEFAULT

Add/remove bytes from the end (default).

aerospike.BIT_RESIZE_FROM_FRONT

Add/remove bytes from the front.

aerospike.BIT_RESIZE_GROW_ONLY

Only allow the bitmap size to increase.

aerospike.BIT_RESIZE_SHRINK_ONLY

Only allow the bitmap size to decrease.

New in version 3.9.0.

Bitwise Overflow

aerospike.BIT_OVERFLOW_FAIL

Operation will fail on overflow/underflow.

aerospike.BIT_OVERFLOW_SATURATE

If add or subtract ops overflow/underflow, set to max/min value. Example: MAXINT + 1 = MAXINT.

aerospike.BIT_OVERFLOW_WRAP

If add or subtract ops overflow/underflow, wrap the value. Example: MAXINT + 1 = MININT.

New in version 3.9.0.

HyperLogLog Write Flags

aerospike.HLL_WRITE_DEFAULT

Default. Allow create or update.

aerospike.HLL_WRITE_CREATE_ONLY

If the bin already exists, the operation will be denied. If the bin does not exist, a new bin will be created.

aerospike.HLL_WRITE_UPDATE_ONLY

If the bin already exists, the bin will be overwritten. If the bin does not exist, the operation will be denied.

aerospike.HLL_WRITE_NO_FAIL

Do not raise error if operation is denied.

aerospike.HLL_WRITE_ALLOW_FOLD

Allow the resulting set to be the minimum of provided index bits. For intersect_counts and similarity, allow the usage of less precise HLL algorithms when minhash bits of all participating sets do not match.

New in version 3.11.0.

Write Expression Flags

Flags used by expression_write.

aerospike.EXP_WRITE_DEFAULT

Default. Allow create or update.

aerospike.EXP_WRITE_CREATE_ONLY

If bin does not exist, a new bin will be created. If bin exists, the operation will be denied. If bin exists, fail with BinExistsError when EXP_WRITE_POLICY_NO_FAIL is not set.

aerospike.EXP_WRITE_UPDATE_ONLY

If bin exists, the bin will be overwritten. If bin does not exist, the operation will be denied. If bin does not exist, fail with BinNotFound when EXP_WRITE_POLICY_NO_FAIL is not set.

aerospike.EXP_WRITE_ALLOW_DELETE

If expression results in nil value, then delete the bin. Otherwise, return OpNotApplicable when EXP_WRITE_POLICY_NO_FAIL is not set.

aerospike.EXP_WRITE_POLICY_NO_FAIL

Do not raise error if operation is denied.

aerospike.EXP_WRITE_EVAL_NO_FAIL

Ignore failures caused by the expression resolving to unknown or a non-bin type.

Read Expression Flags

Flags used by expression_read.

aerospike.EXP_READ_DEFAULT

Default.

aerospike.EXP_READ_EVAL_NO_FAIL

Ignore failures caused by the expression resolving to unknown or a non-bin type.

Bin Types

aerospike.AS_BYTES_UNDEF

(int): 0

aerospike.AS_BYTES_INTEGER

(int): 1

aerospike.AS_BYTES_DOUBLE

(int): 2

aerospike.AS_BYTES_STRING

(int): 3

aerospike.AS_BYTES_BLOB

(int): 4

aerospike.AS_BYTES_JAVA

(int): 7

aerospike.AS_BYTES_CSHARP

(int): 8

aerospike.AS_BYTES_PYTHON

(int): 9

aerospike.AS_BYTES_RUBY

(int): 10

aerospike.AS_BYTES_PHP

(int): 11

aerospike.AS_BYTES_ERLANG

(int): 12

aerospike.AS_BYTES_BOOL

(int): 17

aerospike.AS_BYTES_HLL

(int): 18

aerospike.AS_BYTES_MAP

(int): 19

aerospike.AS_BYTES_LIST

(int): 20

aerospike.AS_BYTES_GEOJSON

(int): 23

aerospike.AS_BYTES_TYPE_MAX

(int): 24

Miscellaneous

aerospike.__version__

A str containing the module’s version.

New in version 1.0.54.

aerospike.UDF_TYPE_LUA

UDF type is LUA (which is the only UDF type).

aerospike.INDEX_STRING

An index whose values are of the aerospike string data type.

aerospike.INDEX_NUMERIC

An index whose values are of the aerospike integer data type.

aerospike.INDEX_BLOB

An index whose values are of the aerospike blob data type.

aerospike.INDEX_GEO2DSPHERE

An index whose values are of the aerospike GetJSON data type.

See also

Data Types.

aerospike.INDEX_TYPE_DEFAULT

Index a bin that doesn’t contain a complex data type.

aerospike.INDEX_TYPE_LIST

Index a bin whose contents is an aerospike list.

aerospike.INDEX_TYPE_MAPKEYS

Index the keys of a bin whose contents is an aerospike map.

aerospike.INDEX_TYPE_MAPVALUES

Index the values of a bin whose contents is an aerospike map.

Log Level

aerospike.LOG_LEVEL_TRACE
aerospike.LOG_LEVEL_DEBUG
aerospike.LOG_LEVEL_INFO
aerospike.LOG_LEVEL_WARN
aerospike.LOG_LEVEL_ERROR
aerospike.LOG_LEVEL_OFF

Privileges

Permission codes define the type of permission granted for a user’s role.

aerospike.PRIV_READ

The user is granted read access.

aerospike.PRIV_WRITE

The user is granted write access.

aerospike.PRIV_READ_WRITE

The user is granted read and write access.

aerospike.PRIV_READ_WRITE_UDF

The user is granted read and write access, and the ability to invoke UDFs.

aerospike.PRIV_SYS_ADMIN

The user is granted the ability to perform system administration operations. Global scope only.

aerospike.PRIV_USER_ADMIN

The user is granted the ability to perform user administration operations. Global scope only.

aerospike.PRIV_DATA_ADMIN

User can perform systems administration functions on a database that do not involve user administration. Examples include setting dynamic server configuration. Global scope only.

aerospike.PRIV_TRUNCATE

User can truncate data only. Requires server 6.0+

aerospike.PRIV_UDF_ADMIN

User can perform user defined function(UDF) administration actions. Examples include create/drop UDF. Global scope only. Global scope only. Requires server version 6.0+

aerospike.PRIV_SINDEX_ADMIN

User can perform secondary index administration actions. Examples include create/drop index. Global scope only. Requires server version 6.0+

Regex Flag Values

Flags used by the aerospike_operation_helpers.expressions.base.CmpRegex Aerospike expression. See aerospike_helpers.expressions package for more information.

aerospike.REGEX_NONE

Use default behavior.

aerospike.REGEX_ICASE

Do not differentiate case.

aerospike.REGEX_EXTENDED

Use POSIX Extended Regular Expression syntax when interpreting regex.

aerospike.REGEX_NOSUB

Do not report position of matches.

aerospike.REGEX_NEWLINE

Match-any-character operators don’t match a newline.