marshmallow-union
Union fields for marshmallow.
What it is and what it does
marshmallow-union extends marshmallow's schema validation by providing a Union field that can accept multiple field types. Instead of defining a schema field as strictly one type, you pass a list of candidate fields, and the union tries each one in order during deserialization and serialization, using the first field that succeeds without raising an error.
The library is straightforward but has a documented caveat: because it relies on trial-and-error field matching rather than type inspection, field order matters and unexpected type coercion can occur. The documentation notes that an Integer field accepting string representations will deserialize string inputs as integers. The package suggests marshmallow-polyfield as an alternative if you need stricter type control.
Use it for:
- Accept API payloads where a field may be either an integer ID or a full object representation
- Handle legacy data where a field type changed over time but both formats must be supported
- Deserialize configuration files with flexible value types across multiple formats
- Build schemas that tolerate multiple input formats without explicit type conversion logic
- Serialize polymorphic data structures where the same logical field holds different types
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds union field support to marshmallow, allowing a single field to deserialize and serialize values that match any of several candidate field types.
Yes, if you are already using marshmallow and need union field support with low friction. The package is stable and permissively licensed, but be aware that it has not been actively maintained since 2020 and relies on field-order heuristics rather than strict type matching—test your specific use case carefully, especially if field order could cause unexpected coercion.
Install
marshmallow-union on PyPI
pip
pip install marshmallow-unionuv
uv add marshmallow-unionpoetry
poetry add marshmallow-unionInstalling marshmallow-union
Before you install
Low install friction with a single runtime dependency on marshmallow. Maintenance is aging—last release was 2020-06-24 and the repository shows no recent commits, though it remains unarchived and has received no security vulnerabilities.
License in practice
MIT license (permissive) means you can use, modify, and distribute this package freely with minimal restrictions, making it safe for both open-source and commercial projects.
Quickstart
pip install marshmallow-union
from marshmallow import Schema, fields
from marshmallow_union import Union
class MySchema(Schema):
value = Union([fields.Integer(), fields.String()])
schema = MySchema()
result = schema.load({'value': 'example'})
Verify before relying
- Whether the package works reliably with recent marshmallow versions (last tested in 2020)
- Current Python version support beyond the 3.6 and 3.7 classifiers listed
- Whether field ordering in the union list significantly impacts real-world performance
Package facts
| License | not declared (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — marshmallow |
| Maintenance | aging — 2,242 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,182,494/month — #4,254 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: marshmallow_union-0.1.15.post1-py2.py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
marshmallow-polyfieldExtends Marshmallow with a PolyField class that…
permissive · top 15,000 on PyPI
marshmallow-enumProvides an Enum field type for Marshmallow…
permissive · top 5,000 on PyPI
flask-marshmallowFlask-Marshmallow integrates Flask and…
permissive · top 5,000 on PyPI
marshmallow-mongoengineGenerates marshmallow schemas automatically…
permissive · top 15,000 on PyPI
marshmallowMarshmallow converts complex Python objects to…
permissive · top 1,000 on PyPI
marshmallow-oneofschemaExtends marshmallow to handle polymorphic…
permissive · top 5,000 on PyPI
marshmallow-fastoneofschemaExtends marshmallow to handle polymorphic…
permissive · top 15,000 on PyPI
DeepFriedMarshmallowAccelerates Marshmallow schema serialization…
permissive · top 15,000 on PyPI
amundsen-commonAmundsen Common provides shared utilities and…
unclear · top 15,000 on PyPI
djangorestframework-queryfieldsAllows Django REST framework API clients to…
permissive · top 15,000 on PyPI