Skip to main content

Pure Python CBOR (de)serializer with extensive tag support

Project description

Testing Status Publish Status Code Coverage Documentation Status

About

This library provides encoding and decoding for the Concise Binary Object Representation (CBOR) (RFC 8949) serialization format. The specification is fully compatible with the original RFC 7049. Read the docs to learn more.

It is implemented in pure python with an optional C backend.

On PyPy, cbor2 runs with almost identical performance to the C backend.

Features

  • Simple api like json or pickle modules.

  • Support many CBOR tags with stdlib objects.

  • Generic tag decoding.

  • Shared value references including cyclic references.

  • String references compact encoding with repeated strings replaced with indices.

  • Optional C module backend tested on big- and little-endian architectures.

  • Extensible tagged value handling using tag_hook and object_hook on decode and default on encode.

  • Command-line diagnostic tool, converting CBOR file or stream to JSON python -m cbor2.tool (This is a lossy conversion, for diagnostics only)

  • Thorough test suite.

Installation

pip install cbor2

Requirements

  • Python >= 3.6 (or PyPy3 3.6+)

  • C-extension: Any C compiler that can build Python extensions. Any modern libc with the exception of Glibc<2.9

Building the C-Extension

To force building of the optional C-extension, set OS env CBOR2_BUILD_C_EXTENSION=1. To disable building of the optional C-extension, set OS env CBOR2_BUILD_C_EXTENSION=0. If this environment variable is unset, setup.py will default to auto detecting a compatible C library and attempt to compile the extension.

Usage

Basic Usage

Command-line Usage

python -m cbor2.tool converts CBOR data in raw binary or base64 encoding into a representation that allows printing as JSON. This is a lossy transformation as each datatype is converted into something that can be represented as a JSON value.

Usage:

# Pass hexadecimal through xxd.
$ echo a16568656c6c6f65776f726c64 | xxd -r -ps | python -m cbor2.tool --pretty
{
    "hello": "world"
}
# Decode Base64 directly
$ echo ggEC | python -m cbor2.tool --decode
[1, 2]
# Read from a file encoded in Base64
$ python -m cbor2.tool -d tests/examples.cbor.b64
{...}

It can be used in a pipeline with json processing tools like jq to allow syntax coloring, field extraction and more.

CBOR data items concatenated into a sequence can be decoded also:

$ echo ggECggMEggUG | python -m cbor2.tool -d --sequence
[1, 2]
[3, 4]
[5, 6]

Multiple files can also be sent to a single output file:

$ python -m cbor2.tool -o all_files.json file1.cbor file2.cbor ... fileN.cbor

Security

This library has not been tested against malicious input. In theory it should be as safe as JSON, since unlike pickle the decoder does not execute any code.

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

