Skip to main content

Python implementation of the DAG-CBOR codec.

Project description

Python versions PyPI version PyPI status Checked with Mypy Documentation Status Python package status 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.

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

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.2.0.post1.tar.gz (38.7 kB view details)

Uploaded Source

Built Distribution

dag_cbor-0.2.0.post1-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dag-cbor-0.2.0.post1.tar.gz
  • Upload date:
  • Size: 38.7 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.2.0.post1.tar.gz
Algorithm Hash digest
SHA256 0b961e9822c512cea272b4185d019ab379c90ec27a3d18a907b7b67330993946
MD5 6276bfa433f6b6f7ec75e679ced09f7a
BLAKE2b-256 01beb6429b955c24c77207ed57a36319077562121d0313ccb7cff2afcc4d8126

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dag_cbor-0.2.0.post1-py3-none-any.whl
  • Upload date:
  • Size: 16.1 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.2.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 d54706c5974ead5ae6f1af69f3eed6e0a27ffd3f4aef8a77162074a52e1633b4
MD5 48e9e83efd5d3133c30f7027c76d292b
BLAKE2b-256 c86e646f0c22b850d07f078b6e281721c6ea20296d083aad9a34b495c1f1082e

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