Behavior

class aerospike_sdk.policy.behavior.Behavior[source]

Bases: object

Immutable, scope-aware configuration for Aerospike operation policies.

A Behavior holds a set of scope-keyed Settings patches that are resolved at operation time based on the operation’s kind, shape, and namespace mode. More-specific scopes override less-specific ones, and a child Behavior inherits from its parent.

Resolved settings are eagerly cached at construction time so that get_settings() is a simple dict lookup.

Example:

# Use a pre-defined behavior
session = cluster.create_session(Behavior.DEFAULT)

# Derive a custom behavior with scope-specific overrides
fast = Behavior.DEFAULT.derive_with_changes(
    "fast_reads",
    reads=Settings(total_timeout=timedelta(milliseconds=200)),
    reads_batch=Settings(max_concurrent_nodes=8),
)
session = cluster.create_session(fast)
DEFAULT

Balanced defaults (30 s total timeout, 2 retries, send key).

READ_FAST

Low-latency reads (200 ms total, 50 ms socket, 3 retries).

STRICTLY_CONSISTENT

SC-namespace reads with linearizable consistency.

FAST_RACK_AWARE

Low-latency rack-preferred reads.

DEFAULT: ClassVar[Behavior] = Behavior(name='DEFAULT', total_timeout=0:00:30, socket_timeout=0:00:05, max_retries=2)
READ_FAST: ClassVar[Behavior] = Behavior(name='READ_FAST', total_timeout=0:00:00.200000, socket_timeout=0:00:00.050000, max_retries=3)
STRICTLY_CONSISTENT: ClassVar[Behavior] = Behavior(name='STRICTLY_CONSISTENT', total_timeout=0:00:30, socket_timeout=0:00:05, max_retries=2)
FAST_RACK_AWARE: ClassVar[Behavior] = Behavior(name='FAST_RACK_AWARE', total_timeout=0:00:00.200000, socket_timeout=0:00:00.050000, max_retries=3)
__init__(name, patches, parent=None)[source]
property name: str

Identifier for this behavior (for example 'DEFAULT').

property parent: Behavior | None

Behavior from which this one inherits, or None for root.

property children: List[Behavior]

Behaviors derived from this one via derive_with_changes().

get_settings(kind, shape, mode=Mode.AP)[source]

Return the fully-resolved Settings for the given operation context.

This is a cached O(1) dict lookup; the matrix is pre-computed at construction time.

Return type:

Settings

clear_cache()[source]

Recompute the resolved settings matrix and cascade to children.

Return type:

None

derive_with_changes(name, *, all=None, reads=None, reads_point=None, reads_batch=None, reads_query=None, reads_ap=None, reads_sc=None, writes=None, writes_retryable=None, writes_non_retryable=None, writes_point=None, writes_batch=None, writes_query=None, writes_ap=None, writes_sc=None, total_timeout=None, socket_timeout=None, max_retries=None, retry_delay=None, send_key=None, use_compression=None)[source]

Create a child Behavior with the specified overrides.

Accepts either scope-keyed Settings objects or flat keyword arguments (which are applied to the ALL scope). Both styles can be combined; flat kwargs are merged into the all Settings.

Example:

fast_reads = default_behavior.derive_with_changes(
    "fast_reads",
    reads=Settings(total_timeout=timedelta(milliseconds=200)),
)
Return type:

Behavior

find_behavior(name)[source]

Search this behavior and its descendants for one with name.

Return type:

Optional[Behavior]

Returns:

The matching Behavior, or None if not found.

explain()[source]

Return a human-readable summary of overrides and resolved settings.

Example:

print(behavior.explain())
Return type:

str

Returns:

Multi-line string with overrides and the full resolved settings matrix.

property total_timeout: timedelta

Total timeout for point reads (from READ:POINT:AP scope).

property socket_timeout: timedelta

Socket timeout for point reads (from READ:POINT:AP scope).

property max_retries: int

Max retries for point reads (from READ:POINT:AP scope).

property retry_delay: timedelta

Retry delay for point reads (from READ:POINT:AP scope).

property send_key: bool

Whether to send the user key with point reads (from READ:POINT:AP scope).

Behavior Settings

Settings and scope types for the Behavior model.

class aerospike_sdk.policy.behavior_settings.OpKind[source]

Bases: Enum

The kind of database operation.

READ = 'read'
WRITE_RETRYABLE = 'write_retryable'
WRITE_NON_RETRYABLE = 'write_non_retryable'
class aerospike_sdk.policy.behavior_settings.OpShape[source]

Bases: Enum

The shape (cardinality) of the operation.

POINT = 'point'
BATCH = 'batch'
QUERY = 'query'
class aerospike_sdk.policy.behavior_settings.Mode[source]

Bases: Enum

Namespace consistency mode.

AP = 'ap'
SC = 'sc'
class aerospike_sdk.policy.behavior_settings.Scope[source]

Bases: Enum

Named scopes for configuring operation settings within a Behavior.

Scope values correspond to keyword arguments accepted by Behavior.derive_with_changes().

ALL = 'all'
READS = 'reads'
READS_POINT = 'reads_point'
READS_BATCH = 'reads_batch'
READS_QUERY = 'reads_query'
READS_AP = 'reads_ap'
READS_SC = 'reads_sc'
WRITES = 'writes'
WRITES_RETRYABLE = 'writes_retryable'
WRITES_NON_RETRYABLE = 'writes_non_retryable'
WRITES_POINT = 'writes_point'
WRITES_BATCH = 'writes_batch'
WRITES_QUERY = 'writes_query'
WRITES_AP = 'writes_ap'
WRITES_SC = 'writes_sc'
class aerospike_sdk.policy.behavior_settings.Settings[source]

Bases: object

Immutable set of operation settings.

All fields are Optional; None means “not configured / inherit from a less-specific scope or the parent Behavior”.

total_timeout: timedelta | None = None
socket_timeout: timedelta | None = None
max_retries: int | None = None
retry_delay: timedelta | None = None
send_key: bool | None = None
durable_delete: bool | None = None
commit_level: CommitLevel | None = None
replica: Replica | None = None
read_mode_ap: ReadModeAP | None = None
read_mode_sc: ReadModeSC | None = None
use_compression: bool | None = None
max_concurrent_nodes: int | None = None
record_queue_size: int | None = None
allow_inline: bool | None = None
allow_inline_ssd: bool | None = None
read_touch_ttl_percent: int | None = None
classmethod merge(base, override)[source]

Merge two Settings; override’s non-None fields win.

Return type:

Settings

__init__(total_timeout=None, socket_timeout=None, max_retries=None, retry_delay=None, send_key=None, durable_delete=None, commit_level=None, replica=None, read_mode_ap=None, read_mode_sc=None, use_compression=None, max_concurrent_nodes=None, record_queue_size=None, allow_inline=None, allow_inline_ssd=None, read_touch_ttl_percent=None)
aerospike_sdk.policy.behavior_settings.resolution_order(kind, shape, mode=Mode.AP)[source]

Return applicable scopes from least-specific to most-specific.

Used by Behavior.get_settings() to layer patches so that more-specific scopes override less-specific ones.

Return type:

tuple[Scope, ...]