# Excel reports. Python simplicity.

Turn Python data into Excel workbooks — from everyday reports to large exports. Read and write **XLSB** and **XLSX**, export DataFrames, and refresh existing **XLSM** templates while preserving their macros.

[![PyPI](<https://img.shields.io/pypi/v/xlspy?color=2f9e8f&amp;label=PyPI>)](<https://pypi.org/project/xlspy/>) [![Python versions](<https://img.shields.io/pypi/pyversions/xlspy?color=2f9e8f>)](<https://pypi.org/project/xlspy/>) [![MIT license](<https://img.shields.io/badge/license-MIT-2f9e8f>)](<https://github.com/justybase/xlspy/blob/main/LICENSE>) [![CI](<https://github.com/justybase/xlspy/actions/workflows/ci.yml/badge.svg?branch=main>)](<https://github.com/justybase/xlspy/actions/workflows/ci.yml>)

[Start the tutorial](<https://justybase.github.io/xlspy/learn/index.md>) [API reference](<https://justybase.github.io/xlspy/api/index.md>)

`pip install xlspy`

## Why xlspy

### Fast by default

2.5 million cells in under a second as XLSB. The native Rust extension accelerates reads, writes and `load_workbook()`.

### XLSB and XLSX

One API for both formats: `XlsxWriter` and `XlsbWriter` take the same rows, styles, charts and tables.

### DataFrames included

Export pandas or polars directly with `to_xlsx()` / `to_xlsb()`, or stream rows from a database cursor.

### Templates preserved

Refresh data in XLSM templates without touching the VBA project, drawings or unrelated sheets.

### No required dependencies

The core library has no required Python packages. Pandas and polars are optional extras.

### Excel not required

Create and read workbooks on Linux, Windows or macOS. Microsoft Excel is not needed for the core APIs.

## Your first report

```
from xlspy import F, Style, XlsxWriter

rows = [
    ["Product", "Units", "Revenue"],
    ["Coffee", 120, (12500, F.THOUSANDS_SEP)],
    ["Tea", 90, (8400, F.THOUSANDS_SEP)],
    ["Juice", 45, (5100, F.THOUSANDS_SEP)],
]

with XlsxWriter("sales.xlsx") as workbook:
    workbook.add_sheet("Sales")
    workbook.write_sheet(
        rows,
        header_style=Style(bold=True, fill="#183C52", font_color="#FFFFFF"),
        freeze_panes="A2",
    )
```

For binary output, change `XlsxWriter` to `XlsbWriter` and the filename to `.xlsb`. The rest of the code stays the same.

[Build this report step by step →](<https://justybase.github.io/xlspy/learn/first-workbook/index.md>)

## Performance at a glance

50,000 × 50 cells (2.5 million cells), Windows 11, AMD Ryzen 7 7840HS:

|  | xlspy XLSB | xlspy XLSX | xlsxwriter | openpyxl |
| :--- | ---: | ---: | ---: | ---: |
| Write | **0.67 s** | **1.16 s** | 11.71 s | 20.39 s |
| Read | **0.22 s** | **0.98 s** | — | 14.35 s |

[Full benchmarks and methodology →](<https://justybase.github.io/xlspy/performance/index.md>)

## Start here

### [Learn xlspy](<https://justybase.github.io/xlspy/learn/index.md>)

A ten-step tutorial: install, write your first workbook, style it, add formulas and charts, read it back.

### [How-to guides](<https://justybase.github.io/xlspy/guide/index.md>)

Task-focused pages: choose a format, stream large exports, update templates, add pivots, comments and protection.

### [API reference](<https://justybase.github.io/xlspy/api/index.md>)

Every public class and function, generated from the docstrings, with signatures and examples.

### [Explanation](<https://justybase.github.io/xlspy/explanation/index.md>)

Architecture, performance, validation and the openpyxl parity matrix — the reasoning behind the library.

## Works with your stack

| Workflow | Entry point |
| :--- | :--- |
| pandas or polars | `to_xlsx(df, "report.xlsx")`, `to_xlsb(df, "report.xlsb")` |
| Existing Excel template | `XlsxUpdater`, `XlsmUpdater`, `XlsbUpdater` |
| Database cursor | `writer.write_sheet(cursor_rows(cursor))` |
| Random access and edits | `load_workbook(path)` |
| Values only, fastest | `ExcelReader(path).get_rows(sheet)` |

[Examples](<https://github.com/justybase/xlspy/blob/main/examples/README.md>) · [Changelog](<https://github.com/justybase/xlspy/blob/main/CHANGELOG.md>) · [GitHub](<https://github.com/justybase/xlspy>)
