DataSet

class aerospike_sdk.dataset.DataSet[source]

Bases: object

Pair a namespace and set name for building Key values.

Use of() as the factory, then id() for one key or ids() for many. Pass keys to query(), upsert(), and other session APIs.

Example:

users = DataSet.of("test", "users")
k = users.id("user-123")
ks = users.ids("a", "b", "c")

# No set: covers the whole namespace, for queries and namespace-wide indexes.
everything = DataSet.of("test")

See also

Session: Operations on keys.

__init__(namespace, set_name=None)[source]

Create a DataSet instance.

Parameters:
  • namespace (str) – The Aerospike namespace

  • set_name (Optional[str]) – The set name within the namespace. None or "" means no set: the dataset then covers the whole namespace.

Raises:

ValueError – If namespace is empty

static of(namespace, set_name=None)[source]

Construct a dataset handle for namespace and set_name.

Omit the set, or pass None or "", to cover the whole namespace. A query on such a dataset reaches every set and the null set, and can be served by a namespace-wide secondary index — one created without a set.

The set-less form means different things to different verbs, because the server does: to a query it means every set; to id() and ids() it means the null set, the one records carry when they were written without a set name.

Parameters:
  • namespace (str) – Non-empty Aerospike namespace name.

  • set_name (Optional[str]) – Set name within that namespace, or None / "" for no set.

Return type:

DataSet

Returns:

A DataSet sharing the same equality/hash for the pair. None and "" produce equal datasets.

Raises:

ValueError – If namespace is empty.

Example:

orders = DataSet.of("prod", "orders")

# Every set in the namespace, through a namespace-wide index.
everything = DataSet.of("prod")
stream = await session.query(everything).where("$.created >= %s", cutoff).execute()

See also

id(): Build a single user key. ids(): Build several keys at once.

property namespace: str

Get the namespace of this dataset.

property set_name: str

Get the set name of this dataset, or "" when it has no set.

id(identifier)[source]

Build one Key for this namespace and set.

Parameters:

identifier (Union[str, int, bytes]) – User key value (string, integer, or bytes).

Return type:

Key

Returns:

A Key bound to this dataset’s namespace/set.

Example:

users = DataSet.of("test", "users")
key_str = users.id("user123")
key_int = users.id(12345)
key_bin = users.id(b"pk")

See also

ids(): Multiple keys in one call.

id_from_digest(digest)[source]

Create an Aerospike key from a digest.

Parameters:

digest (Union[str, bytes]) – The digest as a hex string or bytes

Return type:

Key

Returns:

A new Key instance created from the digest

Example:

users = DataSet.of("test", "users")
# From hex string
key = users.id_from_digest("a1b2c3d4...")
# From bytes
key = users.id_from_digest(b"\xa1\xb2\xc3...")
id_for_object(obj)[source]

Create an Aerospike key from an object identifier. Supports String, Integer, Long, and byte array types.

Parameters:

obj (object) – The object to use as the key identifier

Return type:

Key

Returns:

A new Key instance

Raises:

TypeError – If the object type is not supported

Example:

users = DataSet.of("test", "users")
key1 = users.id_for_object("user123")     # String key
key2 = users.id_for_object(123)           # Integer key
key3 = users.id_for_object(12345)         # Integer key
key4 = users.id_for_object(b"bytes")      # Bytes key
ids(*identifiers)[source]

Build many keys sharing this dataset’s namespace and set.

Overloads:
  • self, identifiers (str) → List[Key]

  • self, identifiers (int) → List[Key]

  • self, identifiers (bytes) → List[Key]

  • self, identifiers (List[Union[str, int, bytes]]) → List[Key]

Call either with several positional identifiers (ids("a", "b", "c")) or with a single list (ids(["a", "b", "c"])). Mixed-type lists use id_for_object() per element when the single-list form is used.

Parameters:

*identifiers (Union[str, int, bytes]) – One or more identifiers, or exactly one list of identifiers.

Returns:

A list of Key instances in input order.

Raises:

TypeError – If list elements are not supported key types.

Example:

users = DataSet.of("test", "users")
keys1 = users.ids("u1", "u2", "u3")
keys2 = users.ids(["u1", "u2"])
keys3 = users.ids(1, 2, 3)

See also

id(): Single-key helper.

ids_from_digests(*digests)[source]

Create multiple Aerospike keys from digests.

Parameters:

*digests (Union[str, bytes]) – Variable number of digests (hex strings or bytes)

Return type:

List[Key]

Returns:

A list of Key instances created from the digests

Example:

users = DataSet.of("test", "users")
keys = users.ids_from_digests("digest1", "digest2", b"digest3")