Skip to main content
Version: 0.9.1

Types

All types are importable from aerospike_py or aerospike_py.types.

from aerospike_py import Record, ExistsResult, ReadPolicy, WritePolicy, WriteMeta

Return Types (NamedTuple)

All return types support both attribute access and tuple unpacking.

Record

Returned by: get(), select(), operate(), Query.results()

FieldTypeDescription
keyAerospikeKey | NoneRecord key
metaRecordMetadata | NoneGeneration and TTL
binsdict[str, Any] | NoneBin values
record: Record = client.get(key)
print(record.bins) # attribute access
_, meta, bins = record # tuple unpacking

RecordMetadata

FieldTypeDescription
genintGeneration (optimistic lock version)
ttlintTime-to-live in seconds

AerospikeKey

FieldTypeDescription
namespacestrNamespace
set_namestrSet name
user_keystr | int | bytes | NonePrimary key (None if POLICY_KEY_DIGEST)
digestbytes20-byte RIPEMD-160 digest

BatchRecord

Returned by: batch operations (inside BatchRecords.batch_records)

FieldTypeDescription
keyAerospikeKey | NoneRecord key
resultintPer-record result code (0 = success)
recordRecord | NoneRecord data (None if operation failed)
in_doubtboolWhether the write may have completed despite a transient error (default False)
results = client.batch_operate(keys, ops)
for br in results.batch_records:
if br.result == 0 and br.record is not None:
print(br.record.bins)

BatchRecords

Returned by: sync batch_read(), batch_write(), batch_operate(), batch_remove(), batch_write_numpy()

FieldTypeDescription
batch_recordslist[BatchRecord]Per-record results

BatchReadHandle

Returned by: async batch_read() (zero-conversion handle wrapping raw Rust results)

Method / PropertyTypeDescription
as_dict()dict[str | int, dict[str, Any]]Fastest path: returns dict[key, bins_dict] directly. Excludes digest-only and failed records.
batch_recordslist[BatchRecord]Compat path: lazy NamedTuple conversion, cached after first access.
found_count()intCount of successful records (no conversion needed).
keys()list[str | int]Extract user keys without converting record data.
len(handle)intTotal number of records (including failures).
handle[i]BatchRecordIndex access with negative index support.
for br in handleBatchRecordIteration (via batch_records).

ExistsResult

Returned by: exists()

FieldTypeDescription
keyAerospikeKey | NoneRecord key
metaRecordMetadata | NoneNone if record does not exist
result: ExistsResult = client.exists(key)
if result.meta is not None:
print(f"gen={result.meta.gen}")

InfoNodeResult

Returned by: info_all()

FieldTypeDescription
node_namestrCluster node name
error_codeint0 on success
responsestrInfo response string

OperateOrderedResult

Returned by: operate_ordered()

FieldTypeDescription
keyAerospikeKey | NoneRecord key
metaRecordMetadata | NoneRecord metadata
ordered_binslist[BinTuple]Ordered operation results

BinTuple

FieldTypeDescription
namestrBin name
valueAnyBin value

Return Type Quick Reference

MethodReturn Type
get(), select()Record
exists()ExistsResult
operate()Record
operate_ordered()OperateOrderedResult
info_all()list[InfoNodeResult]
batch_read() (sync)BatchRecords | NumpyBatchRecords
batch_read() (async)BatchReadHandle | NumpyBatchRecords
batch_write(), batch_operate(), batch_remove()BatchRecords
batch_write_numpy()BatchRecords
Query.results()list[Record]

Input Types (TypedDict)

All fields are optional (total=False).

ClientConfig

Used by: aerospike_py.client(config), AsyncClient(config)

FieldTypeDefaultDescription
hostslist[tuple[str, int]]requiredSeed nodes
cluster_namestrExpected cluster name
auth_modeintAUTH_INTERNALAUTH_INTERNAL, AUTH_EXTERNAL, AUTH_PKI
userstrAuthentication username
passwordstrAuthentication password
timeoutint1000Connection timeout (ms)
idle_timeoutintConnection idle timeout (ms)
max_conns_per_nodeint100Max connections per node
min_conns_per_nodeint0Pre-warm connections
tend_intervalint1000Cluster tend interval (ms)
use_services_alternateboolfalseUse alternate service addresses

ReadPolicy

Used by: get(), select(), exists()

