Skip to content

Quick start

Follow the complete minimal flow: load data, inspect rows, update the schema and save another format.

End-to-end flow

Load a JSON file, add a column in memory and export CSV. Python and Robot Framework use the same flow. Install Robot Framework separately for the Robot example.

Input

people.json
[
  {"name": "Alice", "age": 30},
  {"name": "Bob", "age": 25}
]

Run

quickstart.py
from pytabify import DataTableCreator, DataTableSaver

datatable = DataTableCreator.from_file("people.json")

print(datatable.column_names)
print(datatable[0].to_dict())

datatable[0]["country"] = "MX"

DataTableSaver.into_csv(datatable, "people.csv")
Execution
python quickstart.py
quickstart.robot
*** Settings ***
Library    Pytabify

*** Test Cases ***
Convertir json a csv
    ${table}=    Pytabify.Create Data Table From File    people.json
    ${headers}=    Pytabify.Get Data Table Headers    ${table}
    Log To Console    ${headers}
    ${row}=    Pytabify.Get Data Table Row    ${table}    0
    Log To Console    ${row.name}
    ${table}=    Pytabify.Set Data Table Value    ${table}    0    country    MX
    Pytabify.Save Data Table To Csv    ${table}    people.csv
Execution
robot quickstart.robot

Expected output

stdout
('name', 'age')
{'name': 'Alice', 'age': 30}
people.csv
name,age,country
Alice,30,MX
Bob,25,
stdout
['name', 'age']
Alice
people.csv
name,age,country
Alice,30,MX
Bob,25,

Saving is explicit

Cell assignment changes memory only. into_csv or Save Data Table To Csv creates the file.

Alternative sources
JSON -> DataTable -> CSV
from pytabify import DataTableCreator, DataTableSaver

datatable = DataTableCreator.from_file("people.json")

print(datatable.column_names)
print(datatable[0].to_dict())

datatable[0]["country"] = "MX"

DataTableSaver.into_csv(datatable, "people.csv")
List of dictionaries -> DataTable -> JSON
from pytabify import DataTableCreator, DataTableSaver

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

datatable[1].country = "US"

DataTableSaver.into_json(datatable, "people.json")

In-memory access

Index, attribute and key access
row = datatable[0]

print(row.name)
print(row["age"])
print(row.to_dict())

Safe schema updates

Adding a new column to one row expands the full schema and fills other rows with None.

Basic parameters

Parameter Applies to Purpose
path from_file, into_csv, into_json, into_xlsx Input/output file
sheet_name XLSX from_file Specific sheet
encoding CSV/JSON reading and writing File encoding
records from_records Initial tabular collection
Load from a file
datatable = DataTableCreator.from_file("people.json")
Read a specific sheet
datatable = DataTableCreator.from_file("people.xlsx", sheet_name="People")
Save JSON with explicit encoding
DataTableSaver.into_json(datatable, "people.json", encoding="utf-8")

Practical format rules

  • CSV: portable; reading returns strings.
  • JSON: preserves supported native types.
  • XLSX: requires sheet_name when reading.
Read an XLSX sheet
Read a specific sheet
datatable = DataTableCreator.from_file("people.xlsx", sheet_name="People")

Common errors

  • Missing file: path must identify a real file.
  • Non-rectangular records: every row must share the same set of columns.
  • Unexpected CSV types: use JSON, XLSX or from_records when native types matter.

Next steps

Python examples Robot Framework examples DataTableCreator reference DataTableSaver reference