interchange
raw JSON → 2021.0.4 verified Fri May 01 auth: no python maintenance
A Python library providing data types and interchange formats (JSON, YAML, XML, etc.) with a focus on seamless conversion between them. Current version is 2021.0.4, released in 2021. The library is in maintenance mode with no active development.
pip install interchange Common errors
error AttributeError: module 'interchange' has no attribute 'DataTypes' ↓
cause Incorrect import path (e.g., from interchange.data_types import DataTypes) but DataTypes is not a submodule.
fix
Use 'from interchange import DataTypes'.
error TypeError: convert() argument 1 must be a string or dict, not list ↓
cause The convert() function expects a specific input type depending on target format. Lists may not be directly convertible to some formats.
fix
Wrap the list in a dict like {'data': my_list} or use a different approach.
error ImportError: cannot import name 'convert' from 'interchange' ↓
cause Old versions of interchange may not have the convert function, or package installation is corrupted.
fix
Ensure you have version >=2021.0.0: pip install --upgrade interchange
Warnings
deprecated The library is in maintenance mode and no longer actively developed. Future Python versions (e.g., 3.12+) may break due to missing updates. ↓
fix Consider migrating to modern alternatives like pydantic or json.dumps for simple cases.
gotcha The convert() function may not handle all edge cases (e.g., nested custom objects). It is designed for simple types. ↓
fix Test your specific data shapes thoroughly before relying on interchange in production.
gotcha The library does not support Python 3.10+ officially; it was last tested on Python 3.8. ↓
fix Use a virtual environment with Python 3.8 or 3.9 if you must use this library.
Imports
- DataTypes wrong
from interchange.data_types import DataTypescorrectfrom interchange import DataTypes - convert wrong
import interchange.convertcorrectfrom interchange import convert
Quickstart
from interchange import DataTypes, convert
# Convert a dict to JSON string
data = {"name": "example"}
json_str = convert(data, DataTypes.JSON)
print(json_str)
# Parse JSON back to dict
parsed = convert(json_str, DataTypes.DICT)
print(parsed)