Amazon Ion Python Implementation

0.13.0 · active · verified Mon Apr 06

A Python implementation of Amazon Ion, a richly-typed, self-describing, hierarchical data serialization format. It offers interchangeable binary and text representations, with text being a superset of JSON. The library is currently at version 0.13.0 and is actively maintained with regular updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `simpleion` module to serialize Python dictionaries into Ion text and binary formats, and deserialize them back. It also shows how to work with Ion-specific types like `IonPyTimestamp`.

import amazon.ion.simpleion as ion

# Dump Python objects to Ion text or binary
data_py = {'id': 123, 'name': 'example', 'active': True}
ion_text = ion.dumps(data_py, binary=False, indent='  ')
print('Ion Text:\n', ion_text)

ion_binary = ion.dumps(data_py, binary=True)
print('Ion Binary (bytes):', ion_binary)

# Load Ion data back into Python objects
loaded_py_text = ion.loads(ion_text)
print('Loaded from Text:', loaded_py_text)

loaded_py_binary = ion.loads(ion_binary)
print('Loaded from Binary:', loaded_py_binary)

# Example with a specific Ion type
from datetime import datetime
from amazon.ion.simple_types import IonPyTimestamp
timestamp_py = IonPyTimestamp(datetime(2023, 10, 27, 10, 30, 0))
ion_timestamp = ion.dumps({'event_time': timestamp_py}, binary=False)
print('Ion Timestamp:\n', ion_timestamp)

view raw JSON →