Microsoft Kiota Multipart Serialization
This library provides core abstractions and implementation for serializing and deserializing multipart content within Microsoft Kiota generated Python clients. It's part of the broader Kiota ecosystem for building API clients and is currently at version 1.10.1, with a regular release cadence synchronized with other Kiota Python packages. It supports Python versions >=3.10 and <4.0.
Warnings
- breaking Version 1.10.0 and later dropped official support for Python 3.9. Users attempting to install or run with Python 3.9 will encounter `Requires-Python` metadata errors or unexpected runtime behavior.
- gotcha This package relies heavily on core interfaces defined in `microsoft-kiota-abstractions`. If you manually manage your dependencies, ensure `microsoft-kiota-abstractions` is explicitly installed alongside `microsoft-kiota-serialization-multipart` to avoid `ModuleNotFoundError` or `TypeError`.
- gotcha While `MultipartSerializationWriter` supports `write_object_value`, multipart content is fundamentally different from single-body formats like JSON or XML. It's designed for sending data as distinct parts (e.g., form fields, files). Direct serialization of a complex `Parsable` object might not produce the desired single-body multipart output as expected in other formats.
Install
-
pip install microsoft-kiota-serialization-multipart
Imports
- MultipartSerializationWriterFactory
from microsoft_kiota_serialization_multipart import MultipartSerializationWriterFactory
- MultipartParseNodeFactory
from microsoft_kiota_serialization_multipart import MultipartParseNodeFactory
Quickstart
from microsoft_kiota_abstractions.serialization import (
register_default_deserializer,
register_default_serializer,
SerializationWriterFactoryRegistry,
ParseNodeFactoryRegistry
)
from microsoft_kiota_serialization_multipart import (
MultipartSerializationWriterFactory,
MultipartParseNodeFactory
)
# Initialize and register the multipart serialization and deserialization factories.
# This makes them available to Kiota's internal machinery when
# 'multipart/form-data' content type is encountered.
mulipart_serializer_factory = MultipartSerializationWriterFactory()
mulipart_parser_factory = MultipartParseNodeFactory()
register_default_serializer(mulipart_serializer_factory)
register_default_deserializer(mulipart_parser_factory)
print("Microsoft Kiota Multipart Serialization and Deserialization factories registered.")
# You can now retrieve them from the global registry (e.g., for custom HTTP client setups)
# The Kiota generated clients typically handle this registration automatically.
writer_factory = SerializationWriterFactoryRegistry.get_default_instance().get_serialization_writer_factory("multipart/form-data")
parser_factory = ParseNodeFactoryRegistry.get_default_instance().get_parse_node_factory("multipart/form-data")
if writer_factory and parser_factory:
print("\nSuccessfully retrieved Multipart factories from the global registry:")
print(f"- Serialization Writer Factory: {writer_factory}")
print(f"- Parse Node Factory: {parser_factory}")
print("\nThese factories enable Kiota clients to handle 'multipart/form-data' requests and responses.")
else:
print("\nError: Could not retrieve Multipart factories from the global registry.")
# To perform actual serialization/deserialization, you would typically use a
# Kiota-generated client or directly interact with the writer/parser with file streams
# or form data.