Fastexcel

0.19.0 · active · verified Fri Apr 10

Fastexcel is a high-performance Python library for reading Excel files (.xlsx), implemented in Rust. It focuses on speed and memory efficiency, making it suitable for large datasets. The library is actively maintained with frequent minor releases, typically on a monthly cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to read an Excel file using `fastexcel`. It first creates a dummy Excel file with pandas, then initializes `fastexcel.Reader` to load data into an Apache Arrow Table, showing how to read by sheet index and sheet name.

import pandas as pd
from fastexcel import Reader
import os

# Create a dummy Excel file for demonstration
file_path = "dummy_data.xlsx"
data = {'ColumnA': [1, 2, 3], 'ColumnB': ['X', 'Y', 'Z']}
df = pd.DataFrame(data)
df.to_excel(file_path, index=False)

try:
    # Initialize the reader with the Excel file path
    reader = Reader(file_path)

    # Load the first sheet into an Apache Arrow Table
    table = reader.load_table(sheet_name=0)
    print("\nData from first sheet (Arrow Table):")
    print(table)

    # To access sheet names, first call load_ws()
    reader.load_ws() # Loads all worksheet metadata
    if reader.ws_names:
        first_sheet_name = reader.ws_names[0]
        table_by_name = reader.load_table(sheet_name=first_sheet_name)
        print(f"\nData from sheet '{first_sheet_name}' by name:")
        print(table_by_name)

except Exception as e:
    print(f"An error occurred: {e}")
finally:
    # Clean up the dummy file
    if os.path.exists(file_path):
        os.remove(file_path)
        print(f"\nCleaned up {file_path}")

view raw JSON →