SyncClient

class aerospike_sdk.sync.client.SyncClient[source]

Bases: object

Connect to Aerospike and run the SDK API without async/await.

Method shapes match Client; return types are synchronous counterparts (for example SyncQueryBuilder, SyncSession).

Example:

with SyncClient("localhost:3000") as client:
    for row in client.query(
        namespace="test",
        set_name="users"
    ).execute():
        if row.record:
            print(row.record.bins)
Raises:

RuntimeError – If constructed or used while an asyncio event loop is already running in the thread (use Client instead).

See also

Client: Native async client. create_session(): Session-scoped Behavior.

__init__(seeds, policy=None)[source]

Initialize a SyncClient.

Parameters:
  • seeds (str) – Aerospike cluster seed addresses (e.g., “localhost:3000”)

  • policy (Optional[ClientPolicy]) – Optional client policy. If None, a default policy is used.

connect()[source]

Connect to the Aerospike cluster synchronously.

Return type:

None

close()[source]

Close the connection to the Aerospike cluster.

Return type:

None

property is_connected: bool

Check if the client is connected.

query(arg1=None, arg2=None, *keys, namespace=None, set_name=None, dataset=None, key=None, keys_list=None, behavior=None)[source]
Overloads:
  • self, dataset (DataSet), behavior (Optional[Behavior])

  • self, key (Key), behavior (Optional[Behavior])

  • self, keys (List[Key]), behavior (Optional[Behavior])

  • self, keys (Key), behavior (Optional[Behavior])

  • self, namespace (str), set_name (str), behavior (Optional[Behavior])

Create a query builder (synchronous).

Supports the same calling styles as Client.query, including multi-key varargs. Returns a wrapper that executes queries synchronously.

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

  • arg2 (Optional[str]) – 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).

  • 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 Behavior for this builder (same semantics as Client.query).

Returns:

Configured for the requested namespace, set,

and/or keys.

Return type:

SyncQueryBuilder

index(namespace=None, set_name=None, *, dataset=None, behavior=None)[source]
Overloads:
  • self, dataset (DataSet), behavior (Optional[Behavior])

  • self, namespace (str), set_name (str), behavior (Optional[Behavior])

Create a secondary-index builder (synchronous).

Same arguments as index(). create() / drop() run on the client’s event loop.

Returns:

Configured for the requested namespace and set.

Return type:

SyncIndexBuilder

See also

IndexBuilder: Async implementation.

truncate(dataset, before_nanos=None)[source]

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

This method deletes all records in the specified set. This operation cannot be undone.

Parameters:
  • dataset (DataSet) – The DataSet to truncate.

  • before_nanos (Optional[int]) – Optional timestamp in nanoseconds. Only records with last update time (LUT) less than this value will be truncated. If None, all records in the set are truncated.

Return type:

None

Example:

users = DataSet.of("test", "users")
client.truncate(users)

# Truncate only records older than a specific time
import time
cutoff_time = time.time_ns() - (24 * 60 * 60 * 10**9)  # 24 hours ago
client.truncate(users, before_nanos=cutoff_time)
register_udf(body, server_path, language=UDFLang.LUA, *, policy=None)[source]

Register a UDF module from bytes (synchronous).

Return type:

RegisterTask

register_udf_from_file(client_path, server_path, language=UDFLang.LUA, *, policy=None)[source]

Register a UDF module from a local file (synchronous).

Return type:

RegisterTask

remove_udf(server_path, *, policy=None)[source]

Remove a UDF module from the cluster (synchronous).

Return type:

UdfRemoveTask

create_session(behavior=None)[source]

Create a session with the specified behavior (synchronous).

A session represents a logical connection to the cluster with specific behavior settings that control how operations are performed (timeouts, retry policies, consistency levels, etc.).

Parameters:

behavior (Optional[Behavior]) – The behavior configuration for the session. If None, uses Behavior.DEFAULT.

Return type:

SyncSession

Returns:

A SyncSession sharing this client’s event-loop manager and applying behavior to operations.

Example:

session = client.create_session()
from datetime import timedelta
fast = Behavior.DEFAULT.derive_with_changes(
    name="fast",
    total_timeout=timedelta(seconds=5),
)
session = client.create_session(fast)

See also

create_session():

Async equivalent.

create_transactional_session(behavior=None)[source]

Create a synchronous multi-record transaction (MRT) session.

Allocates a fresh Txn on entry. Operations chained off the returned session (tx.upsert(...), tx.query(...), tx.batch(), …) auto-participate in the transaction — every builder stamps policy.txn = tx.txn under the hood. On clean exit the transaction is committed; if an exception propagates out of the with block it is aborted.

Multi-record transactions require an Aerospike server running in strong-consistency (SC) mode on the target namespace.

Parameters:

behavior (Optional[Behavior]) – Optional Behavior for operations inside the transaction. Defaults to Behavior.DEFAULT when omitted.

Return type:

SyncTransactionalSession

Returns:

A SyncTransactionalSession bound to this client and behavior.

Example:

with client.create_transactional_session() as tx:
    tx.upsert(accounts.id("A")).bin("balance").set_to(100).execute()
    tx.upsert(accounts.id("B")).bin("balance").set_to(200).execute()

See also

transaction_session():

Async equivalent.