Tabulator

1.53.5 · active · verified Fri Apr 17

Tabulator provides a consistent interface for reading and writing tabular data from various sources (e.g., CSV, Excel, JSON, Google Sheets) in a streaming fashion. It aims to simplify data integration by abstracting away the underlying file formats. The current version is 1.53.5, and it maintains a regular release cadence with minor updates and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `tabulator.Stream` to read tabular data from a remote CSV file. It iterates through the rows, printing the headers and the first few data rows. The Stream object handles opening and closing the data source automatically.

import os
from tabulator import Stream

# Example: Read a CSV file from a URL
csv_url = "https://raw.githubusercontent.com/frictionlessdata/tabulator-py/master/data/table.csv"

# Ensure the URL is accessible or provide a local path
try:
    with Stream(csv_url) as stream:
        print(f"Headers: {stream.headers}")
        print("First 5 rows:")
        for i, row in enumerate(stream):
            if i >= 5:
                break
            print(row)
except Exception as e:
    print(f"Could not read data from {csv_url}: {e}")

# Example: Reading a local CSV file (ensure 'example.csv' exists)
# You can create a dummy file for local testing:
# with open('example.csv', 'w') as f:
#     f.write('id,name\n1,Alice\n2,Bob')
#
# local_csv_path = 'example.csv'
# if os.path.exists(local_csv_path):
#     with Stream(local_csv_path) as stream:
#         print(f"\nLocal CSV Headers: {stream.headers}")
#         print(f"Local CSV First row: {next(iter(stream))}")
# else:
#     print(f"\nSkipping local CSV example: {local_csv_path} not found.")

view raw JSON →