Python Client SDK
Installing Python client SDK
pip install oxiaPyDoc documentation is available at https://oxia-db.github.io/oxia-client-python/latest
Client API
Initializing the client
To use the Oxia client, you need to create a client instance. Once created, a client instance will be valid until it’s explicitly closed, and it can be used from different threads.
import oxia
client = oxia.Client("localhost:6648")When creating the client is possible to pass several options, such as:
client = oxia.Client("localhost:6648",
namespace="my-namespace",
client_identifier="my-client-identity",
)For the full list of options, see the Client constructor docs .
Writing records
# Write a record to Oxia with the specified key and value, and with the expectation
# that the record does not already exist.
key, version1 = client.put("my-key", "value-1",
expected_version_id=oxia.EXPECTED_RECORD_DOES_NOT_EXIST)
# Write a record with the expectation that it has not changed since the previous write.
# If there was any change, the operation will fail
key, version2 = client.put("my-key", "value-2",
expected_version_id=version1.version_id())All the options for the put operation are available in the put() method docs .
Reading records
Reading the value of a record
key, value, version = client.get("my-key")All the options for the get operation are available in the get() method docs .
Deleting records
Delete a single record by key. Supports conditional deletes using version-based expectations.
# Unconditional delete
client.delete("my-key")
# Conditional delete: only succeed if the version matches
client.delete("my-key", expected_version_id=version.version_id())All the options for the delete operation are available in the delete() method docs .
Deleting a range of records
Delete all records whose keys fall within a specified range.
# Delete all keys in the range [min_key_inclusive, max_key_exclusive)
client.delete_range("/users/", "/users//")Listing keys
List the keys within a specified range, without fetching the associated values.
keys = client.list("/users/", "/users//")
for key in keys:
print(key)Scanning records
Scan records in a key range, returning both keys and values.
for result in client.range_scan("/users/", "/users//"):
print(f"key: {result.key}, value: {result.value}, version: {result.version}")For the complete list of options available on all operations, see the PyDoc reference .