skillfed

marshmallow-oneofschema

marshmallow multiplexing schema

marshmallow-oneofschema v3.2.0 6.6M downloads/30d#1,877 on PyPI142
Permissive license Active released

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-oneofschema

uv

uv add marshmallow-oneofschema

poetry

poetry add marshmallow-oneofschema

Installing 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

Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9

Tags

polymorphic schema serializationmarshmallow oneofschemamultiplexing schemastype-based schema routingdiscriminated union deserializationmarshmallow polymorphic types
serializationpolymorphismdata-validation

More Application Frameworks packages

fastapi

FastAPI is a Python web framework for building…

permissive · top 100 on PyPI

annotated-doc

Provides a way to document function parameters,…

permissive · top 100 on PyPI

textual

Textual is a Python framework for building…

permissive · top 100 on PyPI

typer

Typer builds command-line applications from…

permissive · top 1,000 on PyPI

mcp

Build and connect to Model Context Protocol…

permissive · top 1,000 on PyPI

Werkzeug

Werkzeug is a WSGI utility library providing…

permissive · top 1,000 on PyPI

apispec-oneofschema

Extends apispec to generate OpenAPI 3.0+…

permissive · top 15,000 on PyPI

marshmallow-fastoneofschema

Extends marshmallow to handle polymorphic…

permissive · top 15,000 on PyPI

marshmallow-polyfield

Extends Marshmallow with a PolyField class that…

permissive · top 15,000 on PyPI

DeepFriedMarshmallow

Accelerates Marshmallow schema serialization…

permissive · top 15,000 on PyPI

marshmallow

Marshmallow converts complex Python objects to…

permissive · top 1,000 on PyPI

marshmallow-mongoengine

Generates marshmallow schemas automatically…

permissive · top 15,000 on PyPI

marshmallow-union

Adds union field support to marshmallow,…

permissive · top 5,000 on PyPI

marshmallow-jsonschema

Converts marshmallow schemas into JSON Schema…

permissive · top 5,000 on PyPI

marshmallow-jsonapi

Produces JSON API 1.0-compliant output from…

permissive · top 15,000 on PyPI

flask-marshmallow

Flask-Marshmallow integrates Flask and…

permissive · top 5,000 on PyPI