Marshmallow: Simplifying Python object serialization

Source: Internet
Author: User
Tags object serialization

Reprint: http://www.thinksaas.cn/topics/0/594/594368.html

Marshmallow-a lightweight library for turning complex objects into simple Python data types. Or from a simple Python data type into a complex object.

From datetime import datefrom Marshmallow Import schema, fields, Pprintclass 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, () schema = Albumschema () result = Schema.dump (album) Pprint (Result.data, indent=2) # {' Artist ': {' name ': ' David Bowie '},#   ' release_date ': ' 1971-12-17 ', #   ' title ': ' Hunky Dory '}

In short, marshmallow schemas can is 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 is rendered to standard formats such as JSON for use in an HTTP API.
Get It Now
$ pip install-u Marshmallow

Documentation

Full documentation are available at http://marshmallow.readthedocs.org/.

Requirements
    • Python >= 2.6 or >= 3.3

Marshmallow have no external dependencies outside of the Python standard library, although Python-dateutil is recommended F or robust datetime deserialization.

Ecosystem

A List of marshmallow-related libraries can be found on the GitHub wiki here:

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

Project Links
    • docs:http://marshmallow.readthedocs.org/
    • Changelog:http://marshmallow.readthedocs.org/en/latest/changelog.html
    • Pypi:https://pypi.python.org/pypi/marshmallow
    • Issues:https://github.com/marshmallow-code/marshmallow/issues

License

MIT licensed. See the bundled LICENSE file for more details.


Project Address: Https://github.com/marshmallow-code/marshmallow

Marshmallow: Simplifying Python object serialization

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.