dag-json

Python implementation 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. You may also use it under the CC0 License.
Usage
The dag_json module has three functions:
decodetakes DAG-JSON encodedbytesand returns the corresponding native Python object.encodetakes any IPLD-compatible native Python object -int,float,str,bool,list,bytes, ormultiformats.CID- and returns it as DAG-JSON encodedbytes.encoded_cidtakes DAG-JSON encodedbytesand returns its correspondingmultiformats.CID.
Here's example usage:
>>> from dag_json import decode, encode, encoded_cid
>>> 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'),
}
>>> encoded_cid(encoded)
CID('base58btc', 1, 'dag-json', '1220d7c1db350b6fda1df4ab788bffc87b24c68d05ddfb2c9ff6f2a4f9eb12236c31')
Changelog
0.3 - 2024-09-23
- Add new
dialectkwarg todecodeto matchencode.
0.2 - 2024-06-24
- Add new
encoded_cidfunction. - Add new
dialectkwarg toencode,DagJsonEncoder. Currently only supports one value,'atproto', to encode CIDs and bytes with$linkand$byteskeys according to the AT Protocol data model.
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 python -m unittest discover
-
Bump the version number in
pyproject.toml.git grepthe old version number to make sure it only appears in the changelog. Change the current changelog entry inREADME.mdfor this new version from unreleased to the current date. -
git commit -am 'release vX.Y' -
Upload to test.pypi.org for testing.
python -m build setenv ver X.Y twine upload -r pypitest dist/dag_json-$ver*
-
Install from test.pypi.org.
cd /tmp python -m venv local source local/bin/activate.csh pip uninstall dag-json # make sure we force pip to use the uploaded version pip install --upgrade pip pip install -i https://test.pypi.org/simple --extra-index-url https://pypi.org/simple dag-json==$ver
-
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 changeson 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.Yin the Tag version box. Leave Release title empty. Copy### Notable changesand 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
Metadata
Release files for dag-json 0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dag_json-0.3.tar.gz | 7.5 kB | Without provenance | Details for dag_json-0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dag_json-0.3-py3-none-any.whl | Python 3 | none | any | Details for dag_json-0.3-py3-none-any.whl |
Total release size: 15.1 kB
Release files / dag_json-0.3.tar.gz
| Download URL | dag_json-0.3.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
854fdff028cb5289b3e3b0639f18676e9bc9c192348fc45a8691811540c1c9ef
|
|
BLAKE2b-256 checksum How to use checksums |
051010d2d13a0ca7012a9af6db996399c21009ea3b5618a00eb4ee29c5a22042
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Release files / dag_json-0.3-py3-none-any.whl
| Download URL | dag_json-0.3-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
61c055f90b8ee39dcf42e4189ba7fc55f37c71bddf1cce885df823f9fce7d627
|
|
BLAKE2b-256 checksum How to use checksums |
aa53b2cbcca77777c051e0c95f4cd97f8101ec1dfe7da45f237359c120c302b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Security for dag-json 0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.