XlsxWriter

A Python module for creating fully-featured Excel XLSX files with charts, formatting, and formulas

Library
PyPI
v3.2.9
3,968stars
BSD-2-Clause

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
64/100Good
Development Activity56
Maintenance16
Community84
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
74/100Good
Architecture75
Code Quality82
Innovation62
Learning Curve78

XlsxWriter is a pure-Python library for generating Excel 2007+ XLSX files from scratch. It produces 100% Excel-compatible spreadsheets covering text, numbers, formulas, hyperlinks, merged cells, defined names, and native Excel charts, and supports Python 3.8+ and PyPy3 using only the standard library — no external dependencies required.

Beyond basic cell writing, it handles advanced worksheet features like autofilters, data validation with dropdown lists, conditional formatting, embedded images in multiple formats, rich multi-format strings, cell comments, textboxes, and VBA macros, plus a memory-optimization mode for writing very large files without exhausting RAM. It also integrates directly with Pandas and Polars as an output engine, making it a common choice for data-export pipelines that need richly formatted Excel output rather than a plain CSV-to-XLSX conversion.

What You Get

  • A Workbook/Worksheet API for writing text, numbers, formulas, and hyperlinks with full cell formatting
  • Native Excel chart generation (bar, line, pie, scatter, radar, stock, and more)
  • Data validation, autofilters, conditional formatting, and defined names
  • Image embedding (PNG/JPEG/GIF/BMP/WMF/EMF), textboxes, cell comments, and VBA macro support
  • A memory-optimization (constant-memory) mode for writing very large workbooks
  • Direct integration as a Pandas/Polars Excel writer engine

Common Use Cases

  • Exporting Pandas/Polars DataFrames to richly formatted Excel reports instead of plain CSV
  • Generating scheduled business reports with charts, conditional formatting, and branded styling
  • Building large data-export files where memory-constant streaming mode avoids excessive RAM use
  • Producing Excel templates programmatically for finance, ops, or analytics teams who consume XLSX directly

Under The Hood

Architecture: The library is organized around a Workbook object that owns one or more Worksheet/Chartsheet instances, with dedicated modules for each XLSX subsystem — chart_*.py files per chart type, format.py for cell styling, drawing.py and image.py for embedded media, comments.py, custom.py (custom document properties), and packager.py, which is responsible for assembling all the generated XML parts into the final ZIP-based XLSX container per the OOXML spec. This mirrors the actual internal structure of an XLSX file (a ZIP of XML parts plus relationships/content-type manifests), which is also reflected in contenttypes.py and relationships.py.

Tech Stack: Pure Python (99%+ of the codebase) with zero runtime dependencies, targeting Python 3.8+ and PyPy3. It ships its own XML-writing layer rather than depending on a general-purpose XML library, keeping the install footprint minimal — a deliberate design choice given how often this library is pulled in transitively via Pandas/Polars Excel export.

Code Quality: The project has an unusually large test suite — over 1,280 test files under xlsxwriter/test/ — reflecting the fact that XLSX is a strict binary/XML format where subtle output differences break Excel compatibility, so most tests appear to be golden-file comparisons against known-good XLSX output. With 58 contributors but the vast majority of commits (1,391 of ~1,491 total) from the original author, this is a mature, long-running single-maintainer project (13+ years) with occasional external contributions rather than a broad contributor base.

API Design: The core API is intentionally simple for common cases — workbook.add_worksheet(), worksheet.write(), workbook.close() — with formatting and advanced features layered on via optional add_format()/insert_image()-style calls, so a basic script needs only a few lines while advanced features (charts, validation, VBA) are opt-in and don’t complicate the simple path. Extensive documentation and a working example in the README lower the barrier to entry significantly for a domain (OOXML) that is otherwise quite complex to hand-roll.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search