ContentHash for Python
======================
[![version][icon-version]][link-pypi]
[![downloads][icon-downloads]][link-pypi]
[![license][icon-license]][link-license]
[![python][icon-python]][link-python]
[![linux build][icon-travis]][link-travis]
[![windows build][icon-appveyor]][link-appveyor]
[![coverage][icon-coverage]][link-coverage]
[![quality][icon-quality]][link-quality]
Python implementation of EIP 1577 content hash.
## Description
This is a simple package made for encoding and decoding content hashes has specified in the [EIP 1577][link-eip-1577].
This package will be useful for every [Ethereum][link-ethereum] developer wanting to interact with [EIP 1577][link-eip-1577] compliant [ENS resolvers][link-resolvers].
For JavaScript implementation, see [`pldespaigne/content-hash`][link-javascript-implementation].
## Installation
### Requirements
ContentHash requires Python 3.5 or higher.
### From PyPI
The recommended way to install ContentHash is from PyPI with PIP.
```bash
pip install content-hash
```
### From Source
Alternatively, you can also install it from the source.
```bash
git clone https://github.com/filips123/ContentHashPy.git
cd ContentHashPy
python setup.py install
```
## Usage
### Supported Codecs
The following codecs are currently supported:
- `swarm-ns`
- `ipfs-ns`
- `ipns-ns`
Every other codec supported by [`multicodec`][link-multicodec] will be encoded by default in `utf-8`. You can see the full list of the supported codecs [here][link-supported-codecs].
### Getting Codec
You can use a `get_codec` function to get codec from the content hash.
It takes a content hash as a HEX string and returns the codec name. A content hash can be prefixed with a `0x`, but it's not mandatory.
```py
import content_hash
chash = 'bc037a716b746c776934666563766f367269'
codec = content_hash.get_codec(chash)
print(codec) # onion
```
### Decoding
You can use a `decode` function to decode a content hash.
It takes a content hash as a HEX string and returns the decoded content as a string. A content hash can be prefixed with a `0x`, but it's not mandatory.
```py
import content_hash
chash = 'e3010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f'
value = content_hash.decode(chash)
print(value) # QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4
```
### Encoding
You can use an `encode` function to encode a content hash.
It takes a supported codec as a string and a value as a string and returns the corresponding content hash as a HEX string. The output will not be prefixed with a `0x`.
```py
import content_hash
codec = 'swarm-ns'
value = 'd1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162'
chash = content_hash.encode(codec, value)
print(chash) # e40101701b20d1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162
```
## Creating Codecs
All supported codec profiles are available in [`content_hash/profiles/__init__.py`][link-profiles-file], in `PROFILES` dictionary. You need to add a new profile there. You only need to add a new profile if your codec encoding and decoding are different from `utf-8`.
Each profile must have the same name as the corresponding codec in the `multicodec` library.
A profile must also have decode and encode function. They should be passed as a string containing the name of the module for required decode or encode. All such modules are available in [`content_hash/decodes`][link-decodes-directory] and [`content_hash/encodes`][link-encodes-directory].
Each module name should describe it as much as possible. Its name can only contain valid characters for Python modules.
Each decode module must have a `decode` function. It must be a function that takes a `bytes` input and returns a `str` result.
Each encode module must have an `encode` function. It must be a function that takes a `str` input and returns a `bytes` result.
All inputs and outputs must be the same as in the [JavaScript implementation][link-javascript-implementation]. Multiple profiles can share the same decodes and encodes.
## Versioning
This library uses [SemVer][link-semver] for versioning. For the versions available, see [the tags][link-tags] on this repository.
## License
This library is licensed under the MIT license. See the [LICENSE][link-license-file] file for details.
[icon-version]: https://img.shields.io/pypi/v/content-hash.svg?style=flat-square&label=version
[icon-downloads]: https://img.shields.io/pypi/dm/content-hash.svg?style=flat-square&label=downloads
[icon-license]: https://img.shields.io/pypi/l/content-hash.svg?style=flat-square&label=license
[icon-python]: https://img.shields.io/pypi/pyversions/content-hash?style=flat-square&label=python
[icon-travis]: https://img.shields.io/travis/com/filips123/ContentHashPy.svg?style=flat-square&label=linux+build
[icon-appveyor]: https://img.shields.io/appveyor/ci/filips123/ContentHashPy.svg?style=flat-square&label=windows+build
[icon-coverage]: https://img.shields.io/scrutinizer/coverage/g/filips123/ContentHashPy.svg?style=flat-square&label=coverage
[icon-quality]: https://img.shields.io/scrutinizer/g/filips123/ContentHashPy.svg?style=flat-square&label=quality
[link-pypi]: https://pypi.org/project/content-hash/
[link-license]: https://choosealicense.com/licenses/mit/
[link-python]: https://python.org/
[link-travis]: https://travis-ci.com/filips123/ContentHashPy/
[link-appveyor]: https://ci.appveyor.com/project/filips123/ContentHashPy/
[link-coverage]: https://scrutinizer-ci.com/g/filips123/ContentHashPy/code-structure/
[link-quality]: https://scrutinizer-ci.com/g/filips123/ContentHashPy/
[link-semver]: https://semver.org/
[link-eip-1577]: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1577.md
[link-ethereum]: https://www.ethereum.org/
[link-resolvers]: http://docs.ens.domains/en/latest/introduction.html
[link-multicodec]: https://github.com/multiformats/multicodec/
[link-supported-codecs]: https://github.com/multiformats/multicodec/blob/master/table.csv
[link-tags]: https://github.com/filips123/ContentHashPy/tags/
[link-license-file]: https://github.com/filips123/ContentHashPy/blob/master/LICENSE
[link-profiles-file]: https://github.com/filips123/ContentHashPy/blob/master/content_hash/profiles/__init__.py
[link-decodes-directory]: https://github.com/filips123/ContentHashPy/tree/master/content_hash/decodes/
[link-encodes-directory]: https://github.com/filips123/ContentHashPy/tree/master/content_hash/encodes/
[link-javascript-implementation]: https://github.com/pldespaigne/content-hash/
Raw data
{
"_id": null,
"home_page": "https://github.com/filips123/ContentHashPy/",
"name": "rotki-content-hash",
"maintainer": "",
"docs_url": null,
"requires_python": ">= 3.5",
"maintainer_email": "",
"keywords": "ethereum,ethereum-name-service,ens,eip1577,web3,decentralized",
"author": "Filip \u0160",
"author_email": "projects@filips.si",
"download_url": "https://files.pythonhosted.org/packages/de/13/8da7f1df598a37235c8283118ca568ac9b611f27db3e4ea25294961f17b4/rotki-content-hash-0.0.3.tar.gz",
"platform": null,
"description": "ContentHash for Python\n======================\n\n[![version][icon-version]][link-pypi]\n[![downloads][icon-downloads]][link-pypi]\n[![license][icon-license]][link-license]\n[![python][icon-python]][link-python]\n\n[![linux build][icon-travis]][link-travis]\n[![windows build][icon-appveyor]][link-appveyor]\n[![coverage][icon-coverage]][link-coverage]\n[![quality][icon-quality]][link-quality]\n\nPython implementation of EIP 1577 content hash.\n\n## Description\n\nThis is a simple package made for encoding and decoding content hashes has specified in the [EIP 1577][link-eip-1577].\nThis package will be useful for every [Ethereum][link-ethereum] developer wanting to interact with [EIP 1577][link-eip-1577] compliant [ENS resolvers][link-resolvers].\n\nFor JavaScript implementation, see [`pldespaigne/content-hash`][link-javascript-implementation].\n\n## Installation\n\n### Requirements\n\nContentHash requires Python 3.5 or higher.\n\n### From PyPI\n\nThe recommended way to install ContentHash is from PyPI with PIP.\n\n```bash\npip install content-hash\n```\n\n### From Source\n\nAlternatively, you can also install it from the source.\n\n```bash\ngit clone https://github.com/filips123/ContentHashPy.git\ncd ContentHashPy\npython setup.py install\n```\n\n## Usage\n\n### Supported Codecs\n\nThe following codecs are currently supported:\n\n- `swarm-ns`\n- `ipfs-ns`\n- `ipns-ns`\n\nEvery other codec supported by [`multicodec`][link-multicodec] will be encoded by default in `utf-8`. You can see the full list of the supported codecs [here][link-supported-codecs].\n\n### Getting Codec\n\nYou can use a `get_codec` function to get codec from the content hash.\n\nIt takes a content hash as a HEX string and returns the codec name. A content hash can be prefixed with a `0x`, but it's not mandatory.\n\n```py\nimport content_hash\n\nchash = 'bc037a716b746c776934666563766f367269'\ncodec = content_hash.get_codec(chash)\n\nprint(codec) # onion\n```\n\n### Decoding\n\nYou can use a `decode` function to decode a content hash.\n\nIt takes a content hash as a HEX string and returns the decoded content as a string. A content hash can be prefixed with a `0x`, but it's not mandatory.\n\n```py\nimport content_hash\n\nchash = 'e3010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f'\nvalue = content_hash.decode(chash)\n\nprint(value) # QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4\n```\n\n### Encoding\n\nYou can use an `encode` function to encode a content hash.\n\nIt takes a supported codec as a string and a value as a string and returns the corresponding content hash as a HEX string. The output will not be prefixed with a `0x`.\n\n```py\nimport content_hash\n\ncodec = 'swarm-ns'\nvalue = 'd1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162'\nchash = content_hash.encode(codec, value)\n\nprint(chash) # e40101701b20d1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162\n```\n\n## Creating Codecs\n\nAll supported codec profiles are available in [`content_hash/profiles/__init__.py`][link-profiles-file], in `PROFILES` dictionary. You need to add a new profile there. You only need to add a new profile if your codec encoding and decoding are different from `utf-8`.\n\nEach profile must have the same name as the corresponding codec in the `multicodec` library.\n\nA profile must also have decode and encode function. They should be passed as a string containing the name of the module for required decode or encode. All such modules are available in [`content_hash/decodes`][link-decodes-directory] and [`content_hash/encodes`][link-encodes-directory].\n\nEach module name should describe it as much as possible. Its name can only contain valid characters for Python modules.\n\nEach decode module must have a `decode` function. It must be a function that takes a `bytes` input and returns a `str` result.\n\nEach encode module must have an `encode` function. It must be a function that takes a `str` input and returns a `bytes` result.\n\nAll inputs and outputs must be the same as in the [JavaScript implementation][link-javascript-implementation]. Multiple profiles can share the same decodes and encodes.\n\n## Versioning\n\nThis library uses [SemVer][link-semver] for versioning. For the versions available, see [the tags][link-tags] on this repository.\n\n## License\n\nThis library is licensed under the MIT license. See the [LICENSE][link-license-file] file for details.\n\n[icon-version]: https://img.shields.io/pypi/v/content-hash.svg?style=flat-square&label=version\n[icon-downloads]: https://img.shields.io/pypi/dm/content-hash.svg?style=flat-square&label=downloads\n[icon-license]: https://img.shields.io/pypi/l/content-hash.svg?style=flat-square&label=license\n[icon-python]: https://img.shields.io/pypi/pyversions/content-hash?style=flat-square&label=python\n\n[icon-travis]: https://img.shields.io/travis/com/filips123/ContentHashPy.svg?style=flat-square&label=linux+build\n[icon-appveyor]: https://img.shields.io/appveyor/ci/filips123/ContentHashPy.svg?style=flat-square&label=windows+build\n[icon-coverage]: https://img.shields.io/scrutinizer/coverage/g/filips123/ContentHashPy.svg?style=flat-square&label=coverage\n[icon-quality]: https://img.shields.io/scrutinizer/g/filips123/ContentHashPy.svg?style=flat-square&label=quality\n\n[link-pypi]: https://pypi.org/project/content-hash/\n[link-license]: https://choosealicense.com/licenses/mit/\n[link-python]: https://python.org/\n[link-travis]: https://travis-ci.com/filips123/ContentHashPy/\n[link-appveyor]: https://ci.appveyor.com/project/filips123/ContentHashPy/\n[link-coverage]: https://scrutinizer-ci.com/g/filips123/ContentHashPy/code-structure/\n[link-quality]: https://scrutinizer-ci.com/g/filips123/ContentHashPy/\n[link-semver]: https://semver.org/\n\n[link-eip-1577]: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1577.md\n[link-ethereum]: https://www.ethereum.org/\n[link-resolvers]: http://docs.ens.domains/en/latest/introduction.html\n[link-multicodec]: https://github.com/multiformats/multicodec/\n[link-supported-codecs]: https://github.com/multiformats/multicodec/blob/master/table.csv\n\n[link-tags]: https://github.com/filips123/ContentHashPy/tags/\n[link-license-file]: https://github.com/filips123/ContentHashPy/blob/master/LICENSE\n[link-profiles-file]: https://github.com/filips123/ContentHashPy/blob/master/content_hash/profiles/__init__.py\n[link-decodes-directory]: https://github.com/filips123/ContentHashPy/tree/master/content_hash/decodes/\n[link-encodes-directory]: https://github.com/filips123/ContentHashPy/tree/master/content_hash/encodes/\n\n[link-javascript-implementation]: https://github.com/pldespaigne/content-hash/\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python implementation of EIP 1577 content hash",
"version": "0.0.3",
"project_urls": {
"Homepage": "https://github.com/filips123/ContentHashPy/"
},
"split_keywords": [
"ethereum",
"ethereum-name-service",
"ens",
"eip1577",
"web3",
"decentralized"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d4aecabdcda5473cfaff8e8e7b6158f5f3591cdd96f064b82d44365a66ae5a4b",
"md5": "318e6b3bdee4a5163a97488be04ce76d",
"sha256": "8b6ebc6b4a560588f4bb87b2ac97253753d283cb8e0e3937e31cdda55f65387f"
},
"downloads": -1,
"filename": "rotki_content_hash-0.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "318e6b3bdee4a5163a97488be04ce76d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">= 3.5",
"size": 10425,
"upload_time": "2023-06-15T22:34:57",
"upload_time_iso_8601": "2023-06-15T22:34:57.811800Z",
"url": "https://files.pythonhosted.org/packages/d4/ae/cabdcda5473cfaff8e8e7b6158f5f3591cdd96f064b82d44365a66ae5a4b/rotki_content_hash-0.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "de138da7f1df598a37235c8283118ca568ac9b611f27db3e4ea25294961f17b4",
"md5": "58f86f2e691442b0014a26130f7f7482",
"sha256": "392ae6c9f3f54f0c6984a40f9e81b7e045fdd5758079058478e83399d10f96d2"
},
"downloads": -1,
"filename": "rotki-content-hash-0.0.3.tar.gz",
"has_sig": false,
"md5_digest": "58f86f2e691442b0014a26130f7f7482",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">= 3.5",
"size": 10741,
"upload_time": "2023-06-15T22:34:59",
"upload_time_iso_8601": "2023-06-15T22:34:59.458268Z",
"url": "https://files.pythonhosted.org/packages/de/13/8da7f1df598a37235c8283118ca568ac9b611f27db3e4ea25294961f17b4/rotki-content-hash-0.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-15 22:34:59",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "filips123",
"github_project": "ContentHashPy",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"lcname": "rotki-content-hash"
}