{"id":442,"library":"marshmallow","title":"Marshmallow","description":"Marshmallow is a lightweight library for converting complex datatypes to and from native Python datatypes. The current version is 4.2.3, released on March 28, 2026. It follows a regular release cadence, with updates approximately every few months.","status":"active","version":"4.2.3","language":"python","source_language":"en","source_url":"https://github.com/marshmallow-code/marshmallow","tags":["serialization","deserialization","Python","ORM","ODM"],"install":[{"cmd":"pip install marshmallow","lang":"bash","label":"Install Marshmallow"}],"dependencies":[{"reason":"Recommended for robust datetime deserialization","package":"python-dateutil","optional":true}],"imports":[{"note":"Ensure correct import path to avoid ImportError.","symbol":"Schema","correct":"from marshmallow import Schema"},{"note":"Import fields from marshmallow to access various field types.","symbol":"fields","correct":"from marshmallow import fields"}],"quickstart":{"code":"from marshmallow import Schema, fields\n\nclass UserSchema(Schema):\n    name = fields.Str()\n    email = fields.Email()\n    created_at = fields.DateTime()\n\nuser_data = {\n    'name': 'Monty',\n    'email': 'monty@python.org',\n    'created_at': '2014-08-17T14:54:16.049594+00:00'\n}\n\nschema = UserSchema()\nresult = schema.load(user_data)\nprint(result)","lang":"python","description":"A simple example demonstrating how to define a schema and load data using Marshmallow."},"warnings":[{"fix":"Add 'ordered = True' in the Meta class of your schema.","message":"In Marshmallow 4.x, the 'load' method now returns a dictionary instead of an OrderedDict by default. To maintain the previous behavior, set the 'ordered' option to True in the schema's Meta class.","severity":"breaking","affected_versions":"4.x"},{"fix":"Add 'unknown = INCLUDE' in the Meta class of your schema to include unknown fields.","message":"The 'load' method in Marshmallow 4.x raises a ValidationError if it encounters unknown fields by default. To change this behavior, set the 'unknown' option in the schema's Meta class.","severity":"gotcha","affected_versions":"4.x"}],"env_vars":null,"last_verified":"2026-05-12T13:51:04.616Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"To fix this, either define the 'unknown' option in your Schema's `Meta` class to `EXCLUDE` or `INCLUDE`, or ensure your input data only contains fields explicitly defined in the schema.","cause":"This error occurs when the input data contains fields that are not defined in the Marshmallow schema.","error":"marshmallow.exceptions.ValidationError: {'field_name': ['Unknown field.']}"},{"fix":"Ensure that all fields marked as `required=True` in your schema are present in the data being loaded.","cause":"This error indicates that a required field, explicitly marked with `required=True` in your Marshmallow schema, was not provided in the input data during deserialization (`load` method).","error":"marshmallow.exceptions.ValidationError: {'field_name': ['Missing data for required field.']}"},{"fix":"Ensure you are using your Marshmallow schema's `.dump()` method to serialize complex Python objects into a dictionary of JSON-serializable types (like strings, numbers, booleans, lists, and dicts) before attempting to JSON-encode them with `jsonify` or `json.dumps()`. Alternatively, configure custom JSON encoders for specific types if not using Marshmallow for that particular object.","cause":"This error often occurs when trying to `jsonify` or directly JSON-encode a Python object (like a SQLAlchemy model instance or a `datetime` object) that Python's default `json` module or a framework's `jsonify` function doesn't know how to convert. Marshmallow's role is to serialize these into JSON-serializable types, but if the output of `schema.dump()` is not used or if non-serializable objects are passed directly to `jsonify` before Marshmallow processes them, this error will appear.","error":"TypeError: Object of type X is not JSON serializable"},{"fix":"When defining a list of nested objects in a Marshmallow schema, wrap the nested Schema class with `fields.Nested()`. For example, use `my_list_field = fields.List(fields.Nested(MyNestedSchema))`.","cause":"This error typically arises in Marshmallow when attempting to define a nested schema within a `fields.List` using `fields.List(MySchema)` instead of `fields.List(fields.Nested(MySchema))`. The `fields.List` expects a Field instance, and `fields.Nested` creates that instance from a Schema class.","error":"TypeError: 'type' object is not subscriptable"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"cli_name":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.46,"mem_mb":4.4,"disk_size":"18.7M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.31,"mem_mb":5.1,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.99,"mem_mb":4.1,"disk_size":"20.1M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.81,"mem_mb":4.1,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.7,"mem_mb":4,"disk_size":"11.9M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.73,"mem_mb":4,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.68,"mem_mb":3.2,"disk_size":"11.6M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.67,"mem_mb":3,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.1,"mem_mb":4.5,"disk_size":"18.2M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.1,"mem_mb":5,"disk_size":"19M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}