cbor2-5.4.2.tar.gz (85.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cbor2-5.4.2-cp39-cp39-win_amd64.whl (62.8 kB view details)

Uploaded CPython 3.9Windows x86-64

cbor2-5.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (222.6 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

cbor2-5.4.2-cp39-cp39-macosx_10_14_x86_64.whl (59.6 kB view details)

Uploaded CPython 3.9macOS 10.14+ x86-64

cbor2-5.4.2-cp38-cp38-win_amd64.whl (62.9 kB view details)

Uploaded CPython 3.8Windows x86-64

cbor2-5.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (236.4 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

cbor2-5.4.2-cp38-cp38-macosx_10_14_x86_64.whl (59.1 kB view details)

Uploaded CPython 3.8macOS 10.14+ x86-64

cbor2-5.4.2-cp37-cp37m-win_amd64.whl (61.4 kB view details)

Uploaded CPython 3.7mWindows x86-64

cbor2-5.4.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (190.9 kB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

cbor2-5.4.2-cp37-cp37m-macosx_10_14_x86_64.whl (58.2 kB view details)

Uploaded CPython 3.7mmacOS 10.14+ x86-64

cbor2-5.4.2-cp36-cp36m-win_amd64.whl (61.4 kB view details)

Uploaded CPython 3.6mWindows x86-64

cbor2-5.4.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (189.4 kB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

cbor2-5.4.2-cp36-cp36m-macosx_10_14_x86_64.whl (58.4 kB view details)

Uploaded CPython 3.6mmacOS 10.14+ x86-64

File details

Details for the file cbor2-5.4.2.tar.gz.

File metadata

  • Download URL: cbor2-5.4.2.tar.gz
  • Upload date:
  • Size: 85.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for cbor2-5.4.2.tar.gz
Algorithm Hash digest
SHA256 e283e70b55a049ff364cc5e648fde587e4d9b0e87e4b2664c69e639135e6b3b8
MD5 b3a6085ee1a9e11ddec305f7a7bc5956
BLAKE2b-256 d4cab96be94f694155ce58823c38cf8fd1aa620bdc91e2c801713cdb4167b6aa

See more details on using hashes here.

File details

Details for the file cbor2-5.4.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: cbor2-5.4.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 62.8 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for cbor2-5.4.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 310c7d7925f7aa6cb90791606be17c164bbf3b28d4d17047b5d19d303f2fe817
MD5 91f82192e8a15ea7c921b41062ed29eb
BLAKE2b-256 3f2ac9b948103c537a595cf47fabb65cf7022ca7341b33fdf931d383aa1d06cf

See more details on using hashes here.

File details

Details for the file cbor2-5.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: cbor2-5.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 222.6 kB
  • Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for cbor2-5.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 395aec8f415f039ab3be6cb58861c21bd2202f5c0ad6537b31956da532ea74ad
MD5 7fe06448de687aaeef2603212b8ba32f
BLAKE2b-256 0f83e3c2598b41891489fff6b2df03b8b505307f379085d448fd752c51c1410a

See more details on using hashes here.

File details

Details for the file cbor2-5.4.2-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: cbor2-5.4.2-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 59.6 kB
  • Tags: CPython 3.9, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for cbor2-5.4.2-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 0e27c52abdccadadab858437f6d98d5e8711aa84f0af7417dd1404d16127db7f
MD5 b50e67a67e01b2de2aac696b27a3d794
BLAKE2b-256 5e6ddd049f0490ec5a045e2b441f9302e8dfaf9ce0b49f92ab9aa0915bc0fbf2

See more details on using hashes here.

File details

Details for the file cbor2-5.4.2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: cbor2-5.4.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 62.9 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for cbor2-5.4.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 79c10306d9128258dea110c01abbe9c58c48ee2ffcf995f982fb063f1a82e2ee
MD5 c9969992b29b995dcad17441e1db9c78
BLAKE2b-256 5897393f0241456b3ebec346444644b45c3691dcddb3b18d0e388657b8765beb

See more details on using hashes here.

File details

Details for the file cbor2-5.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: cbor2-5.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 236.4 kB
  • Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for cbor2-5.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 32c1d00d8ad1a89f2358bf444fd43cacc3ca61f3c3feb1a2f2b2bea8ba4853d2
MD5 1b07243d2e41680a8bbb8769c84e0696
BLAKE2b-256 f5189088136c36b3afd736d096f9f4eb615b3c33906d800b983f3bbc1c7f4d48

See more details on using hashes here.

File details

Details for the file cbor2-5.4.2-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: cbor2-5.4.2-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 59.1 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for cbor2-5.4.2-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 2757a7b624478d3b6707adf8ab7aef03d81fdaca6bea981b2323069660b9360f
MD5 8c59575c26503d6ed7574dae9e70223c
BLAKE2b-256 4086a786d1e56109a5dcc04f7ddaee470e32f740f8072905cf52dc7c35fbb673

See more details on using hashes here.

File details

Details for the file cbor2-5.4.2-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: cbor2-5.4.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 61.4 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for cbor2-5.4.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 d9f64241bb30439f6ebde74101683e9dceecab95afe105560ac9d0e54d1b3c2e
MD5 2069f2690cb79cb339f10d67583527cf
BLAKE2b-256 a5abb500a76f425130a465df201563bae62922c0534310fe3bbbc91fec273095

See more details on using hashes here.

File details

Details for the file cbor2-5.4.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: cbor2-5.4.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 190.9 kB
  • Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for cbor2-5.4.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 93baf1ee33a305acf8f1391fed4e63ea2e837b561294fd6275ce8785acb795fa
MD5 5883f9636474e5bc6a702994615c5e78
BLAKE2b-256 f5cc9cd6f14d87e0b5cadc442982711af21127801d6b9a13707d582e8bbed32c

See more details on using hashes here.

File details

Details for the file cbor2-5.4.2-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: cbor2-5.4.2-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 58.2 kB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for cbor2-5.4.2-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 4c112b21fad53b2d936ef2d55c698641a6d49025c1a9cf73db3ef24684514db1
MD5 c532f38715fb7f8573f5f3aee7763b34
BLAKE2b-256 a45dfe2306970fcefce59437d0957c75bce2de537d3faf23821e2cbac99ac4ac

See more details on using hashes here.

File details

Details for the file cbor2-5.4.2-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: cbor2-5.4.2-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 61.4 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for cbor2-5.4.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 10f178697e66eaae51534c3ef9acce1abf2f747e63c841e8702b9453c5bc4cfe
MD5 819ce3d9a9bc7ff3c514f4f169c6c5d8
BLAKE2b-256 bf3cc0369783dd222f530110eacab1fdf7bf444416184a88df89a03bd4d4fa0d

See more details on using hashes here.

File details

Details for the file cbor2-5.4.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: cbor2-5.4.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 189.4 kB
  • Tags: CPython 3.6m, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for cbor2-5.4.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 70fb47a4bca70ae2d1b2b6c9d5ed6c898494739966653f7c84737f795b26d754
MD5 09590ea917beea6afb6efad7909d2f09
BLAKE2b-256 8d46ad351e8202e07943eb1353941f33dc22064e37b3f2ca4c698f1a5bbbce0d

See more details on using hashes here.

File details

Details for the file cbor2-5.4.2-cp36-cp36m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: cbor2-5.4.2-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 58.4 kB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for cbor2-5.4.2-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 0153635a78e62d70f26f5b3469cb8de822420eda69c996304fb3d0dc1a53d7f3
MD5 0dd0d9c340535fc6ae321f3ca337c0d1
BLAKE2b-256 bb79b5024258ff48058d13380c297a355f99f309bcf00d443aee7146584b7e3a

See more details on using hashes here.

Supported by

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