Write data other systems can read
Inside Python, an order is a dict with a Decimal amount. Another program cannot read a Python dict. It reads a file.
Serialization means turning Python values into text or bytes for a file. Reading them back into Python values is called deserialization.
Every example uses the shop orders as a list of dicts:
| order_id | customer_id | status | amount | order_date |
|---|---|---|---|---|
| 101 | 1 | paid | Decimal('40.00') | 2026-01-03 |
| 102 | 1 | paid | Decimal('25.00') | 2026-01-10 |
| 103 | 2 | refunded | Decimal('60.00') | 2026-01-11 |
| 104 | 3 | paid | Decimal('15.50') | 2026-01-15 |
| 105 | 3 | pending | None | 2026-01-20 |
| 106 | 4 | paid | Decimal('80.00') | 2026-01-21 |
A list of six dicts. Chapter 5 turned the amounts into Decimal. Order 105 has no amount.
from decimal import Decimal
orders = [
{"order_id": 101, "customer_id": 1, "status": "paid",
"amount": Decimal("40.00"), "order_date": "2026-01-03"},
# ... orders 102 to 106 in the same shape ...
]This chapter shows four file formats and when to use each:
| Format | In one line |
|---|---|
| CSV | A table as plain text, with commas between values. |
| JSON and NDJSON | Text that can hold nested values. |
| Parquet | A file stored by column, for reports. |
| Avro | Rows stored together with a description of their fields. |
