Python serialization libraries

Updated Nov 2026

Python serialization libraries convert Python objects into text or bytes, such as JSON, YAML, TOML, or a binary format, and load them back. A schema-based format generates message classes from a definition rather than encoding arbitrary values as they are. These libraries let services, configuration tools, and data pipelines store and exchange structured data.

Popularity

PyYAML has the most monthly downloads in this comparison, at 1.3B.

LibraryMonthly downloadsStarsLast releaseLicense
PyYAML
1.3B
3.0KSep 2025MIT
pydantic
1.2B
29.6KNov 2026MIT
protobuf
783.8M
72.2KSep 2026BSD-3-Clause
tomlkit
607.1M
871Oct 2026MIT
msgpack
234.9M
2.1KOct 2026Apache-2.0
orjson
223.6M
8.3KOct 2026MPL-2.0 AND (Apache-2.0 OR MIT)
cloudpickle
209.5M
2.0KNov 2026BSD-3-Clause
ruamel.yaml
182.8M
Not on GitHubJan 2026MIT
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Parses and emits YAML.

Downloads / mo
1.3B
Stars
3.0K
Last release
6.0.3
License
MIT

Quickstart

From __init__.py
$ pip install PyYAML
import yaml

text = yaml.safe_dump({"name": "Ada", "active": True})
print(text)

PyYAML examples

From open-source projects on GitHub

Validates data using Python type hints.

Downloads / mo
1.2B
Stars
29.6K
Last release
2.14.3
License
MIT

Quickstart

From README.md
$ pip install pydantic
from pydantic import BaseModel

class User(BaseModel):
    name: str

print(User(name="Ada").model_dump_json())

pydantic examples

From open-source projects on GitHub

Implements Protocol Buffers, Google's data interchange format.

Downloads / mo
783.8M
Stars
72.2K
Last release
7.36.2
License
BSD-3-Clause

Quickstart

From README.md
$ pip install protobuf
from google.protobuf.struct_pb2 import Struct

message = Struct()
message["name"] = "Ada"
payload = message.SerializeToString()

protobuf examples

From open-source projects on GitHub

Edits TOML and preserves its style.

Downloads / mo
607.1M
Stars
871
Last release
0.15.2
License
MIT

Quickstart

From README.md
$ pip install tomlkit
import tomlkit

document = tomlkit.document()
document["name"] = "Ada"
print(tomlkit.dumps(document))

tomlkit examples

From open-source projects on GitHub
def write_toml(self) -> None:
    assert (
        len(self._toml_paths) == 1
    ), "Will not write configs when more than one toml path was resolved. Found paths: " + str(
        self._toml_paths
    )
    with open(self._toml_paths[0], "w", encoding="utf-8") as f:
        tomlkit.dump(self._config_toml, f)

Encodes and decodes data using the MessagePack serialization format.

Downloads / mo
234.9M
Stars
2.1K
Last release
1.2.4
License
Apache-2.0

Strengths

  • Decodes multiple streamed objects. Use Unpacker with a stream or feed it successive byte buffers.
  • Supports custom data hooks. Pair a default encoder with object_hook to restore custom values.

Limitations

  • Default map keys are restricted. Use string or byte keys unless strict_map_key is disabled.
  • Arrays decode as lists. Set use_list=False to decode arrays as tuples.

Quickstart

From README.md
$ pip install msgpack
import msgpack

payload = msgpack.packb({"name": "Ada"})
print(msgpack.unpackb(payload))

msgpack examples

From open-source projects on GitHub

Encodes and decodes JSON with support for dataclasses, datetimes, and NumPy.

Downloads / mo
223.6M
Stars
8.3K
Last release
3.13.0
License
MPL-2.0 AND (Apache-2.0 OR MIT)

Quickstart

From README.md
$ pip install orjson
import orjson

payload = orjson.dumps({"name": "Ada"})
print(orjson.loads(payload))

orjson examples

From open-source projects on GitHub

Serializes Python functions and classes, including interactive definitions, by value.

Downloads / mo
209.5M
Stars
2.0K
Last release
3.1.3
License
BSD-3-Clause

Strengths

  • Serializes lambdas and interactive definitions. Transfer functions and classes defined in scripts, notebooks or interactive sessions.
  • Can include module definitions. Register a module for by-value serialization when imports will be unavailable.

Limitations

  • Python versions must match. Send objects only between the exact same Python version.
  • Long-term storage is unsupported. Use this serializer for object transfer rather than archival storage.

Quickstart

From README.md
$ pip install cloudpickle
import cloudpickle
import pickle

payload = cloudpickle.dumps(lambda value: value + 1)
restored = pickle.loads(payload)
print(restored(1))

cloudpickle examples

From open-source projects on GitHub

ruamel.yaml

Parses and emits YAML with round-trip preservation of comments, flow style, and key order.

Downloads / mo
182.8M
Last release
0.19.1
License
MIT

Quickstart

From README.md
$ pip install ruamel.yaml
import sys
from ruamel.yaml import YAML

yaml = YAML()
yaml.dump({"name": "Ada"}, sys.stdout)

FAQ

orjson suits JSON with dataclasses, datetimes, and NumPy arrays. ruamel.yaml suits YAML files whose comments must survive a round trip. msgpack suits compact binary messages. cloudpickle suits shipping Python functions between processes.

PyYAML is a YAML parser and emitter for Python. Loading and dumping objects does not preserve the comments in the original file.

orjson is a JSON library with support for dataclasses, datetimes, and NumPy arrays. It returns bytes rather than a string.

cloudpickle serializes Python functions and classes by value, including lambdas and interactive definitions. Loading may execute code. Only trusted data should be unpickled.

tomlkit edits TOML documents and preserves their comments, indentation, whitespace, and element order.

For coding agents

Found your serialization library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official