Python implementation of the DAG-CBOR codec.
Project description
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
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.
Source Distribution
makkus.dag-cbor-0.3.3.tar.gz
(52.3 kB
view hashes)
Built Distribution
Close
Hashes for makkus.dag_cbor-0.3.3-py3-none-any.whl
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | e9ef58c618b76694e61bf9b7f311e1f9c08c130df0c64947342dcbeb1377ca77 |
|
| MD5 | 7a7d5b0a7df34b25af5cb15bb5673be6 |
|
| BLAKE2b-256 | 576d5780e1cf4eea9c0d2799552a6e0476bc69b1f9324acc229f0dbfe74c1145 |