Skip to main content

Developers Toolbox

Data Converter

Python library that loads JSON, JSON5, XML, YAML, or TOML into a dictionary, then writes any of those formats. Conversion is two-pass through that dict hub — there are no pairwise converters.

The PyPI name is lupaxa-data-converter. The import path is lupaxa.data_converter. lupaxa is a namespace package.

Install

pip install lupaxa-data-converter

Requires Python 3.10+. The package pulls in PyYAML, defusedxml, json5, and tomli-w. Python 3.10 also needs tomli; 3.11+ uses stdlib tomllib.

This is a library only. There is no console script and no python -m entry point.

Usage

from lupaxa.data_converter import DataConverter

payload = {"name": "Lupaxa", "formats": ["json", "json5", "xml", "yaml", "toml"]}
converter = DataConverter(payload, data_type="dict")

print(converter.to_json())
print(converter.to_json5())
print(converter.to_xml())
print(converter.to_yaml())
print(converter.to_toml())

DataConverter accepts a dictionary or a document string. Set data_type to match the input (case-insensitive). The value is always stored as a mapping on converter.data, then any to_* method can write it out. Identity conversions are supported.

data_type Input
dict A Python dictionary
json A JSON object string (default)
json5 A JSON5 object string
xml An XML document string
yaml A YAML mapping string
toml A TOML table string
from_dict = DataConverter({"id": 1}, data_type="dict")
from_json = DataConverter('{"id": 1}', data_type="json")
from_json5 = DataConverter("{ id: 1, }", data_type="json5")
from_xml = DataConverter("<root><id>1</id></root>", data_type="xml")
from_yaml = DataConverter("id: 1\n", data_type="yaml")
from_toml = DataConverter("id = 1\n", data_type="toml")

JSON, JSON5, YAML, and TOML documents must be mappings. Arrays and scalars raise DataConverterError.

to_xml() wraps the mapping in root_tag (the XML source root, or root for other sources). Pass root_tag to override it.

converter.to_xml(root_tag="item")

XML

Child elements with the same tag become a list. Attributes are stored as @name keys and written back as attributes. A list value is emitted as repeated elements with that key. The original root stays on converter.root_tag.

converter = DataConverter('<person id="7"><name>Ann</name></person>', data_type="xml")
converter.data
# {"@id": "7", "name": "Ann"}
converter.to_xml()
# <person id="7">...</person>

Errors

Parse failures, type mismatches, unsupported data_type values, and invalid XML names raise DataConverterError. Underlying parser errors are attached as __cause__.

from lupaxa.data_converter import DataConverter, DataConverterError

try:
    DataConverter("{not-json", data_type="json")
except DataConverterError as exc:
    print(exc)

Helpers

These class methods convert without constructing an instance first. dict_to_xml and json_to_xml wrap the mapping in root_tag (default root). xml_to_json returns the element payload, not a {root: ...} wrapper.

from lupaxa.data_converter import DataConverter

DataConverter.dict_to_xml({"id": 1}, root_tag="root")
DataConverter.json_to_xml({"id": 1}, root_tag="root")
DataConverter.xml_to_json("<root><id>1</id></root>")
DataConverter.yaml_to_dict("id: 1\n")
DataConverter.toml_to_dict("id = 1\n")
DataConverter.json5_to_dict("{ id: 1, }")
The Lupaxa Project Footer

Metadata

Release files for lupaxa-data-converter 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lupaxa-data-converter 0.1.4
File Size Uploaded
lupaxa_data_converter-0.1.4.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lupaxa-data-converter 0.1.4
File Interpreter ABI Platform
lupaxa_data_converter-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 17.5 kB

Release files / lupaxa_data_converter-0.1.4.tar.gz

Download URL lupaxa_data_converter-0.1.4.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
42e7d743858a4c55fa96c895182d17119f8f9f0bb46e160c043e42ce3e222ded
BLAKE2b-256 checksum
How to use checksums
2c2fa1823fed75836aee0c7a821009fe31b2be79be596deefe5ea97e74338e74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Release files / lupaxa_data_converter-0.1.4-py3-none-any.whl

Download URL lupaxa_data_converter-0.1.4-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
85f53c56323d15684e5850231319b33df6ff49bdaa5b28087d0ec52821b9cd69
BLAKE2b-256 checksum
How to use checksums
3bf7bdd8353fec4741b2b5f442cb8bcc2bc232fbbf90a4f7fe6940bb3fe39ee5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.5

2 release files

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page