--- id: marshmallow-polyfield version: "5.11" license: Apache 2.0 license_treatment: permissive maintenance: dormant --- # marshmallow-polyfield — An unofficial extension to Marshmallow to allow for polymorphic fields License: permissive · Maintenance: dormant · Downloads: 174.9K/mo ## What it is and what it does Marshmallow-Polyfield is an unofficial extension to Marshmallow that adds support for polymorphic fields—fields that can hold objects of different types and serialize/deserialize them appropriately. Instead of defining a single schema for a field, you provide two selector functions: one that examines an object during serialization and returns the correct schema, and another that examines incoming data during deserialization and returns the correct schema. This allows you to handle heterogeneous data structures where a single field might contain different object types that each need their own serialization logic. The package integrates with Marshmallow's standard field properties like `required`, `allow_none`, and `many`, so polymorphic fields behave like any other Marshmallow field in your schema. It targets Marshmallow 3.0 and above and supports Python >= 3.5. The package has no external runtime dependencies beyond Marshmallow itself. Use it for: - Serialize REST API responses where a single field holds different object types. - Build schemas for heterogeneous collections where each item's schema depends on its type. - Handle polymorphic data in JSON APIs where type discrimination is based on attributes. - Implement type-aware serialization in inheritance hierarchies with custom per-type handling. - Deserialize incoming data by inspecting its structure to determine which schema to apply. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Extends Marshmallow with a PolyField class that handles serialization and deserialization of polymorphic types by selecting the appropriate schema based on the object's runtime type. Yes, if you are already using Marshmallow 3.0+ and need polymorphic field support. The package is permissively licensed, has no external dependencies, and is stable for its intended use. However, it has been dormant since 2022-10-26 with no active maintenance—install only if you can tolerate potential incompatibilities with future Marshmallow releases. ## Install pip install marshmallow-polyfield uv add marshmallow-polyfield poetry add marshmallow-polyfield ## Installing marshmallow-polyfield Before you install: High install friction; no runtime dependencies but the package has been dormant since 2022-10-26 (over 1388 days without release). Last commit was 2024-07-01. Suitable for projects already committed to Marshmallow 3.0+ that can tolerate lack of active maintenance. License in practice: Licensed under Apache 2.0 (permissive), allowing commercial and private use with minimal restrictions. No license-based barriers to adoption. Quickstart: pip install marshmallow-polyfield from marshmallow_polyfield import PolyField from marshmallow import Schema class MySchema(Schema): field = PolyField( serialization_schema_selector=my_serializer, deserialization_schema_selector=my_deserializer ) Requires Marshmallow 3.0 or above; requires Python >= 3.5. You must define both serialization_schema_selector and deserialization_schema_selector functions. Verify before relying: - Whether the package works correctly with recent Marshmallow versions given the long maintenance gap. - Whether critical bugs would receive fixes under current maintenance status. - Compatibility with Python versions beyond 3.7 (classifiers only list up to 3.7). ## Package facts - License: Apache 2.0 (permissive) - Python support: supports_current - Install friction: high - Maintenance: dormant - Downloads: 174.9K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags polymorphic serialization marshmallow, marshmallow polymorphic fields, polymorphic type handling, schema selection by type, marshmallow extension polymorphism, dynamic schema selection, polymorphic deserialization, serialization, polymorphism, marshmallow-extension [View on SkillFed](https://skillfed.io/packages/marshmallow-polyfield) · [View on PyPI](https://pypi.org/project/marshmallow-polyfield/)