Give AlbumentationsX a star on GitHub — it powers this leaderboard

Star on GitHub

mashumaro

Fast and well tested serialization library

Downloads: 0 (30 days)

Description

<div align="center"> <img alt="logo" width="175" src="https://raw.githubusercontent.com/Fatal1ty/mashumaro/ac2f924591d488dbd9a776a6b1ae7dede2d8c73e/img/logo.svg">
Fast and well tested serialization library

Build Status Coverage Status Latest Version Python Version License

</div>

In Python, you often need to dump and load objects based on the schema you have. It can be a dataclass model, a list of third-party generic classes or whatever. Mashumaro not only lets you save and load things in different ways, but it also does it super quick.

Key features

  • 🚀 One of the fastest libraries
  • ☝️ Mature and time-tested
  • 👶 Easy to use out of the box
  • ⚙️ Highly customizable
  • 🎉 Built-in support for JSON, YAML, TOML, MessagePack
  • 📦 Built-in support for almost all Python types including typing-extensions
  • 📝 JSON Schema generation

Table of contents

Introduction

This library provides two fundamentally different approaches to converting your data to and from various formats. Each of them is useful in different situations:

  • Codecs
  • Mixins

Codecs are represented by a set of decoder / encoder classes and decode / encode functions for each supported format. You can use them to convert data of any python built-in and third-party type to JSON, YAML, TOML, MessagePack or a basic form accepted by other serialization formats. For example, you can convert a list of datetime objects to JSON array containing string-represented datetimes and vice versa.

Mixins are primarily for dataclass models. They are represented by mixin classes that add methods for converting to and from JSON, YAML, TOML, MessagePack or a basic form accepted by other serialization formats. If you have a root dataclass model, then it will be the easiest way to make it serializable. All you have to do is inherit a particular mixin class.

In addition to serialization functionality, this library also provides JSON Schema builder that can be used in places where interoperability matters.

Installation

Use pip to install:

$ pip install mashumaro

The current version of mashumaro supports Python versions 3.9 — 3.14.

It's not recommended to use any version of Python that has reached its end of life and is no longer receiving security updates or bug fixes from the Python development team. For convenience, there is a table below that outlines the last version of mashumaro that can be installed on unmaintained versions of Python.

Python VersionLast Version of mashumaroPython EOL
3.83.142024-10-07
3.73.9.12023-06-27
3.63.1.12021-12-23

Changelog

This project follows the principles of Semantic Versioning. Changelog is available on GitHub Releases page.

Supported data types

There is support for generic types from the standard typing module: