--- id: marshmallow-oneofschema version: "3.2.0" license: unclear license_treatment: permissive maintenance: active --- # marshmallow-oneofschema — marshmallow multiplexing schema License: permissive · Maintenance: active · Downloads: 6.6M/mo ## 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 above — 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 pip install marshmallow-oneofschema uv add marshmallow-oneofschema 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_current - Install friction: low - Maintenance: active - Downloads: 6.6M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags polymorphic schema serialization, marshmallow oneofschema, multiplexing schemas, type-based schema routing, discriminated union deserialization, marshmallow polymorphic types, serialization, polymorphism, data-validation [View on SkillFed](https://skillfed.io/packages/marshmallow-oneofschema) · [View on PyPI](https://pypi.org/project/marshmallow-oneofschema/)