SyncRecordStream

class aerospike_sdk.sync.record_stream.SyncRecordStream[source]

Bases: object

Synchronous iterator of RecordResult.

Produced by sync builder terminals (execute()). Iterate with a regular for loop or use the helpers below (first, collect, failures, …). Single-pass — most underlying sources do not support resetting.

Example:

for row in session.query(key).bins(["name"]).execute():
    if row.is_ok and row.record:
        print(row.record.bins)

See also

aerospike_sdk.record_stream.RecordStream: async counterpart.

__init__(source)[source]
classmethod from_list(results)[source]

Wrap an already-materialized list of results.

Return type:

SyncRecordStream

classmethod from_batch_records(batch_records)[source]

Wrap a list of PAC BatchRecord objects.

Return type:

SyncRecordStream

classmethod from_pac_batch_stream(pac_stream, on_error=None)[source]

Lazy-feed adapter over a PAC BatchRecordStream (sync iter).

See aerospike_sdk.record_stream.RecordStream.from_pac_batch_stream() for the contract. This sync variant pulls (idx, BatchRecord) tuples via PAC’s blocking __iter__/__next__ and maps each to a RecordResult with index=idx (NOT enumeration — completion order can differ from input order).

Parameters:
  • pac_stream (Any) – PAC BatchRecordStream (sync iter) to drain.

  • on_error (Optional[Callable[[Key, int, AerospikeError], None]]) – Optional (key, index, exception) -> None callback. When set, per-key failures are dispatched to the handler and excluded from the returned stream; cluster-level errors still raise from __next__.

Return type:

SyncRecordStream

classmethod from_pac_recordset(recordset)[source]

Wrap a PAC Recordset (sync __iter__ / __next__).

Each yielded Record becomes an OK RecordResult with index=-1 (queries have no positional index).

Return type:

SyncRecordStream

classmethod from_chunked_pac_recordset(recordset, reexecute, limit=0)[source]

Wrap a PAC Recordset for chunked iteration.

reexecute is a sync callable that takes the current PartitionFilter and returns the next Recordset (or None to stop). Use has_more_chunks() to advance.

Return type:

SyncRecordStream

classmethod from_single(key, record)[source]

Wrap a single-key result.

Sets result_code = OK when record is not None; otherwise KEY_NOT_FOUND_ERROR.

Return type:

SyncRecordStream

classmethod from_error(key, result_code, in_doubt=False, exception=None)[source]

Wrap a single-key error as a one-element stream.

Return type:

SyncRecordStream

classmethod chain(streams)[source]

Yield all results from each stream in order.

Return type:

SyncRecordStream

first()[source]

Consume and return the first row, or None if empty.

Return type:

Optional[RecordResult]

first_or_raise()[source]

Return the first row, or raise if the stream is empty / not OK.

Return type:

RecordResult

first_udf_result()[source]

Scan forward for the first non-None udf_result.

Return type:

Any | None

collect()[source]

Drain the stream into a list.

Return type:

list[RecordResult]

failures()[source]

Drain the stream, returning only rows whose is_ok is false.

Return type:

list[RecordResult]

close()[source]

Mark the stream closed; further iteration raises StopIteration.

Return type:

None

has_more_chunks()[source]

Return whether more server-side chunks remain.

First call always returns True so the caller enters the loop for the already-loaded first chunk. Subsequent calls inspect the cursor; new chunks are fetched transparently via reexecute.

Return type:

bool