Skip to content

Getting Started

Rahmad Afandi edited this page Jun 7, 2026 · 1 revision

Getting Started

Install

pip install rustpy-xlsxwriter

Prebuilt wheels ship for CPython 3.8–3.14 (and PyPy) on Linux, macOS, and Windows. No Rust toolchain needed to install.

First file

from rustpy_xlsxwriter import FastExcel

records = [
    {"name": "Alice", "age": 30, "active": True},
    {"name": "Bob",   "age": 25, "active": False},
]

FastExcel("out.xlsx").sheet("People", records).save()

The first row's keys become the header row; column types are detected from row 1 and cached for the rest.

Builder options

FastExcel is a fluent builder — chain configuration, then .save():

(
    FastExcel("report.xlsx", password="s3cret")
    .format(float_format="0.00", bold_headers=True, index_columns=["ID"])
    .freeze(row=1, col=1)
    .sheet("Users", user_records)
    .sheet("Orders", order_records)
    .save()
)
Option Where Meaning
password constructor Worksheet-protection flag (NOT encryption — see Limitations)
autofit constructor Approx column auto-width (default True)
sanitize_formulas constructor CSV-only formula-injection guard (default False)
float_format .format() Excel number format for floats, e.g. "0.00"
datetime_format .format() Default "yyyy-mm-ddThh:mm:ss"
bold_headers .format() Bold the header row
index_columns .format() Column names rendered bold
freeze(row, col, sheet=) .freeze() Freeze panes (per-sheet or all)

Accepted input

.sheet(name, data) accepts:

  • a list of dicts (or a generator of dicts — memory-efficient streaming),
  • a pandas DataFrame,
  • a polars DataFrame,
  • anything exposing __arrow_c_stream__ (Arrow zero-copy).

See DataFrames.

Output targets

import io, pathlib

FastExcel("out.xlsx")                      # str path
FastExcel(pathlib.Path("out.xlsx"))        # os.PathLike
FastExcel(io.BytesIO())                    # writable binary buffer

Format is auto-detected from the extension: .xlsx → Excel, .csv → CSV, .tsv → TSV.

Context manager

with FastExcel("out.xlsx") as f:
    f.sheet("Users", user_records)
    f.sheet("Orders", order_records)
# auto-saves on exit

Clone this wiki locally