https://github.com/hashberg-io/dag-cbor
Python implementation of the DAG-CBOR codec for IPLD.
https://github.com/hashberg-io/dag-cbor
cbor dag-cbor ipld multiformats python
Last synced: 5 months ago
JSON representation
Python implementation of the DAG-CBOR codec for IPLD.
- Host: GitHub
- URL: https://github.com/hashberg-io/dag-cbor
- Owner: hashberg-io
- License: mit
- Created: 2021-09-15T18:18:45.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-12-18T22:31:42.000Z (almost 2 years ago)
- Last Synced: 2025-05-11T13:48:09.676Z (5 months ago)
- Topics: cbor, dag-cbor, ipld, multiformats, python
- Language: Python
- Homepage: https://dag-cbor.readthedocs.io
- Size: 222 KB
- Stars: 16
- Watchers: 2
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.rst
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
dag-cbor: A Python implementation of the `DAG-CBOR codec `_
========================================================================================================.. image:: https://img.shields.io/badge/python-3.7+-green.svg
:target: https://docs.python.org/3.7/
:alt: Python versions.. image:: https://img.shields.io/pypi/v/dag-cbor.svg
:target: https://pypi.python.org/pypi/dag-cbor/
:alt: PyPI version.. image:: https://img.shields.io/pypi/status/dag-cbor.svg
:target: https://pypi.python.org/pypi/dag-cbor/
:alt: PyPI status.. image:: http://www.mypy-lang.org/static/mypy_badge.svg
:target: https://github.com/python/mypy
:alt: Checked with Mypy
.. image:: https://readthedocs.org/projects/dag-cbor/badge/?version=latest
:target: https://dag-cbor.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status.. image:: https://github.com/hashberg-io/dag-cbor/actions/workflows/python-pytest.yml/badge.svg
:target: https://github.com/hashberg-io/dag-cbor/actions/workflows/python-pytest.yml
:alt: Python package status.. image:: https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square
:target: https://github.com/RichardLitt/standard-readme
:alt: standard-readme compliantThis 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.
.. contents::
Install
-------You can install the latest release from `PyPI `_ as follows:
.. code-block:: console
$ 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 ``_.
License
-------`MIT © Hashberg Ltd. `_