FieldTypeDefaultDescription
socket_timeoutint30000Socket timeout (ms)
total_timeoutint1000Total transaction timeout (ms)
max_retriesint2Max retries
sleep_between_retriesint0Sleep between retries (ms)
timeout_delayint0Delay (ms) before timing out a request after the deadline. Drains the socket so reused connections do not see stale responses.
filter_expressionAnyExpression filter built via aerospike_py.exp.
replicaintPOLICY_REPLICA_SEQUENCEReplica selection algorithm.
read_mode_apintPOLICY_READ_MODE_AP_ONEAP namespace read consistency. Maps to aerospike-core ConsistencyLevel.
read_touch_ttl_percentint0Reset TTL on read when within N% of original write TTL (server v8+). 0 = server default, -1 = never reset, 1..=100 = percent.

WritePolicy

Used by: put(), remove(), touch(), append(), prepend(), increment(), remove_bin(), operate(), operate_ordered()

FieldTypeDefaultDescription
socket_timeoutint30000Socket timeout (ms)
total_timeoutint1000Total transaction timeout (ms)
max_retriesint0Max retries
timeout_delayint0Delay (ms) before timing out a request after the deadline.
durable_deleteboolfalseDurable delete (Enterprise)
keyintPOLICY_KEY_DIGESTKey send policy
existsintPOLICY_EXISTS_IGNOREExistence policy
genintPOLICY_GEN_IGNOREGeneration policy
commit_levelintPOLICY_COMMIT_LEVEL_ALLCommit level
ttlint0Record TTL (seconds)
filter_expressionAnyExpression filter (aerospike_py.exp).
read_mode_apintPOLICY_READ_MODE_AP_ONEAP read consistency for read-after-write operate() ops.
read_touch_ttl_percentint0Reset TTL on read within N% of write TTL (server v8+).

BatchPolicy

Used by: batch_read(), batch_operate(), batch_write(), batch_remove()

Transport / batch-level fields

FieldTypeDefaultDescription
socket_timeoutint30000Socket timeout (ms)
total_timeoutint1000Total transaction timeout (ms)
max_retriesint2Max retries
timeout_delayint0Delay (ms) before timing out a request after the deadline.
concurrencyintBATCH_CONCURRENCY_PARALLELPer-node dispatch mode: BATCH_CONCURRENCY_SEQUENTIAL (one node at a time) or BATCH_CONCURRENCY_PARALLEL (all nodes in parallel — default). See Batch Concurrency constants. Other values raise ValueError.
filter_expressionAnyExpression filter
allow_inlinebooltrueAllow server inline processing in receiving thread
allow_inline_ssdboolfalseAllow inline processing for SSD namespaces
respond_all_keysbooltrueAttempt all keys regardless of per-record errors
replicaintPOLICY_REPLICA_SEQUENCEReplica selection.
read_mode_apintPOLICY_READ_MODE_AP_ONEAP read consistency for batch_read.
read_touch_ttl_percentint0Reset TTL on read within N% of write TTL (server v8+).

Write defaults (used by batch_write)

These fields apply to every record in a batch_write() call. Per-record WriteMeta overrides them — see the precedence rule.

