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.5-cp313-cp313-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54c72a3207bb2d4480c2c39dad12d7971ce0853a99e3f9b8d559ce6eac84f66f |
|
MD5 | 1542dc0dcca9eb0147704793a4324cce |
|
BLAKE2b-256 | a8cd793dc041395609f5dd1edfdf0aecde504dc0fd35ed67eb3b2db79fb8ef4d |
Hashes for cbor2-5.6.5-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ce13a27ef8fddf643fc17a753fe34aa72b251d03c23da6a560c005dc171085b |
|
MD5 | d2ae0038440c8b400b57cdde1fdea1ea |
|
BLAKE2b-256 | 77cb9b4f7890325eaa374c21fcccfee61a099ccb9ea0bc0f606acf7495f9568c |
Hashes for cbor2-5.6.5-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f91e6d74fa6917df31f8757fdd0e154203b0dd0609ec53eb957016a2b474896a |
|
MD5 | 27f916e59fa6a706cd544649f5ea3c39 |
|
BLAKE2b-256 | f48d0d5ad3467f70578b032b3f52eb0f01f0327d5ae6b1f9e7d4d4e01a73aa95 |
Hashes for cbor2-5.6.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f6d69f38f7d788b04c09ef2b06747536624b452b3c8b371ab78ad43b0296fab |
|
MD5 | aee8c44e7ba1acbc13f29b18922d0605 |
|
BLAKE2b-256 | 6404f64bda3eea649fe6644c59f13d0e1f4666d975ce305cadf13835233b2a26 |
Hashes for cbor2-5.6.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97a7e409b864fecf68b2ace8978eb5df1738799a333ec3ea2b9597bfcdd6d7d2 |
|
MD5 | b2e9e05752ab46561b93ed89832c44f6 |
|
BLAKE2b-256 | 5c3fe16a1e29994483c751b714cdf61d2956290b0b30e94690fa714a9f155c5c |
Hashes for cbor2-5.6.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61ceb77e6aa25c11c814d4fe8ec9e3bac0094a1f5bd8a2a8c95694596ea01e08 |
|
MD5 | 513927b7bce33ea0b4737cf276f6e596 |
|
BLAKE2b-256 | 8483cb941d4fd10e4696b2c0f6fb2e3056d9a296e5765b2000a69e29a507f819 |
Hashes for cbor2-5.6.5-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0d0a9c5aabd48ecb17acf56004a7542a0b8d8212be52f3102b8218284bd881e |
|
MD5 | 76148884a62d692a7b2175b1d3584ab0 |
|
BLAKE2b-256 | 2b6977e93caae71d1baee927c9762e702c464715d88073133052c74ecc9d37d4 |
Hashes for cbor2-5.6.5-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3ac50485cf67dfaab170a3e7b527630e93cb0a6af8cdaa403054215dff93adf |
|
MD5 | 1f7394aab5ba5f3f66421bc3a091c49f |
|
BLAKE2b-256 | 10183866693a87c90cb12f7942e791d0f03a40ba44887dde7b7fc85319647efe |
Hashes for cbor2-5.6.5-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2764804ffb6553283fc4afb10a280715905a4cea4d6dc7c90d3e89c4a93bc8d |
|
MD5 | 8f38271a9b563998c305d55f55ba4518 |
|
BLAKE2b-256 | a89c76b11a5ea7548bccb0dfef3e8fb3ede48bfeb39348f0c217519e0c40d33a |
Hashes for cbor2-5.6.5-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae2b49226224e92851c333b91d83292ec62eba53a19c68a79890ce35f1230d70 |
|
MD5 | 5a16c4ebca01a9dfca898a981dc63967 |
|
BLAKE2b-256 | f19008800367e920aef31b93bd7b0cd6fadcb3a3f2243f4ed77a0d1c76f22b99 |
Hashes for cbor2-5.6.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38886c41bebcd7dca57739439455bce759f1e4c551b511f618b8e9c1295b431b |
|
MD5 | 38daf70ef5d220097b2f8e2d1e89b819 |
|
BLAKE2b-256 | cfcb70751377d94112001d46c311b5c40b45f34863dfa78a6bc71b71f40c8c7f |
Hashes for cbor2-5.6.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8947c102cac79d049eadbd5e2ffb8189952890df7cbc3ee262bbc2f95b011a9 |
|
MD5 | 45ef27a2127b4830bca9ee2078e35114 |
|
BLAKE2b-256 | 77ac5fb79db6e882ec29680f4a974d35c098020a1b4709cad077667a8c3f4676 |
Hashes for cbor2-5.6.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fde21ac1cf29336a31615a2c469a9cb03cf0add3ae480672d4d38cda467d07fc |
|
MD5 | a66de6e89a35b038f840452677385c98 |
|
BLAKE2b-256 | f2d6f63a840c68fed4de67d5441947af2dc695152cc488bb0e57312832fb923a |
Hashes for cbor2-5.6.5-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e25c2aebc9db99af7190e2261168cdde8ed3d639ca06868e4f477cf3a228a8e9 |
|
MD5 | f11762700beda9c821ffc9ad9332168f |
|
BLAKE2b-256 | 57af84ced14c541451696825b7b8ccbb7668f688372ad8ee74aaca4311e79672 |
Hashes for cbor2-5.6.5-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e14a1bf6269d25e02ef1d4008e0ce8880aa271d7c6b4c329dba48645764f60e |
|
MD5 | 1c6936ed28505cf919399465dcc0654d |
|
BLAKE2b-256 | 6f76478c12193de9517ce691bb8a3f7c00eafdd6a1bc3f7f23282ecdd99d02ec |
Hashes for cbor2-5.6.5-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73b9647eed1493097db6aad61e03d8f1252080ee041a1755de18000dd2c05f37 |
|
MD5 | 494ada14b2033670db52ab3d7273b6ee |
|
BLAKE2b-256 | b21e12d887fb1a8227a16181eeec5d43057e251204626d73e1c20a77046ac1b1 |
Hashes for cbor2-5.6.5-cp311-cp311-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6797b824b26a30794f2b169c0575301ca9b74ae99064e71d16e6ba0c9057de51 |
|
MD5 | 266dbac57757cfea39e860760bdd2529 |
|
BLAKE2b-256 | 3875ebfdbb281104b46419fe7cb65979de9927b75acebcb6afa0af291f728cd2 |
Hashes for cbor2-5.6.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34cf5ab0dc310c3d0196caa6ae062dc09f6c242e2544bea01691fe60c0230596 |
|
MD5 | 662b9215e5edf83d645e5fd6c3717d41 |
|
BLAKE2b-256 | e184e177d9bef4749d14f31c513b25e341ac84e403e2ffa2bde562eac9e6184b |
Hashes for cbor2-5.6.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4c7dbcdc59ea7f5a745d3e30ee5e6b6ff5ce7ac244aa3de6786391b10027bb3 |
|
MD5 | ff61a3469394f9aa7f46670a52516e47 |
|
BLAKE2b-256 | 0f1e2010f6d02dd117df88df64baf3eeca6aa6614cc81bdd6bfabf615889cf1f |
Hashes for cbor2-5.6.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cff06464b8f4ca6eb9abcba67bda8f8334a058abc01005c8e616728c387ad32 |
|
MD5 | ed7e34530b18529f2a12c52b16ada4f9 |
|
BLAKE2b-256 | 41205a9d93f86b1e8fd9d9db33aff39c0e3a8459e0803ec24bd837d8b56d4a1d |
Hashes for cbor2-5.6.5-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 863e0983989d56d5071270790e7ed8ddbda88c9e5288efdb759aba2efee670bc |
|
MD5 | e0095b2723bbbfe3c6d3203f29b843f6 |
|
BLAKE2b-256 | bdb7ef045245180510305648fd604244d3bb1ecf1b20de68f42ab5bc20198024 |
Hashes for cbor2-5.6.5-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b856fda4c50c5bc73ed3664e64211fa4f015970ed7a15a4d6361bd48462feaf |
|
MD5 | 3d7719a0226cdbef54ff27e1ce60395c |
|
BLAKE2b-256 | 2055bd657fdedb0d046762f9bf567b262b233175995d40302cdaa71d9aadcec8 |
Hashes for cbor2-5.6.5-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 559dcf0d897260a9e95e7b43556a62253e84550b77147a1ad4d2c389a2a30192 |
|
MD5 | 197edf9b9b0980c2575ed9999d91e0de |
|
BLAKE2b-256 | b2d527eced2cee4725bb876875f26d659063e2b7750d0dfb7572f451b569c4d1 |
Hashes for cbor2-5.6.5-cp310-cp310-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47261f54a024839ec649b950013c4de5b5f521afe592a2688eebbe22430df1dc |
|
MD5 | 69651283463ba33bdf19a4ab198954ce |
|
BLAKE2b-256 | 0bba5c07b001bb26bd91d96e4b3b720676a909e1acdbaf7d250a47c5d7a5a0f7 |
Hashes for cbor2-5.6.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9d15b638539b68aa5d5eacc56099b4543a38b2d2c896055dccf7e83d24b7955 |
|
MD5 | 3f2d0822cf7f5f976ef3e2875e369db1 |
|
BLAKE2b-256 | bb41debb6f35d240caa8078a4a27c03e7eed09737575c564d619e1ee0e829616 |
Hashes for cbor2-5.6.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a88f029522aec5425fc2f941b3df90da7688b6756bd3f0472ab886d21208acbd |
|
MD5 | fa64f381730dcecad7329df7f6f027ef |
|
BLAKE2b-256 | fa889b5fc312f21a10e048c348cead933e9f891cc09a295757957d8a5726641f |
Hashes for cbor2-5.6.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87026fc838370d69f23ed8572939bd71cea2b3f6c8f8bb8283f573374b4d7f33 |
|
MD5 | f9dd4e7d9fe958eec76610f067bbc88e |
|
BLAKE2b-256 | 62d833ec188eeff9c5e2e8ee8e214d15a0edf8fd001eefa01730e27834cfd410 |
Hashes for cbor2-5.6.5-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e16c4a87fc999b4926f5c8f6c696b0d251b4745bc40f6c5aee51d69b30b15ca2 |
|
MD5 | 2335a7c1793e656f3ccc9b630db7db4f |
|
BLAKE2b-256 | f1f2eada1d3fcaeddbd0f9a25381eed6b150f2858cf615d33ef7c14f9f86218a |
Hashes for cbor2-5.6.5-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a34ee99e86b17444ecbe96d54d909dd1a20e2da9f814ae91b8b71cf1ee2a95e4 |
|
MD5 | 3354e22c59f601b44e8e3de04dcd6106 |
|
BLAKE2b-256 | c722d0c40558aa227b44b3cd80d313cee76dc36779cba3bdb7307ef9743c6322 |
Hashes for cbor2-5.6.5-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7488aec919f8408f9987a3a32760bd385d8628b23a35477917aa3923ff6ad45f |
|
MD5 | a7b451f3034498bca95e0ed68bdec3f1 |
|
BLAKE2b-256 | f7f88febf9a0073f617b23c97fce819a6878c7310c40482c55a411a6075ed327 |
Hashes for cbor2-5.6.5-cp39-cp39-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 824f202b556fc204e2e9a67d6d6d624e150fbd791278ccfee24e68caec578afd |
|
MD5 | be4e977d3b6bbe47f866d3841fe87349 |
|
BLAKE2b-256 | 98fa9c83eae3b45428f76444b23919ed8cd922d37d3281a953a8b41268a85d7b |
Hashes for cbor2-5.6.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa61a02995f3a996c03884cf1a0b5733f88cbfd7fa0e34944bf678d4227ee712 |
|
MD5 | a74f1e04bb379e597d0654cae79b1249 |
|
BLAKE2b-256 | 942298eec0f27e0dec07222fcbf31f276631b8224c69ac979836cf3c184d9d6d |
Hashes for cbor2-5.6.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66dd25dd919cddb0b36f97f9ccfa51947882f064729e65e6bef17c28535dc459 |
|
MD5 | ff7515d652f9c03990ec3100a5bf097c |
|
BLAKE2b-256 | 972c1b08c060d1369113bbda8ba699effd049d7ef58ba9dc35dd6ba6b9fcccda |
Hashes for cbor2-5.6.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe11c2eb518c882cfbeed456e7a552e544893c17db66fe5d3230dbeaca6b615c |
|
MD5 | 8ba0d01f61354468f79b7543b3243b8d |
|
BLAKE2b-256 | 0defdbc6cd298cc96ec51fe71d4b15d3ddb30692071f86fdc2a65fdbdeadfb11 |
Hashes for cbor2-5.6.5-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94885903105eec66d7efb55f4ce9884fdc5a4d51f3bd75b6fedc68c5c251511b |
|
MD5 | 361465c05adfaeaea08f7026d98752a7 |
|
BLAKE2b-256 | acd2cf0f7357912c51a2e8405797093b8c50f4aba3b113344782bafd4910e403 |
Hashes for cbor2-5.6.5-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f747b7a9aaa58881a0c5b4cd4a9b8fb27eca984ed261a769b61de1f6b5bd1e6 |
|
MD5 | f49913510839ef635db524504da2ad72 |
|
BLAKE2b-256 | b443b1d235a841ec35066815fedc39c6f1317b06b17ce93bd599a540281963a0 |
Hashes for cbor2-5.6.5-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93676af02bd9a0b4a62c17c5b20f8e9c37b5019b1a24db70a2ee6cb770423568 |
|
MD5 | 8de4557c9f143e0b0a818db5feb3d735 |
|
BLAKE2b-256 | d24d4c11d6adfc1f5cd06f543a3b3a523d883f48ed8c4097c5feec38a617cb4b |
Hashes for cbor2-5.6.5-cp38-cp38-musllinux_1_2_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37096663a5a1c46a776aea44906cbe5fa3952f29f50f349179c00525d321c862 |
|
MD5 | ff21428c0ceba36b4974cb0c13e8e851 |
|
BLAKE2b-256 | 8b7b95f8930ad9e8299f4f8ba105f9d9ea840bc2f0403f349a062ae4f2267983 |
Hashes for cbor2-5.6.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90bfa36944caccec963e6ab7e01e64e31cc6664535dc06e6295ee3937c999cbb |
|
MD5 | 3eb3f4d94409c01387e9093b8657175f |
|
BLAKE2b-256 | a03bb58d95dff6c8b1dd150451356fadac8294f1b8e73124863d7b9abb03a359 |
Hashes for cbor2-5.6.5-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a83b76367d1c3e69facbcb8cdf65ed6948678e72f433137b41d27458aa2a40cb |
|
MD5 | 9551aa4a4ac9f342aedf8e2717eb453d |
|
BLAKE2b-256 | c20bd55db4214f093a966d31e4a4ee737fbf02ea81c88fc7fc743612e62a4dea |
Hashes for cbor2-5.6.5-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d1a18b3a58dcd9b40ab55c726160d4a6b74868f2a35b71f9e726268b46dc6a2 |
|
MD5 | 462680b26db55da42092ee5b45fc1532 |
|
BLAKE2b-256 | 9668efca8d029f334e61767268e37184fb04138bd9e0b1d55b4512dd32c8ce8d |
Hashes for cbor2-5.6.5-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4586a4f65546243096e56a3f18f29d60752ee9204722377021b3119a03ed99ff |
|
MD5 | 5d7fdc8fe0f2988bcc5e699b4dd187d2 |
|
BLAKE2b-256 | cce4f33809edd874dc16edce3929abc4830d9d703894b265b77581035f12d362 |