From the course: Effective Serialization with Python

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

msgpack serialization

msgpack serialization - Python Tutorial

From the course: Effective Serialization with Python

Start my 1-month free trial

msgpack serialization

- Msgpack is a schemaless binary format. You can think of it as a binary JSON. The lack of schema allows it to iterate quickly with message formats. Msgpack is not in the Python standard library. You can install it with the Python -m pip, then install and msgpack. Let's have a look at some code. We input msgpack, then we create default, which is a function for serializing datetime into msgpack and object hook, which is a function for deserializing from msgpack back to datetime. We define our metric, which has time, which is a datetime, name, which is a string, value, which is a float, and labels, which is another dictionary. Then we use the dumps function to dump the metric into bytes using our own default function and to load it back, we use the loads with our object hook function to get it back. If you work with files, you can use the dump and the load functions. If you run it, python metric.py. How much…

Contents