GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - amazon-ion/ion-hash-python: A Python implementation of Amazon Ion Hash.

BranchesTags
Open more actions menu

Latest commit

 

History

40 Commits
40 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
docs
docs
 
 
ion-hash-test @ 54c98b5
ion-hash-test @ 54c98b5
 
 
ionhash
ionhash
 
 
tests
tests
 
 
tools
tools
 
 
.gitignore
.gitignore
 
 
.gitmodules
.gitmodules
 
 
CHANGES.md
CHANGES.md
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
NOTICE
NOTICE
 
 
README.md
README.md
 
 
pytest.ini
pytest.ini
 
 
requirements.txt
requirements.txt
 
 
setup.cfg
setup.cfg
 
 
setup.py
setup.py
 
 
tox.ini
tox.ini
 
 

Repository files navigation

Amazon Ion Hash Python

An implementation of Amazon Ion Hash in Python.

Build Status Documentation Status

This package is designed to work with Python 3.4+.

Getting Started

Computing the Ion hash of a simpleion value may be done by calling the ion_hash() method. For example:

>>> import amazon.ion.simpleion as ion
>>> import ionhash
>>> obj = ion.loads('[1, 2, 3]')
>>> digest = obj.ion_hash('md5')
>>> print('digest:', ''.join(' %02x' % x for x in digest))
digest:  8f 3b f4 b1 93 5c f4 69 c9 c1 0c 31 52 4b 26 25

Alternatively, lower-level hash_reader/hash_writer APIs may be used to compute an Ion hash:

from io import BytesIO

from amazon.ion.core import IonEventType
from amazon.ion.reader import blocking_reader
from amazon.ion.reader import NEXT_EVENT
from amazon.ion.reader_managed import managed_reader
from amazon.ion.reader_text import text_reader

from ionhash.hasher import hash_reader
from ionhash.hasher import hashlib_hash_function_provider
from ionhash.hasher import HashEvent


ion = b'[1, 2, 3]'
hash_function = "md5"

reader = hash_reader(
    blocking_reader(managed_reader(text_reader(), None), BytesIO(ion)),
    hashlib_hash_function_provider(hash_function))

while True:
    event = reader.send(NEXT_EVENT)
    if event.event_type == IonEventType.STREAM_END:
        break

digest = reader.send(HashEvent.DIGEST)
print('digest:', ''.join(' %02x' % x for x in digest))

When run, it produces the following output:

digest:  8f 3b f4 b1 93 5c f4 69 c9 c1 0c 31 52 4b 26 25

Development

This repository contains a git submodule called ion-hash-test which holds data used by ion-hash-python's unit tests.

The easiest way to clone the ion-hash-python repository and initialize its ion-hash-test submodule is to run the following command:

$ git clone --recursive https://github.com/amzn/ion-hash-python.git ion-hash-python

Alternatively, the submodule may be initialized independently from the clone by running the following commands:

$ git submodule init $ git submodule update

Once the repository has been fully initialized, cd into it:

$ cd ion-hash-python

Then use venv to create a clean environment to build/test ion-hash-python as follows:

$ python3 -m venv venv
$ . venv/bin/activate
$ pip install -r requirements.txt
$ pip install -e .

You should then be able to run the test suite by executing python setup.py test, or simply running py.test.

Tox Setup

In order to verify that ion-hash-python works on all supported platforms, we use a combination of tox with pyenv.

Install relevant versions of Python:

$ for V in 3.4.10 3.5.7 3.6.8 3.7.3 pypy3.6-7.1.0; do pyenv install $V; done

Once you have these installations, add each as a local pyenv configuration:

$ pyenv local 3.4.10 3.5.7 3.6.8 3.7.3 pypy3.6-7.1.0

Assuming you have pyenv properly set up (making sure pyenv init is evaluated into your shell), you can now run tox:

# Run tox for all versions of Python (this executes `py.test` for each supported platform):
$ tox

# Run tox for just Python 3.4 and 3.5:
$ tox -e py34,py35

# Run tox for a specific version and run py.test with high verbosity:
$ tox -e py34 -- py.test -vv

# Run tox for a specific version and start the virtual env's Python REPL:
$ tox -e py35 -- python

License

This library is licensed under the Apache 2.0 License.

About

A Python implementation of Amazon Ion Hash.

amazon-ion.github.io/ion-hash/

Resources

Readme
Apache-2.0 license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

10 stars

Watchers

10 watching

Forks

5 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.