CBOR (de)serializer with extensive tag support
Project description
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.8 (or PyPy3 3.8+)
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
Command-line Usage
The provided command line tool (cbor2) 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.
The tool can alternatively be invoked with python -m cbor2.tool.
Usage:
# Pass hexadecimal through xxd. $ echo a16568656c6c6f65776f726c64 | xxd -r -ps | cbor2 --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 | cbor2 -d --sequence [1, 2] [3, 4] [5, 6]
Multiple files can also be sent to a single output file:
$ cbor2 -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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for cbor2-5.6.3-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18b3dee4eddde9761c60298ce21c0cd4e770237978034c5ee1d4242e255683ec |
|
MD5 | 3ddf165d067271eeb3c0f230493a04cd |
|
BLAKE2b-256 | 13564c7072e612487ea24dddf1e41bb79138bc141b645849a259a211e96cf1c0 |
Hashes for cbor2-5.6.3-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea4a0412426155c3b78763449db56cf5c72c48788a37d7e60bd66c844b9c8634 |
|
MD5 | da98dbd3524bbdf19c4f45c810b44842 |
|
BLAKE2b-256 | 0e22cc03622affd861b977d6641e68f0416065b3fef4d1d4ac615169b6a7568e |
Hashes for cbor2-5.6.3-cp312-cp312-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | adc87485ffd7a4dad481e08e6819eebfcfbafc0918fffcca47aee4cdf8c6de04 |
|
MD5 | 1d64cd78ca73ae8b7596811f74b7b9bd |
|
BLAKE2b-256 | e231f832968bf9540a84b38dc7ba00279e838081d6f5ccc06959ef6d2502281b |
Hashes for cbor2-5.6.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | add01e4b4663199940d10f8c8e1d926e70823d1b2f3f981cc097a4764125f110 |
|
MD5 | 35f5eeccf85475bde49b207c8b2f4da1 |
|
BLAKE2b-256 | b61c7cdf2585d34481627689324136a1ec1a10f2d1091f940d82902912bc49c8 |
Hashes for cbor2-5.6.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 277997127402710a3abdf4372ac75e8f8bb2e75a303cd789312e515c8ef657dd |
|
MD5 | eb54c00c949316c6ed84b1272805d3a2 |
|
BLAKE2b-256 | 70c2ab9b6a77a8c46fa09acd68d684a9d86580f60c5f407fb167d8a375d0fb83 |
Hashes for cbor2-5.6.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1e5181d4f858237ab4e1a28e21bdcaf31dab2657ab60a8d4a0701a078fe5926 |
|
MD5 | c1178c7018918fb7dc4fc2111d9ed1da |
|
BLAKE2b-256 | bb1065d69300202f95752c36362a087112e35514e005778526e746dac8e3823d |
Hashes for cbor2-5.6.3-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9eaec8c04618124a6b597fe4471035cb7cb0d5114f43aaf2062821ad480ef57c |
|
MD5 | 4577996e00dfb19c2ebe477c6411e37e |
|
BLAKE2b-256 | 813966c063e9799167aea1a585d60efa8762de57200d362e5a88de4382fe2cc7 |
Hashes for cbor2-5.6.3-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0c915db92b441f505f8a14a521c9461439ac8e5d959454845eb92f93db0bb3b |
|
MD5 | 2a23889bc532ca36e67c90f4d90e6568 |
|
BLAKE2b-256 | 4bf2cf932a74258a660ec185d94d6e9d081fcca82bf2638d4c9c38a2f85438b9 |
Hashes for cbor2-5.6.3-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 193d1abdffd52893710d39389daa5c03e1569421cdf53585a28033689aef7aec |
|
MD5 | a12ebe9ea3dffbfb25cb9b0b8d459820 |
|
BLAKE2b-256 | 48433133a2fa4497b74c48a979e0cb7040d8cf9cdb0f274bd2add732eed37805 |
Hashes for cbor2-5.6.3-cp311-cp311-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | acb93292843aa72768f089a135bfeec4c9b745132e8dc22f1b149490fc77cb0a |
|
MD5 | cea6419b9e9c85d89b8e666d5ce8366d |
|
BLAKE2b-256 | 82b5e4299de1d4aed5f244a9e11d2783d95ecaad0a2883542b1fdd77486d09df |
Hashes for cbor2-5.6.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3af60ac82a733bfdfb2b1079c850fefea2621bdb8c8f87f4c5d12802d48a8c55 |
|
MD5 | 19b9bc3a7fd94661768c5706a63788fc |
|
BLAKE2b-256 | b223e5b21da8d418bb5b693e3e8e69cbcf28d0639d2c1d8ca642951944acfe84 |
Hashes for cbor2-5.6.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c66d4c227c2ed6c63ec5c2d50eb8ec0e1c41c07b452a867544e48ca41d4f0b64 |
|
MD5 | 801f3b26d08f284d15ce115aacb0eb14 |
|
BLAKE2b-256 | 10fbb2874b196486d163001a198b54ed8f7fe883b4d5fbd56a5c5d70809d091e |
Hashes for cbor2-5.6.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fc063843c14e9e95181faf8d807a53c958d77bb9d360eb4f2344d075ecfed36 |
|
MD5 | b0651dbdd8466c8a6cce03868edf30cd |
|
BLAKE2b-256 | 49c6782ca089765566bc5418ecbe4dab60c3d37854d342d528dbf056e1d1eaad |
Hashes for cbor2-5.6.3-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b07ee755ae5b0dfad608dab37364b35895cab5d1222653da1fea32a10330c4b0 |
|
MD5 | d8fbb4368ec369e13703458963afaa97 |
|
BLAKE2b-256 | be86c2f4376fb6a5c76e1a48410010e665d9268fb48739414941ce473e615e2e |
Hashes for cbor2-5.6.3-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca15be7142e861fb9f918e0248620b4d4153b9ff14ef6034f7204db5db2924a1 |
|
MD5 | 5e35e5c3419b5d4eb4c21d687459a842 |
|
BLAKE2b-256 | 4ce179ddd20e779a49524ddd74d9655c5c399b88b7c793339bddd27415ff82d5 |
Hashes for cbor2-5.6.3-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23847075ce1bcda871c7698e5db0635685995ae470098a5e4c9a26c00f65f21a |
|
MD5 | 4ee061fd4eaa9a8f0fc664a53a8773a1 |
|
BLAKE2b-256 | a75c792e2b4ef9f21e42038e119a7fb67196e7094ded49e297c63d5314179dc8 |
Hashes for cbor2-5.6.3-cp310-cp310-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b7636d39de203ee30ac13575ed3e9a0510e993fa1671022b84b9e35e369825f |
|
MD5 | 60d7a8962c0fa56468eb4a05bb46f088 |
|
BLAKE2b-256 | 61fb869368b929497aaca27765deab6605afc83a0df5213e10b4a61bbf6200eb |
Hashes for cbor2-5.6.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a3cf6b339a005031e4b8c79b9541856e3b0077ea4c33d7bb6a019885136f53a |
|
MD5 | 4c2dc5f0107d8c054f5937b350acfa7a |
|
BLAKE2b-256 | a00ac23585215cee2e7174e22b0b6d0952cfd4c4a9dc76c167455d963dc21841 |
Hashes for cbor2-5.6.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14561038b8eaab3fd5e867f09bc43f7525a1405e41ade14066925ea3d42513a8 |
|
MD5 | 657c3ebd36ceeaa9309c6cb70a64ff20 |
|
BLAKE2b-256 | c7a944b1fee137ba4ef94e0391f7fc54b677b8ac9b0b2397d82cd5879f23eda0 |
Hashes for cbor2-5.6.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eda6965cca276d4c2cebdbee14572dec65b991c5359fc32a793f03f052e35985 |
|
MD5 | 96d1f1566ffac6c4f099641125ca2c38 |
|
BLAKE2b-256 | 54c3054d3cd3724d5c0b2dcdfb2852be7f38fec64825264e42686befaac98f8d |
Hashes for cbor2-5.6.3-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0201d5e8d9ad1557aeb50d35b907c0f170de0ae9ebb484b2894bcee3b2e13b80 |
|
MD5 | de27408002c0bfb5d5e9b292e82d7de1 |
|
BLAKE2b-256 | 6db3762738a2b7a9a2ae79f3d38bfe95309a10eed02bc01dfffa2a35546daa9e |
Hashes for cbor2-5.6.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2aba8b75e36c9f84a42a7026271da8fd759035a871c1b799028439059527276b |
|
MD5 | 82103d26133b58913d940882a323d2db |
|
BLAKE2b-256 | e4470826f48df153c2b5e38bf60aa91dab365b2c1fb428f8870cde57fd8d85bd |
Hashes for cbor2-5.6.3-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6081c1ab9791d5973a40b95ecb8b04b0fbf9fc04be170d89a3ad77d5964f52d5 |
|
MD5 | 56dbc6ddcd449cfc2ca7adcf9d188341 |
|
BLAKE2b-256 | 9412576404065bb50182eae6aa25b6c45057d80c44c7736a59a95a638fae4bc1 |
Hashes for cbor2-5.6.3-cp39-cp39-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3ec251db32516d383fc587874b15f4b5fb4e9049d9436b8696f5767b11c149b |
|
MD5 | 68de62154eb841d171ffdecbca9a136e |
|
BLAKE2b-256 | d6456a877cd34af8da085c9a80f3977c8ee41af7ffabfea7b067f69e90d48e08 |
Hashes for cbor2-5.6.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7693e53c3ba0b2ad4e46b610f8d69159ffdbcb6ebe75ea1c1f5f40c3283639ca |
|
MD5 | 2dc1573f4ff1019c9f18aaceba920526 |
|
BLAKE2b-256 | 2043da0bd6554f3f48af9e820c2894a078c081dd5cc0dc2bbc8fd6ab6362c1ca |
Hashes for cbor2-5.6.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f0e95011ae8460265ef348fe380664fa22c51015fd52344ebd781579fa9552a |
|
MD5 | 6cc02b786101be41a443f7aa9bfae17a |
|
BLAKE2b-256 | f051dc954364856dff150612d33efea1f5ce64d70c7baa65d07c17a59ac143e6 |
Hashes for cbor2-5.6.3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b7755b93d32638f4d79a0fa0744b423787f6faa3c96ccccac68b6dbf1848368 |
|
MD5 | b5a904b0bc9b11d6e6dc758dcb8f2c5f |
|
BLAKE2b-256 | c509bc3a57870e6861395c72f48fae6dcd440de842c2c3809139a68985ef34bd |
Hashes for cbor2-5.6.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81e619a2a59ae966cedb5fd3ea8a9487a3d4430824bbeacdcf5f74ad6112cc57 |
|
MD5 | 65a091549ca35c6c7739db8994762eb8 |
|
BLAKE2b-256 | de9205769fa047a6b436498a1f76f78f537981a437ad064c6279f18c55829775 |
Hashes for cbor2-5.6.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33efbe7103bac090430d291fca2fe1c444b0ec55c4716e8051b72a81377e8b79 |
|
MD5 | c97b5eb7d0f80eb0fbc9a1e6265106bb |
|
BLAKE2b-256 | a98355c91c30ff1a5b5e50d85e33289ed75046878543790d2f8a6e593433d451 |
Hashes for cbor2-5.6.3-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d4f95a567e26d8d9d62db234cd089525c52f19e7fdd59152629d9f03bd94b4f |
|
MD5 | 015dae7fce0cdef6908bdd58f4b246f9 |
|
BLAKE2b-256 | c433bbc70822a636e1087a503ea1c50e8ba4405c06016a13d8fbd1d4666ea950 |
Hashes for cbor2-5.6.3-cp38-cp38-musllinux_1_1_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3d2902e1aed155d56cdcae99cd4a9dae843e3fff6978148d2d5d5f9a0b986cd |
|
MD5 | 8a2459a8af0451d98d3c733b0671a475 |
|
BLAKE2b-256 | bd9d0288ba43133909f537f865f052288267f9ef2ea57b6af81f1da0a2ad1bd6 |
Hashes for cbor2-5.6.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64ea120206f82492a4385bbc5e2639f9b67c8bc7bdc57bffcbe9a8fee8cd6342 |
|
MD5 | 42310549035e5e6164f12c48a7daa322 |
|
BLAKE2b-256 | c8753c1a130442ccffbc5e6642f2899ffd835859c300cefe48b513799e4b0c07 |
Hashes for cbor2-5.6.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7be74f2cbda547fdd57c83ee5b3470804f02c660db28efcf9d4016f001b66f40 |
|
MD5 | 36233bbbb4eae7cc49b5a144d9d1545c |
|
BLAKE2b-256 | 9901c36b3c0dbacb2fb57f0abe62126a8b80b99bf0e39b197e36b97ae1dfbcfd |
Hashes for cbor2-5.6.3-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac6f10b9d25f2d61c036f86238bf23e3ea0253f98faa8ab00f67228bf3c0ce2a |
|
MD5 | 1de5c7b3b762d32399b7f39fa643f96c |
|
BLAKE2b-256 | 33955c97dc63e5ac30b22422e442d306678f56822de2397b4718d69fae752a12 |
Hashes for cbor2-5.6.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff6fd1c54b97ee322c0b7180092305ca3b012ff78fddadad97b33490f5f8881f |
|
MD5 | 3bba2d7aa668b92f09f6511e62978f70 |
|
BLAKE2b-256 | f74fe3b6323a60cdd45c162a6b68ba3132c7115691eb93fe3dc47c8d50da2d72 |