marshmallow

A lightweight library for converting complex datatypes to and from native Python datatypes.

200 个版本 Python >=3.10
安装
pip install marshmallow
poetry add marshmallow
pipenv install marshmallow
conda install marshmallow
描述

marshmallow: simplified object serialization


|pypi| |build-status| |pre-commit| |docs|

.. |pypi| image:: https://badgen.net/pypi/v/marshmallow :target: https://pypi.org/project/marshmallow/ :alt: Latest version

.. |build-status| image:: https://github.com/marshmallow-code/marshmallow/actions/workflows/build-release.yml/badge.svg :target: https://github.com/marshmallow-code/marshmallow/actions/workflows/build-release.yml :alt: Build status

.. |pre-commit| image:: https://results.pre-commit.ci/badge/github/marshmallow-code/marshmallow/dev.svg :target: https://results.pre-commit.ci/latest/github/marshmallow-code/marshmallow/dev :alt: pre-commit.ci status

.. |docs| image:: https://readthedocs.org/projects/marshmallow/badge/ :target: https://marshmallow.readthedocs.io/ :alt: Documentation

.. start elevator-pitch

marshmallow is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, to and from native Python datatypes.

.. code-block:: python

from datetime import date
from pprint import pprint

from marshmallow import Schema, fields


class ArtistSchema(Schema):
    name = fields.Str()


class AlbumSchema(Schema):
    title = fields.Str()
    release_date = fields.Date()
    artist = fields.Nested(ArtistSchema())


bowie = dict(name="David Bowie")
album = dict(artist=bowie, title="Hunky Dory", release_date=date(1971, 12, 17))

schema = AlbumSchema()
result = schema.dump(album)
pprint(result, indent=2)
# { 'artist': {'name': 'David Bowie'},
#   'release_date': '1971-12-17',
#   'title': 'Hunky Dory'}

In short, marshmallow schemas can be used to:

  • Validate input data.
  • Deserialize input data to app-level objects.
  • Serialize app-level objects to primitive Python types. The serialized objects can then be rendered to standard formats such as JSON for use in an HTTP API.

Get it now

.. code-block:: shell-session

$ pip install -U marshmallow

.. end elevator-pitch

Documentation

Full documentation is available at https://marshmallow.readthedocs.io/ .

Ecosystem

A list of marshmallow-related libraries can be found at the GitHub wiki here:

https://github.com/marshmallow-code/marshmallow/wiki/Ecosystem

Credits

Contributors

This project exists thanks to all the people who contribute.

You're highly encouraged to participate in marshmallow's development. Check out the Contributing Guidelines <https://marshmallow.readthedocs.io/en/latest/contributing.html>_ to see how you can help.

Thank you to all who have already contributed to marshmallow!

.. image:: https://opencollective.com/marshmallow/contributors.svg?width=890&button=false :target: https://marshmallow.readthedocs.io/en/latest/authors.html :alt: Contributors

Backers

If you find marshmallow useful, please consider supporting the team with a donation. Your donation helps move marshmallow forward.

Thank you to all our backers! [Become a backer_]

.. _Become a backer: https://opencollective.com/marshmallow#backer

.. image:: https://opencollective.com/marshmallow/backers.svg?width=890 :target: https://opencollective.com/marshmallow#backers :alt: Backers

Sponsors

.. start sponsors

marshmallow is sponsored by Route4Me <https://route4me.com>_.

.. image:: https://github.com/user-attachments/assets/018c2e23-032e-4a11-98da-8b6dc25b9054 :target: https://route4me.com :alt: Routing Planner

Support this project by becoming a sponsor (or ask your company to support this project by becoming a sponsor). Your logo will be displayed here with a link to your website. [Become a sponsor_]

.. _Become a sponsor: https://opencollective.com/marshmallow#sponsor

.. end sponsors

Professional Support

