class Client: (source)
Constructor: Client(service_address, namespace, session_timeout_ms, client_identifier, request_timeout_ms)
Synchronous client for the Oxia service.
Can be used as a context manager:
with oxia.Client('localhost:6648') as client:
client.put('/key', b'value')
| Method | __enter__ |
Undocumented |
| Method | __exit__ |
Undocumented |
| Method | __init__ |
Create a new Oxia client. |
| Method | close |
Close the client and release all underlying connections. |
| Method | delete |
Delete a key and its value. |
| Method | delete |
Delete all records whose keys fall within ``[min, max)``. |
| Method | get |
Retrieve the record for a key. |
| Method | get |
Subscribe to change notifications for the entire database. |
| Method | get |
Subscribe to updates on a sequential key. |
| Method | list |
List keys in the range ``[min, max)``. |
| Method | put |
Associate a value with a key. |
| Method | range |
Scan records in the range ``[min, max)``. |
| Instance Variable | _client |
Undocumented |
str, namespace: str = 'default', session_timeout_ms: int = 30000, client_identifier: str = None, request_timeout_ms: int = 30000):
(source)
¶
Create a new Oxia client.
Connects to the service, discovers the shards of the namespace and starts the thread the client runs on. The client is thread-safe: operations submitted from several threads run concurrently and are batched together.
| Parameters | |
servicestr | Oxia service address (``host:port``). |
namespace:str | Oxia namespace. Default is ``"default"``. |
sessionint | Session timeout in milliseconds for ephemeral records. Default is 30 000 ms. |
clientstr | Optional client identity string. If ``None``, a random UUID is generated. |
requestint | Deadline for each finite operation (``put``, ``delete``, ``get``, ``list``, ``range_scan``, session management), including the retries the client makes internally. Long-lived subscriptions (notifications, sequence updates, shard assignments) are not bounded. Default is 30 000 ms. A timeout is raised as oxia.ex.OxiaException. |
str, partition_key: str = None, expected_version_id: int = None) -> bool:
(source)
¶
Delete a key and its value.
| Parameters | |
key:str | The key to delete. |
partitionstr | Override shard routing. |
expectedint | If set, the delete is conditional. |
| Returns | |
bool | ``True`` if the record existed and was deleted, ``False`` if the key was not found. |
| Raises | |
oxia.ex.UnexpectedVersionId | if the version check fails. |
str, max_key_exclusive: str, partition_key: str = None):
(source)
¶
Delete all records whose keys fall within ``[min, max)``.
Keys are compared using Oxia's hierarchical sort order. See: https://oxia-db.github.io/docs/features/oxia-key-sorting
| Parameters | |
minstr | Start of the range (inclusive). |
maxstr | End of the range (exclusive). |
partitionstr | If set, only the shard owning this partition key is affected. |
str, partition_key: str = None, comparison_type: ComparisonType = ComparisonType.EQUAL, include_value: bool = True, use_index: str = None) -> tuple[ str, bytes, Version]:
(source)
¶
Retrieve the record for a key.
| Parameters | |
key:str | The key (or secondary-index key when *use_index* is set) to look up. |
partitionstr | Override shard routing. |
comparisonComparisonType | Key comparison mode. Default is ComparisonType.EQUAL. Non-equal modes query across all shards when *partition_key* is not set. |
includebool | If ``False``, the returned value is ``None`` (useful for metadata-only reads). |
usestr | Name of a secondary index to query. |
| Returns | |
tuple[ | ``(key, value, version)`` where *key* is the primary key of the matched record and *value* is ``bytes`` (or ``None`` if *include_value* is ``False``). |
| Raises | |
oxia.ex.KeyNotFound | if no matching record exists. |
Subscribe to change notifications for the entire database.
Returns an iterator that yields Notification objects for every create, modify, delete, or range-delete event. Multiple subscriptions can be active simultaneously. Call ``.close()`` on the returned object when done.
| Returns | |
Iterator[ | An iterator of Notification objects. |
str, partition_key: str = None) -> SequenceUpdates:
(source)
¶
Subscribe to updates on a sequential key.
Returns an iterator that yields the latest key each time the sequence advances. Call ``.close()`` on the returned object when done.
| Parameters | |
prefixstr | The key prefix for the sequence. |
partitionstr | Required. The partition key for shard routing. |
| Returns | |
SequenceUpdates | A SequenceUpdates iterator. |
| Raises | |
oxia.ex.InvalidOptions | if *partition_key* is not set. |
str, max_key_exclusive: str, partition_key: str = None, use_index: str = None) -> list[ str]:
(source)
¶
List keys in the range ``[min, max)``.
Keys are returned in Oxia's hierarchical sort order. See: https://oxia-db.github.io/docs/features/oxia-key-sorting
| Parameters | |
minstr | Start of the range (inclusive). |
maxstr | End of the range (exclusive). |
partitionstr | If set, only query the shard owning this partition key. |
usestr | Name of a secondary index to query. |
| Returns | |
list[ | Sorted list of keys in the range, or ``[]`` if none. |
str, value: str | bytes, partition_key: str = None, expected_version_id: int = None, ephemeral: bool = False, sequence_keys_deltas: list[ int] = None, secondary_indexes: dict[ str, str] = None) -> tuple[ str, Version]:
(source)
¶
Associate a value with a key.
| Parameters | |
key:str | The key to write. |
value:str | bytes | The value (``str`` is encoded to UTF-8). |
partitionstr | Override shard routing with this key instead of the record key. Records sharing a partition key are co-located on the same shard. |
expectedint | If set, the put is conditional: it succeeds only if the current version matches. Pass EXPECTED_RECORD_DOES_NOT_EXIST to assert the key is new. |
ephemeral:bool | If ``True``, the record is tied to the client session and automatically deleted when the session ends. |
sequencelist[ | Server-assigned sequential key suffixes. Requires ``partition_key``. |
secondarydict[ | Additional index entries (``{index_name: secondary_key}``). |
| Returns | |
tuple[ | ``(actual_key, version)`` |
| Raises | |
oxia.ex.InvalidOptions | if options are incompatible. |
oxia.ex.UnexpectedVersionId | if the version check fails. |
oxia.ex.SessionNotFound | if the session for an ephemeral put no longer exists on the server. |
str, max_key_exclusive: str, partition_key: str = None, use_index: str = None) -> Iterator[ tuple[ str, bytes, Version]]:
(source)
¶
Scan records in the range ``[min, max)``.
Returns both keys and values, unlike list which returns keys only.
Keys are returned in Oxia's hierarchical sort order. See: https://oxia-db.github.io/docs/features/oxia-key-sorting
| Parameters | |
minstr | Start of the range (inclusive). |
maxstr | End of the range (exclusive). |
partitionstr | If set, only scan the shard owning this partition key. |
usestr | Name of a secondary index to query. |
| Returns | |
Iterator[ | An iterator of ``(key, value, version)`` tuples. |