FieldTypeDefaultDescription
keyintPOLICY_KEY_DIGESTKey send policy. Set POLICY_KEY_SEND to persist user keys server-side.
existsintPOLICY_EXISTS_UPDATEExistence policy (UPDATE, CREATE_ONLY, REPLACE, etc.).
genintPOLICY_GEN_IGNOREGeneration policy. Note: at batch-level, this is the POLICY_GEN_* enum index. Per-record WriteMeta["gen"] is the expected generation value.
commit_levelintPOLICY_COMMIT_LEVEL_ALLCommit level (ALL or MASTER).
durable_deleteboolfalseDurable delete (Enterprise 3.10+).
ttlint0Record TTL in seconds (0 = namespace default, -1 = never expire, -2 = don't update).

QueryPolicy

Used by: Query.results(), Query.foreach()

FieldTypeDefaultDescription
socket_timeoutint30000Socket timeout (ms)
total_timeoutint0Total timeout (0 = no limit)
max_retriesint2Max retries
timeout_delayint0Delay (ms) before timing out a request after the deadline.
max_recordsint0Max records (0 = all)
records_per_secondint0Rate limit per node (0 = unlimited).
max_concurrent_nodesint0Limit parallel node queries (0 = unlimited).
record_queue_sizeint1024Buffer capacity for record results.
filter_expressionAnyExpression filter.
replicaintPOLICY_REPLICA_SEQUENCEReplica selection.
read_mode_apintPOLICY_READ_MODE_AP_ONEAP read consistency.
read_touch_ttl_percentint0Reset TTL on read within N% of write TTL (server v8+).
expected_durationintQUERY_DURATION_LONGServer hint about query duration (QUERY_DURATION_LONG / _SHORT / _LONG_RELAX_AP).
include_bin_databooltrueInclude bin payload in results. Set False to fetch keys/metadata only.
partition_filterPartitionFilter(all 4096)Restrict the query/scan to a partition subset. Use aerospike_py.partition_filter_*() helpers.

ScanPolicy

Used by: client.scan() and client.query() invocations without a where() predicate. Mirrors the official Python C client's ScanPolicy. Currently the Rust layer routes scan calls through the QueryPolicy parser — when aerospike-core exposes a separate ScanPolicy struct, scan paths will switch to a dedicated parser without changing this user-facing type. See issue #316.

FieldTypeDefaultDescription
socket_timeoutint30000Socket timeout (ms).
total_timeoutint0Total timeout (0 = no limit).
max_retriesint2Max retries.
timeout_delayint0Delay (ms) before timing out a request after the deadline.
filter_expressionAnyExpression filter.
replicaintPOLICY_REPLICA_SEQUENCEReplica selection.
read_mode_apintPOLICY_READ_MODE_AP_ONEAP read consistency.
records_per_secondint0Rate limit per node (0 = unlimited; server 4.7+).
max_recordsint0Approx max records returned (0 = all; server 6.0+).
durable_deleteboolfalseBackground scan-write durable delete (Enterprise 3.10+).
ttlint0Default TTL for background scan-writes.
partition_filterPartitionFilter(all 4096)Restrict the scan to a partition subset.

BatchReadPolicy

Used by: per-record policy in batch_read().

FieldTypeDefaultDescription
read_touch_ttl_percentint0Reset TTL on read within N% of write TTL (server v8+). 0 = server default, -1 = never reset, 1..=100 = percent.
filter_expressionAnyExpression filter. Records that fail return BatchRecord.result == FILTERED_OUT.

BatchDeletePolicy

Used by: batch-level policy for batch_remove(). Per-record overrides go in BatchDeleteMeta.

FieldTypeDefaultDescription
genintPOLICY_GEN_IGNOREGeneration policy enum (POLICY_GEN_*).
keyintPOLICY_KEY_DIGESTSend user key with the delete (XDR-friendly).
commit_levelintPOLICY_COMMIT_LEVEL_ALLCommit level.
durable_deleteboolfalseLeave a tombstone (Enterprise 3.10+).
filter_expressionAnyExpression filter.

BatchDeleteMeta

Per-record meta for batch_remove(). Pass as the second element of a (key, meta) tuple in the keys argument. Setting gen enables CAS-style "delete only if generation matches" semantics — server returns per-record GENERATION_ERROR if generation has advanced.

FieldTypeDescription
genintExpected generation. Setting this implies POLICY_GEN_EQ.
keyintKey send policy (POLICY_KEY_DIGEST / POLICY_KEY_SEND).
commit_levelintCommit level (POLICY_COMMIT_LEVEL_ALL / _MASTER).
durable_deleteboolDurable delete (Enterprise 3.10+).
# CAS delete: only delete user_1 if generation is still 3.
client.batch_remove([
(("test", "demo", "user_1"), {"gen": 3}),
("test", "demo", "user_2"), # bare key, no CAS
])

BatchUDFPolicy

Used by: batch-level UDF policy for batch_apply(). Per-record overrides go in BatchUDFMeta. Transport-level options (timeouts, retries, concurrency, etc.) live on BatchPolicy and are merged into the same policy dict you pass to batch_apply().

FieldTypeDefaultDescription
commit_levelintPOLICY_COMMIT_LEVEL_ALLCommit level (POLICY_COMMIT_LEVEL_ALL / _MASTER).
ttlint0Record TTL in seconds (0 = namespace default, -1 = never expire, -2 = don't update).
keyintPOLICY_KEY_DIGESTKey send policy (POLICY_KEY_DIGEST / POLICY_KEY_SEND).
durable_deleteboolfalseDurable delete for UDFs that delete records (Enterprise 3.10+).
filter_expressionAnyExpression filter applied to each record. Records that fail the filter return BatchRecord.result == FILTERED_OUT.

BatchUDFMeta

Per-record meta for batch_apply(). Pass as the second element of a (key, meta) tuple in the keys argument. Single flat dict (matching BatchDeleteMeta) that may both override the UDF call shape and the policy fields for a specific record.

FieldTypeDescription
modulestrOverride the UDF module name for this record. Falls back to the module argument of batch_apply().
functionstrOverride the UDF function name for this record.
argslist[Any]Override the argument list. Passing [] explicitly clears the default args.
ttlintOverride TTL in seconds for this record (same semantics as WriteMeta.ttl).
commit_levelintOverride commit level.
keyintOverride key send policy (POLICY_KEY_DIGEST / POLICY_KEY_SEND).
durable_deleteboolOverride durable_delete.
note

filter_expression is not accepted in BatchUDFMeta — set it on the batch-level BatchUDFPolicy instead. (Per-record filter_expression is unwired in aerospike-core 2.0; matches the BatchDeleteMeta shape.)

# Apply the same UDF to many keys.
keys = [("test", "demo", f"u_{i}") for i in range(10)]
results = client.batch_apply(keys, "my_udf", "increment_counter", [1])

# Per-record overrides: different args / longer TTL on one record.
results = client.batch_apply(
[
("test", "demo", "u_1"), # uses default args
(("test", "demo", "u_2"), {"args": [5], "ttl": 3600}),
],
"my_udf", "increment_counter", args=[1],
)

PartitionFilter

Opaque handle scoping a query/scan to a subset of partitions (server 6.0+). Construct via the module-level helpers:

import aerospike_py

pf_all = aerospike_py.partition_filter_all()
pf_one = aerospike_py.partition_filter_by_id(42) # single partition (0..4095)
pf_range = aerospike_py.partition_filter_by_range(0, 1024) # 1/4 of partitions
records = client.query("test", "demo").results(policy={"partition_filter": pf_range})

The handle holds mutable internal state (Arc<Mutex<Vec<PartitionStatus>>>). aerospike-py clones the inner filter at parse time so the user's handle is isolated from in-flight query state mutations. To deliberately resume a scan from where the previous run left off, pass the same handle to multiple results() calls — see issue #318 for v2 cursor semantics.

AdminPolicy

Used by: all admin_* methods, index operations, truncate()

FieldTypeDefaultDescription
timeoutint1000Timeout (ms)

WriteMeta

Used by: put(), remove(), touch(), operate() as the meta parameter, and per-record in batch_write() as the third tuple element (key, bins, meta).

In batch_write(), fields set in per-record WriteMeta override the corresponding batch-level BatchPolicy defaults — see the precedence rule.

FieldTypeDescription
genintExpected generation. Setting this implies POLICY_GEN_EQ (CAS-style write).
ttlintRecord TTL in seconds. Special values: 0 = namespace default, -1 = never expire, -2 = don't update.
keyintKey send policy (POLICY_KEY_DIGEST / POLICY_KEY_SEND).
existsintExistence policy (POLICY_EXISTS_*).
commit_levelintCommit level (POLICY_COMMIT_LEVEL_ALL / _MASTER).
durable_deleteboolDurable delete (Enterprise 3.10+).

Write field precedence (batch_write)

For every write field, per-record WriteMeta always wins over batch-level BatchPolicy:

FieldBatchPolicy (batch-level)WriteMeta (per-record)Notes
ttlSame semantics on both sides.
keySet POLICY_KEY_SEND to persist user keys server-side.
existse.g. POLICY_EXISTS_CREATE_ONLY for upsert-fail-on-exists.
gen✅ (enum index)✅ (expected value)Asymmetric: batch-level = POLICY_GEN_* enum index; per-record = numeric generation that forces POLICY_GEN_EQ.
commit_level
durable_delete

Privilege

Used by: admin_create_role(), admin_grant_privileges(), admin_revoke_privileges()

FieldTypeDescription
codeintPrivilege code (PRIV_READ, PRIV_WRITE, etc.)
nsstrNamespace scope (empty = global)
setstrSet scope (empty = namespace-wide)

UserInfo

Returned by: admin_query_user_info(), admin_query_users_info()

FieldTypeDescription
userstrUsername
roleslist[str]Assigned roles
conns_in_useintActive connections

RoleInfo

Returned by: admin_query_role(), admin_query_roles()

FieldTypeDescription
namestrRole name
privilegeslist[Privilege]Assigned privileges
allowlistlist[str]IP allowlist
read_quotaintRead quota
write_quotaintWrite quota