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.0.tar.gz (84.8 kB view details)

Uploaded Source

Built Distributions

cbor2-5.4.0-cp39-cp39-win_amd64.whl (62.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

cbor2-5.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (239.6 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

cbor2-5.4.0-cp39-cp39-macosx_10_14_x86_64.whl (59.2 kB view details)

Uploaded CPython 3.9 macOS 10.14+ x86-64

cbor2-5.4.0-cp38-cp38-win_amd64.whl (62.4 kB view details)

Uploaded CPython 3.8 Windows x86-64

cbor2-5.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (258.1 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

cbor2-5.4.0-cp38-cp38-macosx_10_14_x86_64.whl (58.7 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

cbor2-5.4.0-cp37-cp37m-win_amd64.whl (61.0 kB view details)

Uploaded CPython 3.7m Windows x86-64

cbor2-5.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (198.2 kB view details)

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

cbor2-5.4.0-cp37-cp37m-macosx_10_14_x86_64.whl (57.8 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

cbor2-5.4.0-cp36-cp36m-win_amd64.whl (61.0 kB view details)

Uploaded CPython 3.6m Windows x86-64

cbor2-5.4.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (195.7 kB view details)

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

cbor2-5.4.0-cp36-cp36m-macosx_10_14_x86_64.whl (57.9 kB view details)

Uploaded CPython 3.6m macOS 10.14+ x86-64

File details

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

File metadata

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

File hashes

Hashes for cbor2-5.4.0.tar.gz
Algorithm Hash digest
SHA256 a7926f7244b08c413f1a4fa71a81aa256771c75bdf1a4fd77308547a2d63dd48
MD5 0b4ac06208304fd8251e50d55a7692ca
BLAKE2b-256 ddcf154810bb8698a583fd30faec5a34d84d8a01cc700e34c1e41b90616d7d63

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cbor2-5.4.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 4dd142764607b1a8b5e3e3b474d2b84099e9cbb323596a15ee8db0d78901d95f
MD5 ee94b790ed6520b0bb53f5c79c03113a
BLAKE2b-256 7a89708041c48a7191b836bab858d78bbe0da49b66c819836cf8a3af83ab6274

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cbor2-5.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8bc9f5054650d05e6d3e90f6490dcd6ef6c01ad9c1568958a48dde2702824cb1
MD5 b4253209a78318a25223955ef23caa4e
BLAKE2b-256 ff2b4d944807a103a019bdbfb8c14eaead7868d3a017ada505baa8af1b0f8794

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cbor2-5.4.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 ae31d3b5966807fdff6c9e6f894b0aa10474295d9ff8467a8b978a569c8fec47
MD5 d8e855be9ad7c67f76a8d9620681400f
BLAKE2b-256 1b66bbfbbb425e2d214503d75e3d31b1557ecb4c263f44aa16397f7ec3da453d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cbor2-5.4.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 98410520482796a547af2d5ffe11a8a2dc3b9f2124834fa7c12db8264935ed61
MD5 f90ee060f3d00805a976808cecd06cfb
BLAKE2b-256 28a031dea4fc692fe97ed9b18e0e0e2e09f933ba5d9c5436d5e87859c9302c60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cbor2-5.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d562b2773e14ee1d65ea5b85351a83a64d4f3fd011bc2b4c70a6e813e78203ce
MD5 48c4c14d1ea53dfc8b39a71cf89b8e63
BLAKE2b-256 df5d3b2b390d2ff5f83cc68733d3f70585460c76ae4264fe2a47f6ded8d7db44

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cbor2-5.4.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 ce6219986385778b1ab7f9b542f160bb4d3558f52975e914a27b774e47016fb7
MD5 fc638bf44b15f488b4dc88e2125c698e
BLAKE2b-256 40912d1e6e8155e535162ab03fac4168b1eb3574a6fb39126ea34a0c65e93fec

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cbor2-5.4.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 3c586a6e328ba5020802346f5e0304f81b982dcafeb51ee4109c9be9cccbc4a0
MD5 1a53ea1ffbf102dfd8b9e57402bac0ba
BLAKE2b-256 7039074591edc001055d720b0cf6d391034fe09fab0e936069e33da68186bae5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cbor2-5.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 059363ae716c60f6ba29aa61b3d9c57896189c351c4119095f0542aec169e4dc
MD5 f5392b9ce8d1bd683e83bff39c984d87
BLAKE2b-256 4c595e39f26472f4bcb4c217f28bf24bc682fcfeaed6ffd3fe556c6c53cd6f76

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cbor2-5.4.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 0d22b47fb24b384200277fcfb0582c3a3551c413ad51f3bd3ee334caaf79a483
MD5 008e987949dfb61b1da15ae49a288775
BLAKE2b-256 a1a6db1ec011ec1fc8eff0963d72a1a819823c713a11893c2af76ad9bc9be7b6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cbor2-5.4.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 6f8a7911c2307ee8f8d4940bdcfb8bd21608f14203a83b651fcd7868bce377a5
MD5 62a23e4aca6d39c5adc9ec1c0c6cc3e1
BLAKE2b-256 3fc0cd0e6fe28a57f4b67164092ed6f3901c2d1facc6c36cddd639ec0dca2760

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cbor2-5.4.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0b80a4a4fca830af3d3cf36b725c31f0a98106e9c2b02004ab73b0ec7f139446
MD5 c5dc6742af9e76880c1fe50a96f6470f
BLAKE2b-256 a5698ac4941e6b9de9a9333778fd4796f49d6d0b6e1115a6af2e58e548eac28a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cbor2-5.4.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 7ecc4e9c548282a5d296d4535244efa69c7f67cda959f28e14929cf1d6af8a97
MD5 48d1e46601089454fc20ed3dc346a89f
BLAKE2b-256 cb993cb44e127ef32e73d317a4b398ade8ba09c499bb49f264606388b9635c2d

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