python-calamine

0.6.2 · active · verified Fri Apr 10

python-calamine is a Python binding for the Rust library 'calamine', designed for fast reading of Excel (.xlsx, .xls, .xlsb) and ODF (.ods) spreadsheet files. It is actively maintained, with version 0.6.2 released in February 2026, indicating a regular release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to open an Excel file using `CalamineWorkbook.from_path`, retrieve sheet names, and extract data into a Python list of lists. By default, `python-calamine` skips empty rows and columns, but this behavior can be altered using `skip_empty_area=False` when calling `to_python()` on a sheet. For `pandas` users, versions 2.2 and above have built-in support for the 'calamine' engine in `read_excel`.

import os
from python_calamine import CalamineWorkbook

# Create a dummy Excel file for demonstration
# In a real scenario, 'file.xlsx' would already exist.
# For this quickstart, we'll simulate reading a file.
# You would replace 'file.xlsx' with your actual file path.

# Placeholder for creating a file, as we cannot write to disk directly in this environment.
# Assume 'dummy_file.xlsx' exists with at least one sheet named 'Sheet1'
# and some data like [['1', '2', '3'], ['4', '5', '6']].

try:
    # Attempt to open a non-existent file to demonstrate error handling
    # In a real application, ensure the file exists.
    workbook = CalamineWorkbook.from_path('dummy_file.xlsx')
    print(f"Sheet names: {workbook.sheet_names}")
    
    # Get data from the first sheet
    if workbook.sheet_names:
        sheet_data = workbook.get_sheet_by_name(workbook.sheet_names[0]).to_python()
        print(f"Data from '{workbook.sheet_names[0]}': {sheet_data}")
    
    # Example with skipping empty areas (default is True)
    # To suppress this, set skip_empty_area=False
    # sheet_data_with_empty = workbook.get_sheet_by_name(workbook.sheet_names[0]).to_python(skip_empty_area=False)
    # print(f"Data (including empty): {sheet_data_with_empty}")

except FileNotFoundError:
    print("Please ensure 'dummy_file.xlsx' exists in the current directory or provide a valid path.")
    print("For example, create a simple Excel file with content and try again.")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →