SyncSession

class aerospike_sdk.sync.session.SyncSession[source]

Bases: object

Run session-scoped reads and writes without async/await.

Constructed by SyncClient.create_session, not by calling SyncSession(...) directly. Each method delegates to Session on a shared per-thread loop; return types are sync wrappers where the async API would return a coroutine or async stream.

See also

Session: Async API and behavior

semantics.

__init__(async_session, loop_manager)[source]

Wrap async_session; use SyncClient.create_session() instead.

Parameters:
  • async_session (Session) – Connected async session (same behavior binding).

  • loop_manager (_EventLoopManager) – Loop manager shared with the parent SyncClient.

property behavior: Behavior

Get the behavior configuration for this session.

property client: Client

Get the underlying Client.

query(arg1=None, arg2=None, *keys, namespace=None, set_name=None, dataset=None, key=None, keys_list=None, behavior=None)[source]

Start a read or secondary-index query (synchronous session).

Same shapes as aerospike_sdk.aio.session.Session.query(), with this session’s behavior applied on the underlying async builder.

Parameters:
  • arg1 (Union[DataSet, Key, List[Key], str, None]) – Positional dataset, key, list of keys, or namespace string (when paired with arg2 as set name).

  • arg2 (Union[str, Key, None]) – When arg1 is a namespace, the set name; otherwise may be a second key when passing multiple keys positionally.

  • *keys (Key) – Additional keys when the first positional argument is a key.

  • namespace (Optional[str]) – Keyword namespace (with set_name) when not using a dataset.

  • set_name (Optional[str]) – Keyword set name (with namespace).

  • dataset (Optional[DataSet]) – Keyword DataSet.

  • key (Optional[Key]) – Keyword single key.

  • keys_list (Optional[List[Key]]) – Keyword list of keys for batch read.

  • behavior (Optional[Behavior]) – Optional per-query behavior override (same as async session).

Return type:

SyncQueryBuilder

Returns:

A SyncQueryBuilder.

batch()[source]

Start a multi-key batch of mixed write operations (synchronous).

Chain insert, update, upsert, replace, delete, and bin builders, then execute() for a SyncRecordStream.

Return type:

SyncBatchOperationBuilder

Returns:

A SyncBatchOperationBuilder.

Raises:

RuntimeError – If the client is not connected (from the async session).

Example:

stream = (
    session.batch()
    .insert(key1).put({"name": "Alice", "age": 25})
    .update(key2).bin("counter").add(1)
    .execute()
)
for row in stream:
    print(row.key, row.result_code)

See also

batch()

transaction_session()[source]

Alias for begin_transaction().

Return type:

SyncTransactionalSession

Returns:

SyncTransactionalSession bound to this session’s client and behavior.

See also

begin_transaction(): Preferred entry point. transaction_session(): Async equivalent.

begin_transaction()[source]

Start a multi-record transaction (MRT) using this session’s behavior.

Returns a context manager that allocates a fresh Txn. Every operation run on the returned session auto-participates in the transaction — builders stamp policy.txn = tx.txn under the hood, so user code never touches a policy object. On clean exit the transaction is committed; if an exception propagates out of the with block the transaction is aborted.

Example

>>> with session.begin_transaction() as tx:
...     tx.upsert(accounts.id("A")).bin("balance").set_to(100).execute()
...     tx.upsert(accounts.id("B")).bin("balance").set_to(200).execute()
Return type:

SyncTransactionalSession

Returns:

SyncTransactionalSession bound to this session’s client and behavior.

See also

transaction_session(): Alias for this method. do_in_transaction(): Run a callable inside a retrying MRT. begin_transaction(): Async equivalent.

do_in_transaction(operation, *, max_attempts=5, sleep_between_retries=0.0)[source]

Run a callable inside a retrying multi-record transaction.

Creates a SyncTransactionalSession, invokes operation(tx) inside with, and retries the whole block when the server signals a transient conflict (MRT_BLOCKED, MRT_VERSION_MISMATCH, or TXN_FAILED). On any non-transient failure the transaction is aborted and the exception re-raised.

Parameters:
  • operation (Callable[[SyncTransactionalSession], Any]) – Synchronous callable accepting a SyncTransactionalSession and performing zero or more operations on it. Its return value is returned from do_in_transaction().

  • max_attempts (int) – Maximum total attempts (initial + retries). Must be >= 1. Defaults to 5.

  • sleep_between_retries (float) – Optional seconds to time.sleep between retries. 0 (the default) retries immediately.

