Kiota Text Serialization

1.10.1 · active · verified Thu Apr 09

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

Install

Imports

Quickstart

This quickstart demonstrates how to use `TextSerializationWriterFactory` to serialize a string to bytes and `TextParseNodeFactory` to deserialize those bytes back into a string, explicitly handling the 'text/plain' content type.

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}")

view raw JSON →