Skip to content

xsawyerx/melian-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Melian Python Client

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.

Installation

cd clients/python
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

The library itself has no third-party dependencies; the requirements file only includes tooling for running the test suite (pytest).

Usage

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 DESCRIBE action 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 bytes unless decode_utf8=True, in which case it returns str.

Set decode_utf8=True and decode_errors to control UTF-8 decoding for BYTES.

Tests

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

About

Python client for the Melian cache server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages