Thin Python wrapper for the Melian cache server protocol. It exposes a simple API for fetching rows by table/index identifiers and decoding binary row payloads.
cd clients/python
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtThe library itself has no third-party dependencies; the requirements file only includes tooling for running the test suite (pytest).
from melian import MelianClient
client = MelianClient(dsn="unix:///tmp/melian.sock")
# Slightly slower, but more friendly:
row = client.fetch_by_string_from(table_name, index_name, b"host-00042")
row = client.fetch_by_int_from(table_name, index_name, record_id)
# Slightly faster, resolve identifiers from table/index names
table_id, index_id = client.resolve_index("table2", "hostname")
row = client.fetch_by_string(table_id, index_id, b"host-00042")
row = client.fetch_by_int(table_id, index_id, record_id=42)
print(row["id"])
# If you need field types, use the *_with_fields variants:
typed = client.fetch_by_string_with_fields(table_id, index_id, b"host-00042")
print(typed["id"]["type"], typed["id"]["value"])
client.close()Schema loading options (pass via __init__):
schema: pre-parsed schema dict.schema_spec: inline spec string (e.g.table1#0|60|id#0:int).schema_file: JSON file on disk.- default: issue a
DESCRIBEaction to the running server so it fetches it itself.
Binary payload decoding returns native values by default. If you use the
*_with_fields methods, you get a dict of fields in the form
{"field": {"type": TYPE_ID, "value": value}} with these mappings:
- NULL:
None - INT64: Python
int - FLOAT64: Python
float - DECIMAL: ASCII
str - BOOL: Python
bool - BYTES: raw
bytesunlessdecode_utf8=True, in which case it returnsstr.
Set decode_utf8=True and decode_errors to control UTF-8 decoding for BYTES.
The tests assume a Melian server is available (default unix:///tmp/melian.sock).
Override via MELIAN_TEST_DSN when needed.
cd clients/python
source .venv/bin/activate
pytest