marshmallow-oneofschema
marshmallow multiplexing schema
What it is and what it does
marshmallow-oneofschema is a plugin for the marshmallow serialization library that adds support for polymorphic schemas—schemas that can serialize and deserialize objects of different types by routing each object to the appropriate type-specific schema. When serializing, it inspects the object type, looks up the corresponding schema from a type-to-schema mapping, and adds a discriminator field (by default named 'type') to the output. Deserialization reverses this: it reads the discriminator field to determine which schema to use for reconstructing the object.
The library is designed to integrate seamlessly with marshmallow's existing API, allowing OneOfSchema instances to be nested within other schemas and used anywhere a standard marshmallow schema would work. It requires only marshmallow as a runtime dependency and supports Python 3.9 and later. The project is actively maintained, has no known security vulnerabilities, and is widely used in the Python ecosystem.
Use it for:
- Serialize and deserialize REST API responses containing multiple object types under a single endpoint.
- Handle database records of different entity types (e.g., User, Admin, Guest) with a single schema interface.
- Build event systems where events can be of different types but need uniform serialization.
- Implement discriminated union types in data pipelines that process heterogeneous object streams.
- Validate and transform polymorphic data structures in configuration or data migration tools.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Extends marshmallow to handle polymorphic serialization and deserialization by routing objects to type-specific schemas based on object type.
Yes. The package solves a genuine gap in marshmallow's core functionality (polymorphic schema support), has low install friction, active maintenance, no security issues, and permissive licensing. Install it if you need to serialize or deserialize multiple object types through a single schema interface.
Install
marshmallow-oneofschema on PyPI
pip
pip install marshmallow-oneofschemauv
uv add marshmallow-oneofschemapoetry
poetry add marshmallow-oneofschemaInstalling marshmallow-oneofschema
Before you install
Low friction: pure Python wheel with a single runtime dependency on marshmallow. Actively maintained with recent releases and no known vulnerabilities.
License in practice
MIT licensed under permissive terms, allowing use in commercial and proprietary projects with minimal restrictions.
Quickstart
pip install marshmallow-oneofschema
from marshmallow_oneofschema import OneOfSchema
import marshmallow
class MyUberSchema(OneOfSchema):
type_schemas = {"Foo": FooSchema, "Bar": BarSchema}
MyUberSchema().dump([Foo(foo="hello"), Bar(bar=123)], many=True)
Requires Python 3.9 or later; marshmallow must be installed as a runtime dependency.
Verify before relying
- Whether the package handles deeply nested polymorphic structures or only single-level type discrimination.
- Performance characteristics when type_schemas contains many schema definitions.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — marshmallow |
| Maintenance | actively maintained — 463 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 6,637,373/month — #1,877 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: marshmallow_oneofschema-3.2.0-py3-none-any.whl
Tags
More Application Frameworks packages
FastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
textualTextual is a Python framework for building…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
mcpBuild and connect to Model Context Protocol…
permissive · top 1,000 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
apispec-oneofschemaExtends apispec to generate OpenAPI 3.0+…
permissive · top 15,000 on PyPI
marshmallow-fastoneofschemaExtends marshmallow to handle polymorphic…
permissive · top 15,000 on PyPI
marshmallow-polyfieldExtends Marshmallow with a PolyField class that…
permissive · top 15,000 on PyPI
DeepFriedMarshmallowAccelerates Marshmallow schema serialization…
permissive · top 15,000 on PyPI
marshmallowMarshmallow converts complex Python objects to…
permissive · top 1,000 on PyPI
marshmallow-mongoengineGenerates marshmallow schemas automatically…
permissive · top 15,000 on PyPI
marshmallow-unionAdds union field support to marshmallow,…
permissive · top 5,000 on PyPI
marshmallow-jsonschemaConverts marshmallow schemas into JSON Schema…
permissive · top 5,000 on PyPI
marshmallow-jsonapiProduces JSON API 1.0-compliant output from…
permissive · top 15,000 on PyPI
flask-marshmallowFlask-Marshmallow integrates Flask and…
permissive · top 5,000 on PyPI