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.
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:portstring. IPv6 endpoints use[host]:port. - Returns:
Client. - Raises:
OpenKacheErrorwhen 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-bitint, or bytes-like value (bytes,bytearray, ormemoryview). - Returns:
Found(value)when the key exists, orMissingwhen it does not. A storedNoneorUNDEFINEDis still returned asFound. - Raises:
OpenKacheValueErrorfor an invalid key andOpenKacheErrorfor 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.CREATEDfor a new key orSetOutcome.REPLACEDfor an existing key. - Raises:
OpenKacheValueErrorfor an invalid key or value andOpenKacheErrorfor 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:
Truewhen a value was removed, orFalsewhen no value existed. - Raises:
OpenKacheValueErrorfor an invalid key andOpenKacheErrorfor 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:
strfor UTF-8 text keys;intfor signed 64-bit integer keys;bytes,bytearray, ormemoryviewfor 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:
Nonebecomes Null.boolbecomes Boolean.intbecomes an exact Integer.floatbecomes an IEEE-754 binary64 Float.strbecomes UTF-8 TextString.bytes,bytearray, andmemoryviewbecome Bytes.listandtuplebecome Array.dictbecomes 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 encodedStructuredValue-CBOR-v1item asbytes.decode_value(data, limits=None)decodes one complete item frombytes-like input.model_equal(left, right)compares model values without treatingTrueand1as equal.ValueLimitsbounds 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
361c4a51564262851c806e3b46eab19e813190ec2ecc5df56f8f57ddcb818808
|
|
| MD5 |
c2f031c2cdd6a657e99cf6d54aaf1841
|
|
| BLAKE2b-256 |
9f3974a25eb9a119f33cde03108ac83194340beee3e5c85d3e58fd76076dc1b3
|
Provenance
The following attestation bundles were made for openkache-0.1.2.tar.gz:
Publisher:
publish-pypi.yml on openkache/openkache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openkache-0.1.2.tar.gz -
Subject digest:
361c4a51564262851c806e3b46eab19e813190ec2ecc5df56f8f57ddcb818808 - Sigstore transparency entry: 2583440184
- Sigstore integration time:
-
Permalink:
openkache/openkache@1920db297541835a2ab8c9914dd37687c871f846 -
Branch / Tag:
refs/tags/python-v0.1.2 - Owner: https://github.com/openkache
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@1920db297541835a2ab8c9914dd37687c871f846 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file openkache-0.1.2-py3-none-manylinux_2_38_x86_64.whl.
File metadata
- Download URL: openkache-0.1.2-py3-none-manylinux_2_38_x86_64.whl
- Upload date:
- Size: 4.1 MB
- Tags: Python 3, manylinux: glibc 2.38+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0219e45376f2d5981b52ba6e48fc2e6cec3ed204667ac2cc1b8ec87df410051e
|
|
| MD5 |
0c3f562c9e7f255ab518f220306a8f0e
|
|
| BLAKE2b-256 |
f0f6751ede7a766a95ed426dcfb4a02e6f9b3975cdd907c5326a7ac705b95958
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openkache-0.1.2-py3-none-manylinux_2_38_x86_64.whl -
Subject digest:
0219e45376f2d5981b52ba6e48fc2e6cec3ed204667ac2cc1b8ec87df410051e - Sigstore transparency entry: 2583440208
- Sigstore integration time:
-
Permalink:
openkache/openkache@1920db297541835a2ab8c9914dd37687c871f846 -
Branch / Tag:
refs/tags/python-v0.1.2 - Owner: https://github.com/openkache
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@1920db297541835a2ab8c9914dd37687c871f846 -
Trigger Event:
workflow_dispatch
-
Statement type: