pycborstream
Simple python API to handle CBOR files as streams. It provides lazy methods to read and write huge CBOR data files saving memory: data can be treated on the fly without having to load the entire structure.
Pycborstream mimics the C++ QCborStreamReader Class and QCborStreamWriter Class API to read and write CBOR data. It uses cbor2 under the hood, and combines it to also read/write directly python dictionnaries and arrays.
Simple usage: write a CBOR data file
from io import BytesIO
from pycborstream import CborStreamEnc
cbor_out = "data.cbor"
with open(cbor_out, "wb") as fp:
cbor_encoder = CborStreamEnc(fp)
cbor_encoder.startMap(2) # start a map containing 2 key/value pairs
cbor_encoder.append("first_key")
cbor_encoder.startArray(None) # start an array of undefined length
cbor_encoder.append(5)
cbor_encoder.append(6)
cbor_encoder.append(7)
cbor_encoder.endArray()
cbor_encoder.append("second_key")
cbor_encoder.append("could be a new map or whatever")
cbor_encoder.endMap()
Simple usage: read this CBOR data file
from io import BytesIO
from pycborstream import CborStreamDec
with open(cbor_out, "rb") as fp:
cbor_decoder = CborStreamDec(fp)
cbor_decoder.enter_container() # enters the map (containing 2 keys)
assert cbor_decoder.value() == "first_key"
assert cbor_decoder.is_array() # next value is an array
assert cbor_decoder.length == None # length of array is not known
cbor_decoder.enter_container()
while cbor_decoder.has_next(): # loop on elements in the array
print(cbor_decoder.value())
cbor_decoder.leave_container() # we have to leave container to proceed
assert cbor_decoder.value() == "second_key"
assert cbor_decoder.value() == "could be a new map or whatever"
Metadata
Release files for pycborstream 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pycborstream-0.0.5.tar.gz | 17.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pycborstream-0.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.5 kB
Release files / pycborstream-0.0.5.tar.gz
| Download URL | pycborstream-0.0.5.tar.gz |
|---|---|
| Size | 17.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6d2cd236685fc262ad7c082f6781f4381fa19e072ab2d3e69c783378c738c001
|
|
BLAKE2b-256 checksum How to use checksums |
8ab6b6b67a7234b02df1fedfa60de0d9833a90a0cc8c0dae9481a23611ba6caa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / pycborstream-0.0.5-py3-none-any.whl
| Download URL | pycborstream-0.0.5-py3-none-any.whl |
|---|---|
| Size | 20.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9345a1834492e75e13ddf68d564a0917865043e220ff27c1a6e1e2edffde7898
|
|
BLAKE2b-256 checksum How to use checksums |
e2b1ccb66d9f704b038d508d99c9fe27c2f72700427c4244b4a4b14908df06a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|