Skip to main content

OpenKache Python client

OpenKache is a super-fast open-source SSD cache server. Use this Python client to store, read, and delete values in a few lines.

PyPI package · GitHub source

Install

Python 3.11 or newer is required.

# pip
python -m pip install openkache

# uv
uv add openkache

# Existing uv virtual environment:
uv pip install openkache

# Poetry
poetry add openkache

# PDM
pdm add openkache

# Pipenv
pipenv install openkache

The published wheel currently supports Linux x86_64 (manylinux_2_38).

Quick start

The example below assumes a local OpenKache server at 127.0.0.1:4433.

from openkache import Client

client = Client.connect("127.0.0.1:4433")
print(client.set("greeting", "hello"))  # SetOutcome.CREATED
print(client.get("greeting"))           # Found(value='hello')
print(client.delete("greeting"))        # True
client.close()

set returns SetOutcome.CREATED for a new key, get returns Found(value), and delete returns True when a value was removed.

The example uses the local development TLS profile, which does not verify the server certificate. Use it only with a local development server.

Reference

Client.connect(address)

Opens a connection and returns a Client.

  • Input: a non-empty host:port string. IPv6 endpoints use [host]:port.
  • Returns: Client.
  • Raises: OpenKacheError when the connection cannot be opened.
client = Client.connect("127.0.0.1:4433")

Client and OpenKacheClient refer to the same class.

client.get(key)

Reads one value.

  • Input: a UTF-8 str, signed 64-bit int, or bytes-like value (bytes, bytearray, or memoryview).
  • Returns: Found(value) when the key exists, or Missing when it does not. A stored None or UNDEFINED is still returned as Found.
  • Raises: OpenKacheValueError for an invalid key and OpenKacheError for connection or server failures.
from openkache import Found

result = client.get("greeting")
if isinstance(result, Found):
    print(result.value)

MISSING is a shared Missing instance. GetResult is the Found | Missing type alias.

client.set(key, value)

Stores one value, replacing any existing value for the key.

  • Input: the same key types accepted by get, plus a native or lossless structured value.
  • Returns: SetOutcome.CREATED for a new key or SetOutcome.REPLACED for an existing key.
  • Raises: OpenKacheValueError for an invalid key or value and OpenKacheError for connection or server failures.
outcome = client.set("greeting", "hello")
# outcome is SetOutcome.CREATED or SetOutcome.REPLACED

client.delete(key)

Deletes one key. Deleting a missing key is safe.

  • Input: a key accepted by get.
  • Returns: True when a value was removed, or False when no value existed.
  • Raises: OpenKacheValueError for an invalid key and OpenKacheError for connection or server failures.
removed = client.delete("greeting")
if removed:
    print("deleted")

client.close()

Closes the connection and returns None. Calling it more than once is safe.

client.close()

The client also supports with Client.connect(address), which closes the connection automatically when the block exits.

Keys

Keys are typed. Use:

  • str for UTF-8 text keys;
  • int for signed 64-bit integer keys;
  • bytes, bytearray, or memoryview for exact byte keys.
client.get("text-key")
client.get(42)
client.get(b"bytes-key")

Values

The client converts common Python values to structured values:

  • None becomes Null.
  • bool becomes Boolean.
  • int becomes an exact Integer.
  • float becomes an IEEE-754 binary64 Float.
  • str becomes UTF-8 TextString.
  • bytes, bytearray, and memoryview become Bytes.
  • list and tuple become Array.
  • dict becomes Map.
client.set("profile", {"name": "Ada", "active": True})

Use the lossless model when the exact representation matters: UNDEFINED/UndefinedValue, IntegerValue, FloatValue, ByteStringValue, TextStringValue, ArrayValue, and MapValue. The short names Undefined, Integer, Float, ByteString, TextString, Array, Map, and Value are compatibility aliases.

Value helpers

  • to_value(value, limits=None) converts a native Python value to the lossless model.
  • encode_value(value, limits=None) returns one encoded StructuredValue-CBOR-v1 item as bytes.
  • decode_value(data, limits=None) decodes one complete item from bytes-like input.
  • model_equal(left, right) compares model values without treating True and 1 as equal.
  • ValueLimits bounds encoded bytes, nesting depth, item count, and integer magnitude.
from openkache import decode_value, encode_value, model_equal, to_value

encoded = encode_value({"count": 1})
decoded = decode_value(encoded)
assert model_equal(decoded, to_value({"count": 1}))

StructuredValueError reports conversion, encoding, decoding, and resource limit failures. Its kind property is a ValueErrorKind.

Errors

  • OpenKacheError — connection, protocol, server, or operation failure.
  • OpenKacheValueError — invalid key or value supplied by the caller.
  • OpenKacheUnknownMutationError — a mutation may have reached the server without a confirmed result; do not replay it automatically.
  • OpenKacheIncompatibleServerError — the server returned an outcome that this client does not support.
  • StructuredValueError — invalid structured-value data or resource limits.

More information

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openkache-0.1.2.tar.gz (516.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openkache-0.1.2-py3-none-manylinux_2_38_x86_64.whl (4.1 MB view details)

Uploaded Python 3manylinux: glibc 2.38+ x86-64

File details

Details for the file openkache-0.1.2.tar.gz.

File metadata

  • Download URL: openkache-0.1.2.tar.gz
  • Upload date:
  • Size: 516.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for openkache-0.1.2.tar.gz
Algorithm Hash digest
SHA256 361c4a51564262851c806e3b46eab19e813190ec2ecc5df56f8f57ddcb818808
MD5 c2f031c2cdd6a657e99cf6d54aaf1841
BLAKE2b-256 9f3974a25eb9a119f33cde03108ac83194340beee3e5c85d3e58fd76076dc1b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for openkache-0.1.2.tar.gz:

Publisher: publish-pypi.yml on openkache/openkache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openkache-0.1.2-py3-none-manylinux_2_38_x86_64.whl.

File metadata

File hashes

Hashes for openkache-0.1.2-py3-none-manylinux_2_38_x86_64.whl
Algorithm Hash digest
SHA256 0219e45376f2d5981b52ba6e48fc2e6cec3ed204667ac2cc1b8ec87df410051e
MD5 0c3f562c9e7f255ab518f220306a8f0e
BLAKE2b-256 f0f6751ede7a766a95ed426dcfb4a02e6f9b3975cdd907c5326a7ac705b95958

See more details on using hashes here.

Provenance

The following attestation bundles were made for openkache-0.1.2-py3-none-manylinux_2_38_x86_64.whl:

Publisher: publish-pypi.yml on openkache/openkache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.3

7 files

This release

0.1.2 This release

2 files

0.1.1

2 files

0.1.0

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page