Skip to main content

Write compact XLSX files from pandas DataFrames.

Project description

CompactXLSX

Write smaller XLSX files from pandas.

CompactXLSX is a focused, pure-Python writer for exporting pandas DataFrames to minimal XLSX workbooks. It writes OOXML directly, stores repeated text in a shared-string table, and applies maximum ZIP compression by default.

Why CompactXLSX?

  • One-line DataFrame export.
  • Multiple worksheets from an ordered mapping.
  • Small OOXML payload with shared strings.
  • Native Excel cells for numbers and booleans.
  • Optional compact header style.
  • Atomic output replacement and configurable ZIP compression.
  • No spreadsheet engine, Java runtime, or Rust toolchain required.

CompactXLSX is intended for large, data-only exports. It is not a replacement for a full spreadsheet authoring library such as XlsxWriter or openpyxl.

Installation

pip install compactxlsx

For local development:

python -m pip install -e '.[test]'

Quick start

import pandas as pd

from compactxlsx import write_xlsx

df = pd.DataFrame(
    {
        "name": ["Alice", "Bob", "Alice"],
        "score": [91.5, 88.0, 95.0],
        "active": [True, False, True],
    }
)

write_xlsx(df, "report.xlsx")

Multiple worksheets:

write_xlsx(
    {
        "Students": students_df,
        "Classes": classes_df,
    },
    "school-report.xlsx",
    index=False,
    header_style=True,
    compression=9,
)

Recompress an existing workbook without changing its OOXML parts:

from compactxlsx import recompress_xlsx

before, after = recompress_xlsx("report.xlsx")
print(f"saved {before - after:,} bytes")

For migration from the original helper, save_excel_compressed() remains as an alias of write_xlsx().

Supported data

CompactXLSX writes missing values as blank cells, booleans as Excel booleans, and finite integers/floats as Excel numbers. Strings are stored in one shared string table. Dates, timedeltas, categories, and other Python objects are currently exported as their string representation. Integers outside Excel's exact IEEE-754 range are stored as text to prevent silent precision loss.

Scope and limitations

  • XLSX output only.
  • Data-only worksheets; no formulas, charts, images, merged cells, filters, or arbitrary cell formatting.
  • Header styling is intentionally limited to one built-in style.
  • The complete pandas DataFrame and all unique strings must fit in memory.
  • File-size reduction depends on the input. Repeated text generally benefits more than high-cardinality text.
  • recompress_xlsx() changes ZIP compression only; it does not remove styles, images, worksheets, or workbook features.

Benchmark

Run the included reproducible benchmark instead of relying on a universal compression claim:

PYTHONPATH=src python benchmarks/benchmark.py --rows 100000

The benchmark reports write time and output size. If openpyxl or XlsxWriter is installed, it includes them as comparison writers.

Development

python -m pip install -e '.[test]'
python -m unittest discover -s tests -v

See CONTRIBUTING.md for contribution guidelines.

License

MIT. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

compactxlsx-0.1.0.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

compactxlsx-0.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file compactxlsx-0.1.0.tar.gz.

File metadata

  • Download URL: compactxlsx-0.1.0.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for compactxlsx-0.1.0.tar.gz
Algorithm Hash digest
SHA256 31bf2df24ef39042c4b9961d0955c5ae1578335975e9b65c5ae69b0d475f8693
MD5 96edfff8487be4d35403a8951a578196
BLAKE2b-256 fefc77e32ffb016624f7051d8c745eba88f50211e41d57f39fd63f623b52a929

See more details on using hashes here.

Provenance

The following attestation bundles were made for compactxlsx-0.1.0.tar.gz:

Publisher: publish.yml on wapecheng/compactxlsx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file compactxlsx-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: compactxlsx-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for compactxlsx-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e71735ccfcc34f1803395541b92811bc8dfb487691bcd20b261f7273f6068cbb
MD5 5dee1e8d1549f641b0d464d00e6e61a5
BLAKE2b-256 4f66a10bbb15bf0ec40bfdd73d89805306bd2d6fc8abd8264385245689b498a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for compactxlsx-0.1.0-py3-none-any.whl:

Publisher: publish.yml on wapecheng/compactxlsx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page