Professionally-supported marshmallow is now available through the Tidelift Subscription <https://tidelift.com/subscription/pkg/pypi-marshmallow?utm_source=pypi-marshmallow&utm_medium=readme>_.

Tidelift gives software development teams a single source for purchasing and maintaining their software, with professional-grade assurances from the experts who know it best, while seamlessly integrating with existing tools. [Get professional support_]

.. _Get professional support: https://tidelift.com/subscription/pkg/pypi-marshmallow?utm_source=marshmallow&utm_medium=referral&utm_campaign=github

.. image:: https://user-images.githubusercontent.com/2379650/45126032-50b69880-b13f-11e8-9c2c-abd16c433495.png :target: https://tidelift.com/subscription/pkg/pypi-marshmallow?utm_source=pypi-marshmallow&utm_medium=readme :alt: Get supported marshmallow with Tidelift

Project Links

License

MIT licensed. See the bundled LICENSE <https://github.com/marshmallow-code/marshmallow/blob/dev/LICENSE>_ file for more details.

版本列表
4.3.0 2026-04-03
4.2.4 2026-04-02
4.2.3 2026-03-25
4.2.2 2026-02-04
4.2.1 2026-01-23
4.2.0 2026-01-04
4.1.2 2025-12-22
4.1.1 2025-12-05
4.1.0 2025-11-01
4.0.1 2025-08-28
4.0.0 2025-04-17
3.26.2 2025-12-22
3.26.1 2025-02-03
3.26.0 2025-01-23
3.25.1 2025-01-11
3.25.0 2025-01-09
3.24.2 2025-01-08
3.24.1 2025-01-07
3.24.0 2025-01-06
3.23.3 2025-01-03
3.23.2 2024-12-19
3.23.1 2024-11-01
3.23.0 2024-10-17
3.22.0 2024-08-20
3.21.3 2024-06-06
3.21.2 2024-05-01
3.21.1 2024-03-04
3.21.0 2024-02-26
3.20.2 2024-01-09
3.20.1 2023-07-20
3.20.0 2023-07-20
3.19.0 2022-11-11
3.18.0 2022-09-15
3.17.1 2022-08-22
3.17.0 2022-06-26
3.16.0 2022-05-29
3.15.0 2022-03-12
3.14.1 2021-11-15
3.14.0 2021-10-17
3.13.0 2021-07-21
3.12.2 2021-07-06
3.12.1 2021-05-10
3.12.0 2021-05-10
3.11.1 2021-03-30
3.11.0 2021-03-28
3.10.0 2020-12-19
3.9.1 2020-11-08
3.9.0 2020-10-31
3.8.0 2020-09-16
3.7.1 2020-07-20
3.7.0 2020-07-09
3.6.1 2020-06-02
3.6.0 2020-05-08
3.5.2 2020-04-30
3.5.1 2020-03-05
3.5.0 2020-02-19
3.4.0 2020-02-02
3.3.0 2019-12-06
3.2.2 2019-11-04
3.2.1 2019-10-01
3.2.0 2019-09-17
3.1.1 2019-09-16
3.1.0 2019-09-15
3.0.5 2019-09-13
3.0.4 2019-09-12
3.0.3 2019-09-05
3.0.2 2019-09-04
3.0.1 2019-08-21
3.0.0 2019-08-18
3.0.0rc9 2019-07-31
3.0.0rc8 2019-07-04
3.0.0rc7 2019-06-15
3.0.0rc6 2019-05-05
3.0.0rc5 2019-03-30
3.0.0rc4 2019-02-08
3.0.0rc3 2019-01-14
3.0.0rc2 2019-01-03
3.0.0rc1 2018-11-30
3.0.0b9 2018-04-26
3.0.0b8 2018-03-24
3.0.0b7 2018-02-03
3.0.0b6 2018-01-12
3.0.0b5 2017-12-30
3.0.0b4 2017-10-23
3.0.0b3 2017-08-20
3.0.0b20 2018-11-02
3.0.0b2 2017-03-20
3.0.0b19 2018-10-25
3.0.0b18 2018-10-16
3.0.0b17 2018-10-13
3.0.0b16 2018-09-21
3.0.0b15 2018-09-19
3.0.0b14 2018-09-15
3.0.0b13 2018-08-04
3.0.0b12 2018-07-05
3.0.0b11 2018-05-20
3.0.0b10 2018-05-11
3.0.0b1 2017-03-10
3.0.0a1 2017-02-26
2.21.0 2020-03-05
2.20.5 2019-09-15
2.20.4 2019-09-12
2.20.3 2019-09-04
2.20.2 2019-08-20
2.20.1 2019-08-13
2.20.0 2019-08-10
2.19.5 2019-06-18
2.19.4 2019-06-17
2.19.3 2019-06-15
2.19.2 2019-03-30
2.19.1 2019-03-16
2.19.0 2019-03-08
2.18.1 2019-02-15
2.18.0 2019-01-14
2.17.0 2018-12-26
2.16.3 2018-11-02
2.16.2 2018-10-31
2.16.1 2018-10-23
2.16.0 2018-10-11
2.15.6 2018-09-21
2.15.5 2018-09-15
2.15.4 2018-08-04
2.15.3 2018-05-20
2.15.2 2018-05-11
2.15.1 2018-04-26
2.15.0 2017-12-02
2.14.0 2017-10-23
2.13.6 2017-08-16
2.13.5 2017-04-13
2.13.4 2017-03-20
2.13.3 2017-03-11
2.13.2 2017-03-10
2.13.1 2017-03-04
2.13.0 2017-02-18
2.12.2 2017-01-30
2.12.1 2017-01-24
2.12.0 2017-01-22
2.11.1 2017-01-08
2.11.0 2017-01-08
2.10.5 2016-12-20
2.10.4 2016-11-18
2.10.3 2016-10-02
2.10.2 2016-09-25
2.10.1 2016-09-15
2.10.0 2016-09-05
2.9.1 2016-07-22
2.9.0 2016-07-07
2.8.0 2016-06-24
2.7.3 2016-05-06
2.7.2 2016-04-28
2.7.1 2016-04-09
2.7.0 2016-04-04
2.6.1 2016-03-18
2.6.0 2016-02-02
2.5.0 2016-01-16
2.4.2 2015-12-09
2.4.1 2015-12-08
2.4.0 2015-12-06
2.3.0 2015-11-23
2.2.1 2015-11-12
2.2.0 2015-10-26
2.1.3 2015-10-18
2.1.2 2015-10-15
2.1.1 2015-10-08
2.1.0 2015-10-01
2.0.0 2015-09-25
2.0.0rc2 2015-09-16
2.0.0rc1 2015-09-14
2.0.0b5 2015-08-23
2.0.0b4 2015-07-08
2.0.0b3 2015-06-14
2.0.0b2 2015-05-03
2.0.0b1 2015-04-26
2.0.0a1 2015-04-25
1.2.6 2015-05-03
1.2.5 2015-04-25
1.2.4 2015-03-22
1.2.3 2015-03-16
1.2.2 2015-02-23
1.2.1 2015-01-11
1.2.0 2014-12-23
1.1.0 2014-12-03
1.0.1 2014-11-19
1.0.0-a 2014-10-19
1.0.0 2014-11-16
0.7.0 2014-06-22
0.6.0 2014-06-04
0.5.5 2014-05-03
0.5.4 2014-04-18
0.5.3 2014-03-03
0.5.2 2014-02-10
0.5.1 2014-02-03
0.5.0 2013-12-29
0.4.1 2013-12-02
0.4.0 2013-11-25
0.3.1 2013-11-16
0.3.0 2013-11-14
0.2.1 2013-11-12
0.2.0 2013-11-12
0.1.0 2013-11-11