Skip to content

One XLSX engine for Rust and Python.

Change one import, and your openpyxl code runs on a Rust engine. Large sheets stream within a memory limit that you set. Edits rewrite only what you change, so charts, macros and pivot tables stay intact.

Install

cargo add crabxl

Use Rust 1.88 or newer.

Code examples

The Python sample is plain openpyxl code with one changed import. In Rust, row and column numbers start at zero.

use crabxl::{CellAddress, CellValue, SaveOptions, WorkbookEditor, WorkbookReader};

fn main() -> crabxl::Result<()> {
    // Stream the cells that are present, row by row
    let mut workbook = WorkbookReader::open("input.xlsx")?;
    let mut rows = workbook.rows("Sheet1")?;
    while let Some(row) = rows.next_row()? {
        for cell in row.cells {
            println!("{:?}: {:?}", cell.address, cell.value);
        }
    }

    // Edit one value and keep everything else as it was
    let mut editor = WorkbookEditor::open("input.xlsx")?;
    editor.set_value("Sheet1", CellAddress::new(0, 0)?, CellValue::Integer(42))?;
    editor.save_path("output.xlsx", SaveOptions::default())?;
    Ok(())
}

Features

#CapabilityDetails
openpyxl compatible

Write import crabxl as openpyxl, and existing code keeps working. Charts, pivot tables, images and VBA work through the openpyxl API. openpyxl is not a dependency.

Write import crabxl as openpyxl, and existing code keeps working. Charts, pivot tables, images and VBA work through the openpyxl API. openpyxl is not a dependency.
Edit in place

openpyxl rebuilds the whole file on save, and its docs warn that some content gets lost. CrabXL rewrites only the parts you change. Everything else keeps its original bytes.

openpyxl rebuilds the whole file on save, and its docs warn that some content gets lost. CrabXL rewrites only the parts you change. Everything else keeps its original bytes.
Stream large sheets

Read rows in batches instead of loading the whole sheet. Empty cells take no memory. Use read_sheet when you want the full sheet at once.

Read rows in batches instead of loading the whole sheet. Empty cells take no memory. Use read_sheet when you want the full sheet at once.
Memory limit

Set a memory limit, or choose Auto. Auto picks streaming or full loading for you. CrabXL can move shared strings to disk.

Set a memory limit, or choose Auto. Auto picks streaming or full loading for you. CrabXL can move shared strings to disk.
Write row by row

Write a new workbook one row at a time, even to several sheets at once. Memory use stays constant, however many rows you add.

Write a new workbook one row at a time, even to several sheets at once. Memory use stays constant, however many rows you add.
Exact values

Integers too large for a float stay exact. Dates stay dates, and rich text keeps its formatting. Formulas keep the results that Excel saved.

Integers too large for a float stay exact. Dates stay dates, and rich text keeps its formatting. Formulas keep the results that Excel saved.
Formula calculation

Save with calculate=True and CrabXL calculates every formula first. Readers that skip calculation, such as pandas or openpyxl with data_only=True, then see current results. openpyxl cannot calculate formulas.

Save with calculate=True and CrabXL calculates every formula first. Readers that skip calculation, such as pandas or openpyxl with data_only=True, then see current results. openpyxl cannot calculate formulas.
Compression

Choose a Deflate level from 0 to 9. The default is 6. The default backend is zlib-rs, written in Rust. Native zlib is optional.

Choose a Deflate level from 0 to 9. The default is 6. The default backend is zlib-rs, written in Rust. Native zlib is optional.

Benchmarks

Each case runs in a new Python process, pinned to one CPU. Every library comes from PyPI. Time includes Python start-up. Read the method and all results.

NYC 311 sample saved by Excel: 1,000,001 real service requests, 41 columns, 210 MiB.

Time, lower is better
  • CrabXLread_only15.48 s
  • fastexcel17.46 s
  • CrabXL17.70 s
  • wolfxlread_only21.21 s
  • python-calamineiter_rows23.19 s
  • python-calamineto_python26.07 s
Peak memory, lower is better
  • CrabXLread_only167 MiB
  • wolfxlread_only802 MiB
  • CrabXL1,830 MiB
  • python-calamineiter_rows2,500 MiB
  • fastexcel2,656 MiB
  • python-calamineto_python4,023 MiB