Skip to main content
Help improve PyPI by participating in a 5-minute user interface survey!

A lightweight library for converting complex datatypes into native Python datatypes.

Project Description

Latest version Travis-CI

Homepage: http://marshmallow.rtfd.org/

marshmallow is an ORM/ODM/framework-agnostic library for converting complex datatypes, such as objects, into native Python datatypes. The serialized objects can then be rendered to standard formats such as JSON for use in a REST API.

from datetime import datetime
from marshmallow import Serializer, fields, pprint

# A "model"
class Person(object):
    def __init__(self, name):
        self.name = name
        self.date_born = datetime.now()

# A serializer
class PersonSerializer(Serializer):
    name = fields.String()
    date_born = fields.DateTime()

person = Person("Guido van Rossum")
serialized = PersonSerializer(person)
pprint(serialized.data)
# {"name": "Guido van Rossum", "date_born": "Sun, 10 Nov 2013 14:24:50 -0000"}

Get It Now

$ pip install -U marshmallow

Documentation

Full documentation is available at http://marshmallow.rtfd.org/ .

Requirements

  • Python >= 2.6 or >= 3.3

marshmallow has no external dependencies outside of the Python standard library.

License

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

Changelog

0.5.2 (2014-02-10)

  • Enable custom field validation via the validate parameter.
  • Add utils.from_rfc for parsing RFC datestring to Python datetime object.

0.5.1 (2014-02-02)

  • Avoid unnecessary attribute access in utils.to_marshallable_type for improved performance.
  • Fix RFC822 formatting for localized datetimes.

0.5.0 (2013-12-29)

  • Can customize validation error messages by passing the error parameter to a field.
  • Backwards-incompatible: Rename fields.NumberField -> fields.Number.
  • Add fields.Select. Thanks @ecarreras.
  • Support nesting a Serializer within itself by passing "self" into fields.Nested (only up to depth=1).
  • Backwards-incompatible: No implicit serializing of collections. Must set many=True if serializing to a list. This ensures that marshmallow handles singular objects correctly, even if they are iterable.
  • If Nested field only parameter is a field name, only return a single value for the nested object (instead of a dict) or a flat list of values.
  • Improved performance and stability.

0.4.1 (2013-12-01)

  • An object’s __marshallable__ method, if defined, takes precedence over __getitem__.
  • Generator expressions can be passed to a serializer.
  • Better support for serializing list-like collections (e.g. ORM querysets).
  • Other minor bugfixes.

0.4.0 (2013-11-24)

  • Add additional clas Meta option.
  • Add dateformat class Meta option.
  • Support for serializing UUID, date, time, and timedelta objects.
  • Remove Serializer.to_data method. Just use Serialize.data property.
  • String field defaults to empty string instead of None.
  • Backwards-incompatible: isoformat and rfcformat functions moved to utils.py.
  • Backwards-incompatible: Validation functions moved to validate.py.
  • Backwards-incompatible: Remove types.py.
  • Reorder parameters to DateTime field (first parameter is dateformat).
  • Ensure that to_json returns bytestrings.
  • Fix bug with including an object property in fields Meta option.
  • Fix bug with passing None to a serializer.

0.3.1 (2013-11-16)

  • Fix bug with serializing dictionaries.
  • Fix error raised when serializing empty list.
  • Add only and exclude parameters to Serializer constructor.
  • Add strict parameter and option: causes Serializer to raise an error if invalid data are passed in, rather than storing errors.
  • Updated Flask + SQLA example in docs.

0.3.0 (2013-11-14)

  • Declaring Serializers just got easier. The class Meta paradigm allows you to specify fields more concisely. Can specify fields and exclude options.
  • Allow date formats to be changed by passing format parameter to DateTime field constructor. Can either be "rfc" (default), "iso", or a date format string.
  • More useful error message when declaring fields as classes (instead of an instance, which is the correct usage).
  • Rename MarshallingException -> MarshallingError.
  • Rename marshmallow.core -> marshmallow.serializer.

0.2.1 (2013-11-12)

  • Allow prefixing field names.
  • Fix storing errors on Nested Serializers.
  • Python 2.6 support.

0.2.0 (2013-11-11)

  • Field-level validation.
  • Add fields.Method.
  • Add fields.Function.
  • Allow binding of extra data to a serialized object by passing the extra param when initializing a Serializer.
  • Add relative paramater to fields.Url that allows for relative URLs.

0.1.0 (2013-11-10)

  • First release.

Release history Release notifications

History Node

3.0.0b9

History Node

3.0.0b8

History Node

3.0.0b7

History Node

3.0.0b6

History Node

3.0.0b5

History Node

3.0.0b4

History Node

3.0.0b3

History Node

3.0.0b2

History Node

3.0.0b1

History Node

3.0.0a1

History Node

2.15.1

History Node

2.15.0

History Node

2.14.0

History Node

2.13.6

History Node

2.13.5

History Node

2.13.4

History Node

2.13.3

History Node

2.13.2

History Node

2.13.1

History Node

2.13.0

History Node

2.12.2

History Node

2.12.1

History Node

2.12.0

History Node

2.11.1

History Node

2.11.0

History Node

2.10.5

History Node

2.10.4

History Node

2.10.3

History Node

2.10.2

History Node

2.10.1

History Node

2.10.0

History Node

2.9.1

History Node

2.9.0

History Node

2.8.0

History Node

2.7.3

History Node

2.7.2

History Node

2.7.1

History Node

2.7.0

History Node

2.6.1

History Node

2.6.0

History Node

2.5.0

History Node

2.4.2

History Node

2.4.1

History Node

2.4.0

History Node

2.3.0

History Node

2.2.1

History Node

2.2.0

History Node

2.1.3

History Node

2.1.2

History Node

2.1.1

History Node

2.1.0

History Node

2.0.0

History Node

2.0.0rc2

History Node

2.0.0rc1

History Node

2.0.0b5

History Node

2.0.0b4

History Node

2.0.0b3

History Node

2.0.0b2

History Node

2.0.0b1

History Node

2.0.0a1

History Node

1.2.6

History Node

1.2.5

History Node

1.2.4

History Node

1.2.3

History Node

1.2.2

History Node

1.2.1

History Node

1.2.0

History Node

1.1.0

History Node

1.0.1

History Node

1.0.0

History Node

1.0.0-a

History Node

0.7.0

History Node

0.6.0

History Node

0.5.5

History Node

0.5.4

History Node

0.5.3

This version
History Node

0.5.2

History Node

0.5.1

History Node

0.5.0

History Node

0.4.1

History Node

0.4.0

History Node

0.3.1

History Node

0.3.0

History Node

0.2.1

History Node

0.2.0

History Node

0.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
marshmallow-0.5.2-py2.py3-none-any.whl (25.1 kB) Copy SHA256 hash SHA256 Wheel 2.7 Feb 10, 2014
marshmallow-0.5.2.tar.gz (20.3 kB) Copy SHA256 hash SHA256 Source None Feb 10, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page