Python implementation of the DAG-CBOR codec.
Project Links
Meta
Author: hashberg
Requires Python: >=3.7
Classifiers
Development Status
- 4 - Beta
Programming Language
- Python :: 3.10
- Python :: 3.9
- Python :: 3.8
- Python :: 3.7
Operating System
- OS Independent
Natural Language
- English
Typing
- Typed
This is a fully compliant Python implementation of the DAG-CBOR codec, a subset of the Concise Binary Object Representation (CBOR) supporting the IPLD Data Model and enforcing a unique (strict) encoded representation of items.
Install
You can install the latest release from PyPI as follows:
$ pip install --upgrade dag-cbor
Usage
We suggest you import DAG-CBOR as follows:
>>> import dag_cbor
Below are some basic usage examples, to get you started: for detailed documentation, see https://dag-cbor.readthedocs.io/
Encoding and decoding
>>> dag_cbor.encode({'a': 12, 'b': 'hello!'})
b'\xa2aa\x0cabfhello!'
>>> dag_cbor.decode(b'\xa2aa\x0cabfhello!')
{'a': 12, 'b': 'hello!'}
Random DAG-CBOR data
>>> import pprint # pretty-printing
>>> custom_opts = dict(min_codepoint=0x41, max_codepoint=0x5a, include_cid=False)
>>> with dag_cbor.random.options(**custom_opts):
... for d in dag_cbor.random.rand_dict(3):
... pprint.pp(d)
...
{'BIQPMZ': b'\x85\x1f\x07/\xcc\x00\xfc\xaa',
'EJEYDTZI': {},
'PLSG': {'G': 'JFG',
'HZE': -61.278,
'JWDRKRGZ': b'-',
'OCCKQPDJ': True,
'SJOCTZMK': False},
'PRDLN': 39.129,
'TUGRP': None,
'WZTEJDXC': -69.933}
{'GHAXI': 39.12,
'PVUWZLC': 4.523,
'TDPSU': 'TVCADUGT',
'ZHGVSNSI': [-57, 9, -78.312]}
{'': 11, 'B': True, 'FWD': {}, 'GXZBVAR': 'BTDWMGI', 'TDICHC': 87}
API
For the full API documentation, see https://dag-cbor.readthedocs.io/
Contributing
Please see CONTRIBUTING.md.
License
0.3.3
Dec 18, 2023
0.3.2
Feb 26, 2023
0.3.1
Feb 26, 2023
0.3.0
Feb 06, 2023
0.2.4
Feb 05, 2023
0.2.3.post2
Feb 04, 2023
0.2.3
Feb 03, 2023
0.2.2
Jan 16, 2022
0.2.1
Jan 15, 2022
0.2.0.post1
Dec 30, 2021
0.1.2.post1
Dec 21, 2021
0.1.2
Dec 20, 2021
0.1.0
Dec 13, 2021
0.0.7.post4
Dec 13, 2021
0.0.7.post3
Dec 13, 2021
0.0.7.post2
Dec 12, 2021
0.0.7
Dec 12, 2021
0.0.6
Sep 23, 2021
0.0.5.post1
Sep 21, 2021
0.0.5
Sep 21, 2021
0.0.4
Sep 20, 2021
0.0.3
Sep 20, 2021
Wheel compatibility matrix
Files in release
Extras:
None
Dependencies:
typing-extensions
(>=4.6.0)
typing-validation
(>=1.1.0)
multiformats
(>=0.3.1)