Skip to main content

Python implementation of the DAG-CBOR codec.

Project description

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 the latest release from PyPI as follows:

pip install --upgrade 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dag-cbor-0.1.2.post1.tar.gz (57.2 kB view details)

Uploaded Source

Built Distribution

dag_cbor-0.1.2.post1-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file dag-cbor-0.1.2.post1.tar.gz.

File metadata

  • Download URL: dag-cbor-0.1.2.post1.tar.gz
  • Upload date:
  • Size: 57.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.7

File hashes

Hashes for dag-cbor-0.1.2.post1.tar.gz
Algorithm Hash digest
SHA256 59303e0568bcccdafbb28710bb96e90fca6b9966335f0b53796b8f246757d835
MD5 139cf7e83e1bed6e2834a3b34be2599f
BLAKE2b-256 a5c34bd0904ccc455d342f2c4a1234b69a7a75d9dde80b5877d1338edc3b8a93

See more details on using hashes here.

File details

Details for the file dag_cbor-0.1.2.post1-py3-none-any.whl.

File metadata

  • Download URL: dag_cbor-0.1.2.post1-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.7

File hashes

Hashes for dag_cbor-0.1.2.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 63c5110c0a77032080e155fa73c6367ee20aae4c72eba25466c83695209cf962
MD5 41fd5ee7c1bac8016020aa8bb29d2f4f
BLAKE2b-256 cf6f8ac400050a20b631bf9fdd534b74f4436cd32a6cee6f8bdfdd6e000399e9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page