Files
kennethreitz.org/data/software/tablib.md
T
2026-03-22 04:26:07 -04:00

2.5 KiB

Tablib: Tabular Datasets for Humans

Tablib is a format-agnostic tabular dataset library for Python. Create a dataset once, export it to CSV, JSON, Excel, YAML, or a pandas DataFrame. The data stays the same. The format is up to you.

$ uv pip install tablib

What It Looks Like

import tablib

# Create a dataset.
data = tablib.Dataset(headers=["Name", "Age", "City"])

data.append(["Alice", 28, "Portland"])
data.append(["Bob", 34, "Seattle"])
data.append(["Charlie", 22, "Austin"])

# Export to CSV.
print(data.export("csv"))
# Name,Age,City
# Alice,28,Portland
# Bob,34,Seattle
# Charlie,22,Austin

# Export to JSON.
print(data.export("json"))
# [{"Name": "Alice", "Age": 28, "City": "Portland"}, ...]

# Export to Excel.
with open("people.xlsx", "wb") as f:
    f.write(data.export("xlsx"))

# Import from CSV.
data = tablib.Dataset().load(open("people.csv").read())

# Filter and sort.
data.sort("Age")

One dataset, any format. Import from one, export to another. The data doesn't care about file formats, and neither should you.

The Story

Tablib was one of my first open source projects, built in 2010 before the data science ecosystem in Python really took off. It came from a simple frustration: I kept writing the same import/export boilerplate for every project that dealt with tabular data.

The idea was format agnosticism. Your data is your data. Whether it ends up as a spreadsheet, a JSON file, or a DataFrame shouldn't change how you work with it. That principle, that software should adapt to your workflow rather than the other way around, became central to everything I built after.

Tablib powers the export functionality in Records, and its approach to clean API design directly influenced Requests.

Install

$ uv pip install tablib

For specific format support:

$ uv pip install tablib[xlsx]    # Excel support
$ uv pip install tablib[yaml]    # YAML support
$ uv pip install tablib[all]     # Everything

Resources