Skip to content

DataTableSaver

Public facade for saving a native DataTable in supported formats.

Operations

Method Output Note
into_csv(datatable, path, encoding="utf-8") CSV Portable interoperability
into_json(datatable, path, encoding="utf-8") JSON Supported simple types
into_xlsx(datatable, path, encoding="utf-8") XLSX Spreadsheet output

datatable is the native table, path selects the output file, and encoding applies to CSV/JSON.

Save one table in multiple formats

Save one table
from pytabify import DataTableCreator, DataTableSaver

datatable = DataTableCreator.from_records(
    [
        {"name": "Alice", "age": 30},
        {"name": "Bob", "age": 25},
    ]
)

DataTableSaver.into_csv(datatable, "people.csv")
DataTableSaver.into_json(datatable, "people.json")
DataTableSaver.into_xlsx(datatable, "people.xlsx")
people.csv
name,age
Alice,30
Bob,25
people.json
[
  {"name": "Alice", "age": 30},
  {"name": "Bob", "age": 25}
]

Headers occupy the first row; records follow schema order.

Parameters

Parameter Required Meaning
datatable Yes Native DataTable
path Yes Output path
encoding No CSV/JSON encoding

Usage variants

Portable output
DataTableSaver.into_csv(datatable, "people.csv")
Output with simple types
DataTableSaver.into_json(datatable, "people.json", encoding="utf-8")
Excel output
DataTableSaver.into_xlsx(datatable, "people.xlsx")
Convert JSON to XLSX
Convert JSON to XLSX
datatable = DataTableCreator.from_file("people.json")
DataTableSaver.into_xlsx(datatable, "people.xlsx")

JSON and XLSX represent supported int, bool and None values better than CSV. Invalid paths or adapter failures raise write exceptions; check permissions, path and extension.

Common mistakes

  • Unsupported path extension.
  • Expecting encoding to change XLSX writing.
  • Passing an object other than native DataTable.
  • Assuming CSV preserves types like JSON/XLSX.

Good practices

Match extension and intended format. Choose CSV for portability, JSON for typed round-trips, and into_xlsx when Excel is the destination.

DataTable Supported formats