Skip to main content

Python implementation of the Ethereum Trie structure

Project description

$ pip install trie

Warning: This is an early release and is likely to contain bugs as well as breaking API changes.

This library and repository was previously located at https://github.com/pipermerriam/py-trie. It was transferred to the Ethereum foundation github in November 2017 and renamed to py-trie.

Installation

pip install trie

Development

pip install -e . -r requirements-dev.txt

Running the tests

You can run the tests with:

py.test tests

Or you can install tox to run the full test suite.

Releasing

Pandoc is required for transforming the markdown README to the proper format to render correctly on pypi.

For Debian-like systems:

apt install pandoc

Or on OSX:

brew install pandoc

To release a new version:

bumpversion $$VERSION_PART_TO_BUMP$$
git push && git push --tags
make release

How to bumpversion

The version format for this repo is {major}.{minor}.{patch} for stable, and {major}.{minor}.{patch}-{stage}.{devnum} for unstable (stage can be alpha or beta).

To issue the next version in line, use bumpversion and specify which part to bump, like bumpversion minor or bumpversion devnum.

If you are in a beta version, bumpversion stage will switch to a stable.

To issue an unstable version when the current version is stable, specify the new version explicitly, like bumpversion --new-version 4.0.0-alpha.1 devnum

Usage

>>> from trie import Trie
>>> t = Trie(db={})
>>> t.root_hash
b'V\xe8\x1f\x17\x1b\xccU\xa6\xff\x83E\xe6\x92\xc0\xf8n[H\xe0\x1b\x99l\xad\xc0\x01b/\xb5\xe3c\xb4!'
>>> t.set(b'my-key', b'some-value')
>>> t.get(b'my-key')
b'some-value'
>>> t.exists(b'another-key')
False
>>> t.set(b'another-key', b'another-value')
>>> t.exists(b'another-key')
True
>>> t.delete(b'another-key')
>>> t.exists(b'another-key')
False

You can also use it like a dictionary.

>>> from trie import Trie
>>> t = Trie(db={})
>>> t.root_hash
b'V\xe8\x1f\x17\x1b\xccU\xa6\xff\x83E\xe6\x92\xc0\xf8n[H\xe0\x1b\x99l\xad\xc0\x01b/\xb5\xe3c\xb4!'
>>> t[b'my-key'] = b'some-value'
>>> t[b'my-key']
b'some-value'
>>> b'another-key' in t
False
>>> t[b'another-key']  = b'another-value'
>>> b'another-key' in t
True
>>> del t[b'another-key']
>>> b'another-key' in t
False

Project details


Download files

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

Source Distribution

trie-0.3.2.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

trie-0.3.2-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file trie-0.3.2.tar.gz.

File metadata

  • Download URL: trie-0.3.2.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for trie-0.3.2.tar.gz
Algorithm Hash digest
SHA256 eb3feb50a896edb1e07c81a7707aa17a573daebffb61fc4083972172b8ba2df5
MD5 54c80f57afc48c7fba68176c372b6e64
BLAKE2b-256 996cf30391a03fc87f55bb010a381a4beed350731a85cda9483c3482499bb7f0

See more details on using hashes here.

File details

Details for the file trie-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for trie-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b0410dcae793609413e6ea853a03bcc27db30494de1cc04238aa3e8329ef8407
MD5 5c6d6fd3e58093ac5044be00e8572708
BLAKE2b-256 ec071c0c9b4c4be58aa2b1b5d573008d503056f1982fc2cb12af9c0153b831a4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page