{"library":"marshmallow-union","title":"Marshmallow Union","description":"marshmallow-union provides a `Union` field for Marshmallow schemas, allowing a single field to accept and serialize/deserialize values that conform to one of several specified field types. The library works by trying a list of fields one by one until one succeeds. The current version is 0.1.15.post1, released in June 2020, indicating a maintenance or inactive release cadence.","language":"python","status":"maintenance","last_verified":"Sat May 16","install":{"commands":["pip install marshmallow-union"],"cli":null},"imports":["from marshmallow_union import Union"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import marshmallow\nfrom marshmallow import Schema, fields, ValidationError\nfrom marshmallow_union import Union\n\nclass MySchema(Schema):\n    id = fields.Integer(required=True)\n    value = Union(fields=[fields.Integer(), fields.String()], required=True)\n\n# Deserialization (loading)\ndata_int = {'id': 1, 'value': 123}\ndata_str = {'id': 2, 'value': 'hello'}\ndata_invalid = {'id': 3, 'value': []}\n\nschema = MySchema()\n\n# Load an integer value\nloaded_int = schema.load(data_int)\nprint(f\"Loaded Int: {loaded_int}\")\nassert loaded_int == {'id': 1, 'value': 123}\n\n# Load a string value\nloaded_str = schema.load(data_str)\nprint(f\"Loaded String: {loaded_str}\")\nassert loaded_str == {'id': 2, 'value': 'hello'}\n\n# Attempt to load an invalid value\ntry:\n    schema.load(data_invalid)\nexcept ValidationError as e:\n    print(f\"Validation Error: {e.messages}\")\n    assert 'value' in e.messages\n\n# Serialization (dumping)\ndumped_int = schema.dump(loaded_int)\nprint(f\"Dumped Int: {dumped_int}\")\nassert dumped_int == data_int\n\ndumped_str = schema.dump(loaded_str)\nprint(f\"Dumped String: {dumped_str}\")\nassert dumped_str == data_str","lang":"python","description":"This quickstart demonstrates how to define a `Union` field in a Marshmallow schema and perform both deserialization (loading) and serialization (dumping) of data containing either an integer or a string. It also shows how validation errors are raised for unsupported types.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":"0.1.15.post1","pypi_latest":"0.1.15.post1","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":1.6,"avg_import_s":0.55,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"marshmallow-union","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.46,"mem_mb":4.5,"disk_size":"18.7M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"marshmallow-union","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.6,"import_time_s":0.31,"mem_mb":5.1,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"marshmallow-union","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.96,"mem_mb":4.1,"disk_size":"20.1M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"marshmallow-union","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.6,"import_time_s":0.9,"mem_mb":4.1,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"marshmallow-union","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.64,"mem_mb":4,"disk_size":"12.0M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"marshmallow-union","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.5,"import_time_s":0.74,"mem_mb":4,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"marshmallow-union","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.6,"mem_mb":3.2,"disk_size":"11.7M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"marshmallow-union","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.5,"import_time_s":0.67,"mem_mb":3,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"marshmallow-union","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.12,"mem_mb":4.5,"disk_size":"18.2M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"marshmallow-union","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.9,"import_time_s":0.11,"mem_mb":5.1,"disk_size":"19M"}]}}