gdixon / dag-cbor

Python implementation of the DAG-CBOR codec for IPLD.

Home Page:https://dag-cbor.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dag-cbor: A Python implementation of DAG-CBOR

Generic badge PyPI version shields.io PyPI status Checked with Mypy Python package standard-readme compliant

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.

Table of Contents

Install

You can install this package with pip:

pip install dag-cbor

Usage

The core functionality of the library is performed by the encode and decode functions:

>>> import dag_cbor
>>> dag_cbor.encode({'a': 12, 'b': 'hello!'})
b'\xa2aa\x0cabfhello!'
>>> dag_cbor.decode(b'\xa2aa\x0cabfhello!')
{'a': 12, 'b': 'hello!'}

The random module contains functions to generate random data compatible with DAG-CBOR encoding:

>>> import pprint
>>> import dag_cbor
>>> options = dict(min_codepoint=0x41, max_codepoint=0x5a, include_cid=False)
>>> with dag_cbor.random.rand_options(**options):
...     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}

For further information, please refer to the API documentation.

API

The API documentation for this package is automatically generated by pdoc.

Contributing

Please see the contributing file.

License

MIT © Hashberg Ltd.

About

Python implementation of the DAG-CBOR codec for IPLD.

https://dag-cbor.readthedocs.io

License:MIT License


Languages

Language:Python 100.0%