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”)

See also

Session: Operations on keys.

__init__(namespace, set_name)[source]

Create a DataSet instance.

Parameters:
  • namespace (str) – The Aerospike namespace

  • set_name (str) – The set name within the namespace

Raises:

ValueError – If namespace or set_name is empty

static of(namespace, set_name)[source]

Construct a dataset handle for namespace and set_name.

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

  • set_name (str) – Non-empty set name within that namespace.

Return type:

DataSet

Returns:

A DataSet sharing the same equality/hash for the pair.

Raises:

ValueError – If either string is empty.

Example

orders = DataSet.of(“prod”, “orders”)

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.

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]
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]

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

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")