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.1.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

trie-0.3.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for trie-0.3.1.tar.gz
Algorithm Hash digest
SHA256 3f483450ab858ff7ef8daee4b02179952eee8e1079cb39c852646e0014ae5680
MD5 126e1c55eb37394a70c3c81c9392b335
BLAKE2b-256 83a613ce289fdec4c6b0f412390b146c6d048ddc71e325f9ee5cd2ed996e0c23

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for trie-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 776235e5dad284fd85ec9d91324aa86fd5610d5500db5c71fd6201bc19c8e409
MD5 2b429643a5a31f93bd57f66f387836a5
BLAKE2b-256 4f0d685804d1fe173efaa17c0414dd34ca10600900dcef680d2902de206a417e

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