CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-dicttoxml

Converts a Python dictionary or other native data type into a valid XML string.

86

0.98x
Overview
Eval results
Files

task.mdevals/scenario-4/

XML Order Export

Create an XML document from order records, ensuring the payload is wrapped in an outer element that can use either a default tag or a caller-provided name. Sample input used across tests:

[
    {"order_id": 101, "customer": "Ada", "items": ["pen", "paper"]},
    {"order_id": 102, "customer": "Lin", "items": ["stapler"]}
]

Capabilities

Wraps with default root

  • Converting the sample orders without specifying a root name returns a bytes XML document that starts with an XML declaration and wraps all content inside the default outer element name. @test

Supports custom root tag

  • When the caller supplies a root tag name (e.g., "orders") and requests string output, the XML document uses that tag for the outer element while retaining the declaration and nested order details. @test

Normalizes invalid root names

  • Providing a root tag that is not a valid XML element name (e.g., starts with a digit) results in a valid wrapper element being generated (using the library's normalization) without dropping or reordering order data. @test

Implementation

@generates

API

from typing import Iterable, Mapping, Any, Union

def export_orders(records: Iterable[Mapping[str, Any]], root_tag: str | None = None, as_bytes: bool = True) -> Union[bytes, str]:
    """Convert order records into an XML document with an outer wrapper element."""

Dependencies { .dependencies }

dicttoxml { .dependency }

Converts Python objects into XML documents with configurable wrapping.

Install with Tessl CLI

npx tessl i tessl/pypi-dicttoxml

tile.json