Tablib: Pythonic Tabular Datasets

3.9.0 · active · verified Thu Apr 09

Tablib is an MIT-licensed, format-agnostic tabular dataset library for Python, enabling Pythonic import, export, and manipulation of tabular data. It supports various formats like XLS, JSON, YAML, CSV, Pandas DataFrames, and HTML. Maintained by the Jazzband community, it is currently in version 3.9.0 and receives regular updates for Python compatibility and bug fixes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a `Dataset` object, add headers, append rows, add a new column, and then export the data to different formats like CSV and JSON. It also includes a commented-out example for exporting to an XLSX file.

import tablib

# Create a new Dataset
data = tablib.Dataset()

# Add headers
data.headers = ['First Name', 'Last Name', 'Age']

# Add rows
data.append(['Kenneth', 'Reitz', 22])
data.append(['Bessie', 'Monke', 20])

# Add a new column with data
data.append_col([True, False], header='Is Student')

print("CSV Export:")
print(data.export('csv'))

print("\nJSON Export:")
print(data.export('json'))

# Example of saving to a file (uncomment to run)
# with open('output.xlsx', 'wb') as f:
#     f.write(data.export('xlsx'))
# print("\nData exported to output.xlsx")

view raw JSON →