Kiota Text Serialization
This library provides core serialization and deserialization capabilities for plain text (`text/plain`) within the Microsoft Kiota ecosystem for Python. It allows Kiota-generated API clients to handle text-based responses and requests. The current version is 1.10.1, and releases are frequent, synchronized with the broader Kiota project across multiple languages.
Warnings
- breaking Support for Python 3.9 was dropped starting from version 1.10.0. Ensure your environment uses Python 3.10 or higher.
- gotcha This library specifically handles `text/plain` content. Attempting to use its factories with other content types (e.g., `application/json`, `application/xml`) will result in errors or incorrect parsing, as it lacks the necessary logic for those formats.
- gotcha For full integration within the Kiota request adapter pipeline, you must register `TextSerializationWriterFactory` and `TextParseNodeFactory` with `SerializationWriterFactoryRegistry.default_instance` and `ParseNodeFactoryRegistry.default_instance` respectively. Without registration, the default Kiota request adapter might not automatically pick up these factories for 'text/plain' content.
Install
-
pip install microsoft-kiota-serialization-text
Imports
- TextSerializationWriterFactory
from microsoft_kiota_serialization_text import TextSerializationWriterFactory
- TextParseNodeFactory
from microsoft_kiota_serialization_text import TextParseNodeFactory
Quickstart
from microsoft_kiota_serialization_text import TextParseNodeFactory, TextSerializationWriterFactory
# Instantiate the factory for text serialization
writer_factory = TextSerializationWriterFactory()
writer = writer_factory.get_serialization_writer('text/plain')
# Serialize a string value
writer.write_str_value(None, 'Hello from Kiota!')
serialized_content = writer.get_serialized_content() # Returns bytes
print(f"Serialized (bytes): {serialized_content}")
print(f"Serialized (str): {serialized_content.decode('utf-8')}")
# Instantiate the factory for text deserialization
parser_factory = TextParseNodeFactory()
parser = parser_factory.get_parse_node('text/plain', serialized_content)
# Deserialize the string value
deserialized_value = parser.get_string_value()
print(f"Deserialized: {deserialized_value}")