Serialize Python objects to JSON for an API response without manually writing conversion code for each field.
Validate incoming API request data against your schema rules and return structured error messages when validation fails.
Define data transformation rules once in a schema class and reuse the same definition for serialization, deserialization, and validation.
Convert database query results into formatted dictionaries ready to be returned as JSON from a Flask or Django endpoint.
Marshmallow is a Python library that helps you move data cleanly between your application and the outside world. When your app works with objects that have nested structures, dates, or custom types, marshmallow handles the translation into plain Python dictionaries and strings that can be sent as JSON or stored in a database. It also works in reverse, taking raw incoming data and converting it back into the objects your code expects. The core concept is a "schema," which is a class you write that describes the shape of your data. You define which fields exist, what types they should be, and any rules they must follow. Once you have a schema, you can use it to serialize (convert your objects to simple data), deserialize (convert incoming data to objects), and validate (check that the incoming data meets your rules). All three operations come from the same schema definition, so you only describe your data once. Marshmallow works with any Python web framework or database library. It does not care whether you are using Flask, Django, SQLAlchemy, or something else entirely. You define schemas as plain Python classes, and the library stays out of the way of your broader codebase. This makes it a common choice in HTTP API projects where data needs to be validated on the way in and formatted on the way out. Installing marshmallow takes one command via pip, and the full documentation is hosted at marshmallow.readthedocs.io. The project has an active ecosystem of third-party extensions listed in its GitHub wiki, covering integrations with popular frameworks and tools. The library is MIT licensed and maintained through open-source contributions, with professional support available via a Tidelift subscription for teams that need it.
← marshmallow-code on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.