Skip to main content

Pure Python CBOR (de)serializer with extensive tag support

Project description

Build Status Code Coverage Documentation Status

About

This library provides encoding and decoding for the Concise Binary Object Representation (CBOR) (RFC 7049) serialization format. 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.

  • 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.3.0.tar.gz (81.2 kB view details)

Uploaded Source

Built Distributions

cbor2-5.3.0-cp39-cp39-win_amd64.whl (59.0 kB view details)

Uploaded CPython 3.9 Windows x86-64

cbor2-5.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (224.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

cbor2-5.3.0-cp39-cp39-macosx_10_14_x86_64.whl (55.8 kB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

cbor2-5.3.0-cp38-cp38-win_amd64.whl (59.0 kB view details)

Uploaded CPython 3.8 Windows x86-64

cbor2-5.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (240.3 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

cbor2-5.3.0-cp38-cp38-macosx_10_14_x86_64.whl (55.5 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

cbor2-5.3.0-cp37-cp37m-win_amd64.whl (58.0 kB view details)

Uploaded CPython 3.7m Windows x86-64

cbor2-5.3.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (186.8 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

cbor2-5.3.0-cp37-cp37m-macosx_10_14_x86_64.whl (54.7 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

cbor2-5.3.0-cp36-cp36m-win_amd64.whl (58.1 kB view details)

Uploaded CPython 3.6m Windows x86-64

cbor2-5.3.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (184.0 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

cbor2-5.3.0-cp36-cp36m-macosx_10_14_x86_64.whl (54.8 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: cbor2-5.3.0.tar.gz
  • Upload date:
  • Size: 81.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for cbor2-5.3.0.tar.gz
Algorithm Hash digest
SHA256 462b3604d9579458a79e6ca350943c49aabbc98c794c111a79b98720b9164336
MD5 78fc2e79b0e72b7a347bc6b3df8fd7f5
BLAKE2b-256 360f6c64c4b45bbe0249e65e61691615ef3fa9e89f0b31d69b04cd5e4078d293

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cbor2-5.3.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 59.0 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for cbor2-5.3.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f0058d33b5eaffb176d6190d175a5391f13362f165881deea2b99e63b66ecf55
MD5 f7b7eff636a7e185c741fa31ee2a72b2
BLAKE2b-256 e2aab85cba327fe1686bdbaa19726bf1bb45609f7883825c5fe99b83470b8fd6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cbor2-5.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6f8c53f55a037d7e4ff21f14b972a63654d89eff9148434a81f4e1875379a3b3
MD5 aed61870774a6445775a1960cc25db94
BLAKE2b-256 abd6895fb2d307d25746f21f04f8cc8b625bf8c1344f4819f7bf17be7acd1c19

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cbor2-5.3.0-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 55.8 kB
  • Tags: CPython 3.9, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for cbor2-5.3.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 101af13adb6e4e161d85a80b8b8f04860be8201155ddac5e77c56015821812c0
MD5 3df336f0149a5d9d585cc60ef752049b
BLAKE2b-256 b3ec2b970f4d4cb4a6e8eb248976794e3acc9d27868fb77242b526f4a648a629

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cbor2-5.3.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 59.0 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for cbor2-5.3.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 b37fe4a7976e82ae627ce01eae725458d1c46d1acaa8a15c12078a4ec3156bf2
MD5 ae17aa6f9260f2b7a04324b5d1cdcc1f
BLAKE2b-256 52478c9b18b7d503c5a6fec33b3c318015357167b539a74b78bd3d15768df925

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cbor2-5.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 149b91572289c88f04ec728f705642e8f2f52323ff54c402b7d1329a4c952288
MD5 c373524e57b7447e6f024436db4936f1
BLAKE2b-256 f3be377709603e50ad763d48346a3a14634322e31e484c7808550b33de65e020

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cbor2-5.3.0-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 55.5 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for cbor2-5.3.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 2963d6394de040a71f4c59e90ceaf7089734a2dd2d420131625315968da057c2
MD5 efd1fa0829e07dd08620d5004813c9ce
BLAKE2b-256 bd251e309649eec607c29684e0126f53a36319c33a1f573df8982b7f4133a799

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cbor2-5.3.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 58.0 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for cbor2-5.3.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 371d5079ba80e6851fddd35a9c40c9aafbb71e10bb1a01e74d39bda89530227c
MD5 303103ce849734d4e8d7d35e81651dfe
BLAKE2b-256 ea6410e1af3859be6f5bc1a83e1423bd91d026207fede3846bfb6764324aac98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cbor2-5.3.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a573777f4c19e5236b77905b70ea7744f8e43df6a7cd479cf6c9a16beb02be69
MD5 5194d6386d84c2d478bd5165921b7160
BLAKE2b-256 fc598330293d67fd3a83ec40e10ce4aac84fcf610156912ae22fe88ef90f8442

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cbor2-5.3.0-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 54.7 kB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for cbor2-5.3.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 5114cb48593e2f33d70696545f3341925b31bb785e49e9ff032c1f7c9195d684
MD5 1e83508c9fb463fbdfad458e8ffd38c6
BLAKE2b-256 c0c938b532496e48f9026cf696156eba9611e93bf47e1abd349ab25e39ee4a19

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cbor2-5.3.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 58.1 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for cbor2-5.3.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 f5df0ad8c16f7992bf24e5c9a53f03a11a990fd18253c3c335315bd25a34f832
MD5 8374b06c39731ae803517f633d574508
BLAKE2b-256 0daa7ed69e2ff50d80c3791c2c407856281248e40b3572d142792d4cea9a8d92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cbor2-5.3.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 034bb95b7c38a93568a55b9b2cb24219abe05fbc0fa97740fa9f5147c88a2e3a
MD5 afa89ea3d1ac043e60d1f6bc0f249582
BLAKE2b-256 a37d72a263874af01f9add25a2fe7ea5dca0dfd6befae278cc295210f2507019

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cbor2-5.3.0-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 54.8 kB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for cbor2-5.3.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 ac54f26251e2e77bcd821b7799813891faf0ed6a9a8f337ac4943f046f39c3b4
MD5 c933b8f8cbc5396070350b0118dfd7a8
BLAKE2b-256 d81a66277db090c0999c4c9aa815fcf19559f9c638c4b8c45ca15e2d25978c9c

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