Return type:

Any

Returns:

Whatever operation returns on the successful attempt.

Raises:
  • ValueError – If max_attempts < 1.

  • AerospikeError – The last-seen transient error after max_attempts exhausted retries, or any non-transient error raised by operation.

Example

>>> def transfer(tx):
...     tx.upsert(accounts.id("A")).bin("bal").add(-10).execute()
...     tx.upsert(accounts.id("B")).bin("bal").add(10).execute()
...     return "ok"
>>> result = session.do_in_transaction(transfer)

See also

begin_transaction(): Manual MRT lifecycle. SyncTransactionalSession do_in_transaction(): Async equivalent.

background_task()[source]

Start a background dataset task chain (synchronous).

Return type:

SyncBackgroundTaskSession

Returns:

SyncBackgroundTaskSession.

See also

background_task().

execute_udf(*keys)[source]

Begin a foreground UDF invocation on the given keys (synchronous).

Return type:

SyncUdfFunctionBuilder

Returns:

SyncUdfFunctionBuilder.

See also

execute_udf().

index(namespace=None, set_name=None, *, dataset=None, behavior=None)[source]

Create a secondary-index builder for this namespace/set (synchronous).

Raises:

ValueError – If namespace and set_name are missing and no dataset is provided.

Return type:

SyncIndexBuilder

Returns:

SyncIndexBuilder.

See also

index().

truncate(dataset, before_nanos=None)[source]

Truncate (delete all records) from a set (synchronous).

Return type:

None

is_namespace_sc(namespace)[source]

Check if a namespace is in strong-consistency (SC) mode.

Parameters:

namespace (str) – The namespace name to check.

Return type:

bool

Returns:

True if the namespace is configured for strong consistency, False otherwise.

Raises:
  • RuntimeError – If the underlying client is not connected.

  • ValueError – If the namespace is unknown or the info command fails.

Example:

if session.is_namespace_sc("test_sc"):
    print("Namespace is SC — MRTs are supported here.")

See also

is_namespace_sc():

Async equivalent.

info(command=None)[source]
Overloads:
  • selfSyncInfoCommands

  • self, command (str) → Dict[str, str]

Execute info commands or get the SyncInfoCommands helper (synchronous).

With no argument, returns SyncInfoCommands for high-level helpers and info_on_all_nodes(). With a command string, runs the raw info command and returns its result.

Example:

response = session.info("sindex-list")
info = session.info()
by_node = info.info_on_all_nodes("build")
upsert(arg1=None, arg2=None, *keys, key=None, dataset=None, namespace=None, set_name=None, key_value=None)[source]

Create an upsert write segment (synchronous).

Return type:

SyncWriteSegmentBuilder

insert(arg1=None, arg2=None, *keys, key=None, dataset=None, namespace=None, set_name=None, key_value=None)[source]

Create an insert write segment (synchronous).

Return type:

SyncWriteSegmentBuilder

update(arg1=None, arg2=None, *keys, key=None, dataset=None, namespace=None, set_name=None, key_value=None)[source]

Create an update write segment (synchronous).

Return type:

SyncWriteSegmentBuilder

replace(arg1=None, arg2=None, *keys, key=None, dataset=None, namespace=None, set_name=None, key_value=None)[source]

Create a replace write segment (synchronous).

Return type:

SyncWriteSegmentBuilder

replace_if_exists(arg1=None, arg2=None, *keys, key=None, dataset=None, namespace=None, set_name=None, key_value=None)[source]

Create a replace-if-exists write segment (synchronous).

Return type:

SyncWriteSegmentBuilder

delete(arg1=None, arg2=None, *keys, key=None, dataset=None, namespace=None, set_name=None, key_value=None)[source]

Create a delete write segment (synchronous).

Return type:

SyncWriteSegmentBuilder

touch(arg1=None, arg2=None, *keys, key=None, dataset=None, namespace=None, set_name=None, key_value=None)[source]

Create a touch write segment (synchronous).

Return type:

SyncWriteSegmentBuilder

exists(arg1=None, arg2=None, *keys, key=None, dataset=None, namespace=None, set_name=None, key_value=None)[source]

Create an exists-check write segment (synchronous).

Return type:

SyncWriteSegmentBuilder