No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Trillian Demo: Python API client library

This library helps you interact with a Trillian log. It provides a TrillianLog class with methods like .append().


You'll need to clone this repository and install it manually in your Python app. For example:

. venv/bin/activate
pip install -e ~/trillian-demo-python-api-client/


Example use

>>> log = TrillianLog.load_from_environment()
>>> log.append({'foo': 'bar'})
>>> log.latest()
LogEntry(idx=14, data=b'{\n"foo": "bar"\n}')

>>> log.latest().json()
{'foo': 'bar'}


Helper: reads TRILLIAN_LOG_URL and TRILLIAN_LOG_PUBLIC_KEY from the environment and instantiates a TrillianLog class.

TrillianLog(log_url, public_key)

Instantiate a TrillianLog class with the log_url of a log, for example:

  • log_url:
  • public_key: ECDSA:SHA256:MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAER4Z5Ac9QEtvFqz7c808DJP1IzqxN88r8aUNsC2pluKHkw5EK+vQ1DKaSG20zufLlIeDvWNEYZ6INgqm7Fz35Nw==


Gets the signed log root, validates the signature against the public key

>>> log.get_log_root()
LogRoot(tree_size=5, root_hash='F/ZKT9N6eoDQi0+paj3eToI/U9xu1ZriSMy/vhjkm30=', timestamp_nanos=1531403868624765390)


Insert a Python dictionary into the Trillian log.

>>> log.append({'foo': 'bar'})


Find the latest leaf (log entry) in the Trillian log and return it as a LogEntry object.

>>> log.latest()
LogEntry(idx=14, data=b'{\n"foo": "bar"\n}')


Download and hash all the data in the log, recreating a Merkle tree and comparing its root hash against the given log_root.

>>> log.full_audit(log.get_log_root())

.get_leaves_by_range(start_index, count)

Download the given leaves from the log as LogEntry objects.

>>> log.get_leaves_by_range(0, 2)
[LogEntry(idx=0 data=b'{\n"datetime": "2018-07-12T00:00:00Z",\n"Eastbridge Road - Pedestrians": "23",\n"Eastbridge Road - Bicycles": "15",\n"Eastbridge Road - Cars": "45"\n}'),
 LogEntry(idx=1 data=b'{\n"datetime": "2018-07-12T01:00:00Z",\n"Eastbridge Road - Pedestrians": "34",\n"Eastbridge Road - Bicycles": "4",\n"Eastbridge Road - Cars": "34"\n}')]