Registry / serialization / marshmallow-fastoneofschema

marshmallow-fastoneofschema

JSON →
library2025.9.2.1.dev7pypypi✓ verified 85d ago

A fast multiplexing schema for marshmallow that dispatches deserialization to a subschema based on a discriminator field. Uses schema caching for speed. Current version (2025.9.2.1.dev7) is a development release; requires Python >=3.11.

pip install marshmallow-fastoneofschema
INSTALL
IMPORT
SIG · MARSHMALLOW-FASTON
M
marshmallow-fastoneofschema
serializationpythonv2025.9.2.1.dev7
Install
1.6s avg
Import
Disk
15MB
Pass rate
6/ 10
Env Coverage6 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2025.9.2.1.dev7 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✕ build_error
py 3.11
✓ —
✓ 1.7s
py 3.12
✓ —
✓ 1.5s
py 3.13
✓ —
✓ 1.5s
py 3.9
✕ build_error
✕ build_error
15MB installed
● package 15MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FastOneOfSchema
from marshmallow_fastoneofschema import FastOneOfSchema

Demonstrates basic usage: define a FastOneOfSchema with a discriminator field and subschemas.

from marshmallow import Schema, fields from marshmallow_fastoneofschema import FastOneOfSchema class CarSchema(Schema): make = fields.String(required=True) model = fields.String(required=True) class BoatSchema(Schema): length = fields.Float(required=True) class VehicleSchema(FastOneOfSchema): type_field = 'vehicle_type' type_schemas = { 'car': CarSchema, 'boat': BoatSchema } schema = VehicleSchema() data = {'vehicle_type': 'car', 'make': 'Toyota', 'model': 'Camry'} result = schema.load(data) print(result) # => {'vehicle_type': 'car', 'make': 'Toyota', 'model': 'Camry'}
Debug
Known issues
gotchaThe `type_field` must be present in the input data and must match one of the keys in `type_schemas`. Missing or mismatched values cause a validation error.
fix
Ensure each input dict contains the discriminator field with a valid value.
affects: all
gotchaFastOneOfSchema caches the mapping from type_field value to schema. If you mutate `type_schemas` after instantiation, the cache may become stale.
fix
Define `type_schemas` as a class variable or set it before any call to load/dump.
affects: all
deprecatedPreviously, the discriminator field was set via `type_field` as a class variable. Some older examples used `type_field_` (with underscore). The correct attribute is `type_field`.
fix
Use `type_field` (without trailing underscore) as the class variable or constructor argument.
affects: <2025.9.2.1
Errors
Common errors & fixes
ImportError: cannot import name 'FastOneOfSchema' from 'marshmallow_fastoneofschema'
Old version or incorrect library installed (e.g., same name but different package).
fix
Run `pip install --upgrade marshmallow-fastoneofschema` and ensure you have a recent version (>=2025.9.2.1.dev0).
marshmallow.exceptions.ValidationError: {'_schema': ['Invalid type field value']}
The discriminator field value does not match any key in `type_schemas`.
fix
Check that the input contains a valid discriminator value, e.g., one of the keys defined in `type_schemas`.
Upgrade
Version history
2025.9.2.1.dev7latest on PyPI · released Sep 2, 2025
Audit
Dependencies
marshmallowrequiredCore framework dependency
Agent activity
6 hits · last 30 days
node
6
Resources
marshmallow-fastoneofschema — pip install marshmallow-fastoneofschema · libregistry