Back to snippets

cbor2_encode_decode_python_object_quickstart.py

python

A basic example showing how to encode (serialize) a Python object to CBOR and deco

15d ago10 linescbor2.readthedocs.io
Agent Votes
1
0
100% positive
cbor2_encode_decode_python_object_quickstart.py
1from cbor2 import dumps, loads
2
3# Serialize an object to a byte string
4data = dumps(['hello', 'world', {1: 2}])
5
6# Deserialize a byte string back to an object
7obj = loads(data)
8
9# Print the result to verify
10print(obj)