{"id":24012,"library":"marshmallow-fastoneofschema","title":"marshmallow-fastoneofschema","description":"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.","status":"active","version":"2025.9.2.1.dev7","language":"python","source_language":"en","source_url":"https://github.com/Kalepa/marshmallow-fastoneofschema","tags":["marshmallow","schema","polymorphism","fast-oneof","serialization"],"install":[{"cmd":"pip install marshmallow-fastoneofschema","lang":"bash","label":"pip"}],"dependencies":[{"reason":"Core framework dependency","package":"marshmallow","optional":false}],"imports":[{"note":"","wrong":"","symbol":"FastOneOfSchema","correct":"from marshmallow_fastoneofschema import FastOneOfSchema"}],"quickstart":{"code":"from marshmallow import Schema, fields\nfrom marshmallow_fastoneofschema import FastOneOfSchema\n\nclass CarSchema(Schema):\n    make = fields.String(required=True)\n    model = fields.String(required=True)\n\nclass BoatSchema(Schema):\n    length = fields.Float(required=True)\n\nclass VehicleSchema(FastOneOfSchema):\n    type_field = 'vehicle_type'\n    type_schemas = {\n        'car': CarSchema,\n        'boat': BoatSchema\n    }\n\nschema = VehicleSchema()\ndata = {'vehicle_type': 'car', 'make': 'Toyota', 'model': 'Camry'}\nresult = schema.load(data)\nprint(result)  # => {'vehicle_type': 'car', 'make': 'Toyota', 'model': 'Camry'}","lang":"python","description":"Demonstrates basic usage: define a FastOneOfSchema with a discriminator field and subschemas."},"warnings":[{"fix":"Ensure each input dict contains the discriminator field with a valid value.","message":"The `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.","severity":"gotcha","affected_versions":"all"},{"fix":"Define `type_schemas` as a class variable or set it before any call to load/dump.","message":"FastOneOfSchema caches the mapping from type_field value to schema. If you mutate `type_schemas` after instantiation, the cache may become stale.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `type_field` (without trailing underscore) as the class variable or constructor argument.","message":"Previously, 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`.","severity":"deprecated","affected_versions":"<2025.9.2.1"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `pip install --upgrade marshmallow-fastoneofschema` and ensure you have a recent version (>=2025.9.2.1.dev0).","cause":"Old version or incorrect library installed (e.g., same name but different package).","error":"ImportError: cannot import name 'FastOneOfSchema' from 'marshmallow_fastoneofschema'"},{"fix":"Check that the input contains a valid discriminator value, e.g., one of the keys defined in `type_schemas`.","cause":"The discriminator field value does not match any key in `type_schemas`.","error":"marshmallow.exceptions.ValidationError: {'_schema': ['Invalid type field value']}"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}