mirror of
https://github.com/kennethreitz/kennethreitz.org.git
synced 2026-06-05 22:50:17 +00:00
8459271d45
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
76 lines
2.5 KiB
Markdown
76 lines
2.5 KiB
Markdown
# 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
|
|
|
|
```python
|
|
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](/software/records), and its approach to clean API design directly influenced [Requests](/software/requests).
|
|
|
|
## Install
|
|
|
|
```bash
|
|
$ uv pip install tablib
|
|
```
|
|
|
|
For specific format support:
|
|
|
|
```bash
|
|
$ uv pip install tablib[xlsx] # Excel support
|
|
$ uv pip install tablib[yaml] # YAML support
|
|
$ uv pip install tablib[all] # Everything
|
|
```
|
|
|
|
## Resources
|
|
|
|
- [Documentation](https://tablib.readthedocs.io/en/stable/)
|
|
- [Source Code on GitHub](https://github.com/jazzband/tablib)
|
|
- [Python Package Index](https://pypi.org/project/tablib/)
|
|
|
|
## Related
|
|
|
|
- [**Records**](/software/records) — SQL for Humans, powered by Tablib's export engine.
|
|
- [**The Lego Bricks Era**](/essays/2026-03-18-values_i_outgrew_and_the_ones_that_stayed) — The era when these libraries came together.
|
|
- [**From HTTP to Consciousness**](/essays/2025-08-27-from_http_to_consciousness) — How designing for humans became a worldview.
|