Python implemention of the IPLD DAG-JSON codec
Project description
dag-json
Python implemention of the IPLD DAG-JSON codec. Uses the CID
class from multiformats
. Passes all of IPLD's DAG-JSON cross-codec test fixtures.
Install from PyPI with pip install dag-json
.
License: This project is placed in the public domain.
Usage
The dag_json
module has two functions, encode
and decode
.
encode
takes any IPLD-compatible native Python object -int
,float
,str
,bool
,list
,bytes
, ormultiformats.CID
- and returns it as DAG-JSON encodedbytes
.decode
takes DAG-JSON encodedbytes
and returns the corresponding native Python object.
Here's example usage:
>>> from dag_json import decode, encode
>>> from multiformats import CID
>>>
>>> encoded = encode({
'foo': 'bar',
'data': b'hello world',
'link': CID.decode('QmUGhP2X8xo9dsj45vqx1H6i5WqPqLqmLQsHTTxd3ke8mp'),
})
>>> encoded
b'{"data":{"/":{"bytes":"aGVsbG8gd29ybGQ"}},"foo":"bar","link":{"/":"QmUGhP2X8xo9dsj45vqx1H6i5WqPqLqmLQsHTTxd3ke8mp"}}'
>>>
>>> repr(decode(encoded))
{
'data': b'hello world',
'foo': 'bar',
'link': CID('base58btc', 0, 'dag-pb', '12205822d187bd40b04cc8ae7437888ebf844efac1729e098c8816d585d0fcc42b5b'),
}
Changelog
0.1 - 2023-04-23
Initial release!
Release instructions
Here's how to package, test, and ship a new release.
-
Run the unit tests.
source local/bin/activate.csh python3 -m unittest discover
-
Bump the version number in
pyproject.toml
.git grep
the old version number to make sure it only appears in the changelog. Change the current changelog entry inREADME.md
for this new version from unreleased to the current date. -
git commit -am 'release vX.Y'
-
Upload to test.pypi.org for testing.
python3 -m build setenv ver X.Y twine upload -r pypitest dist/dag-json-$ver*
-
Install from test.pypi.org.
cd /tmp python3 -m venv local source local/bin/activate.csh pip3 uninstall dag-json # make sure we force pip to use the uploaded version pip3 install --upgrade pip pip3 install -i https://test.pypi.org/simple --extra-index-url https://pypi.org/simple dag-json==$ver deactivate
-
Run the example code above to test that the code loads and runs.
-
Tag the release in git. In the tag message editor, delete the generated comments at bottom, leave the first line blank (to omit the release "title" in github), put
### Notable changes
on the second line, then copy and paste this version's changelog contents below it.git tag -a v$ver --cleanup=verbatim git push && git push --tags
-
Click here to draft a new release on GitHub. Enter
vX.Y
in the Tag version box. Leave Release title empty. Copy### Notable changes
and the changelog contents into the description text box. -
Upload to pypi.org!
twine upload dist/dag-json-$ver.tar.gz dist/dag-json-$ver-py3-none-any.whl
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.