[!IMPORTANT]
pyopenxlsx uses OpenXLSX-NX (v1.0.0+), a specialized C++ fork that includes critical performance optimizations and functional enhancements (such as agile encryption, streaming I/O, vector shapes, threaded comments, and custom properties) not currently available in the upstream repository.
pyopenxlsx is a high-performance Python binding for the OpenXLSX-NX C++ library. It aims to provide significantly faster read/write speeds compared to pure Python libraries like openpyxl, while maintaining a Pythonic API design.
Core Features
High Performance: Powered by the modern C++17 OpenXLSX-NX library.
Pythonic API: Intuitive interface with properties, iterators, and context managers.
Streaming I/O: Bypass the DOM entirely with XLStreamWriter and XLStreamReader for memory-efficient bulk data processing.
Security: Full support for ECMA-376 Standard and Agile Encryption (read/write password-protected files) and granular worksheet protection.
Async Support: async/await support for key I/O operations.
Rich Styling: Comprehensive support for fonts, fills, borders, alignments, and number formats.
Extended Metadata: Support for both standard and custom document properties.
Advanced Content: Support for images, vector shapes, hyperlinks (external/internal), and modern threaded comments.
Memory Safety: Combines C++ efficiency with Python's automatic memory management.
Performance: object path vs bulk path
Prefer bulk / native APIs for hot loops; per-cell Cell wrappers are convenient but allocate Python objects.
Date/datetime writes apply a default number format when Workbook.auto_date_formats is True (default). Set wb.auto_date_formats = False to keep raw Excel serial floats without style changes.
Async and threading notes
Async helpers (save_async, write_rows_async, load_workbook_async, …) use asyncio.to_thread and do not make a single workbook safe for concurrent writers.
Do not share one Workbook / Worksheet across threads for simultaneous mutation; use one book per task or serialize access.
Prefer bulk sync APIs inside a single to_thread call over many fine-grained *_async calls (thread-pool overhead).
While openpyxl is a great pure-Python library, pyopenxlsx is designed to solve critical performance bottlenecks and add modern enterprise features by leveraging a C++ engine.
Feature / Capability
pyopenxlsx (OpenXLSX-NX)
openpyxl
Notes
Underlying Engine
C++17 (nanobind wrapped)
Pure Python
pyopenxlsx is heavily optimized for low-level memory management.
Execution Speed
Extremely Fast (Up to 160x)
Slower
Pure Python loop overhead makes parsing large files sluggish.
Memory Footprint
Minimal (C++ Memory Mapping)
High
Parsing large files in openpyxl often leads to OOM errors.
Asyncio Support
✅ Native (await load_workbook_async)
❌ No
pyopenxlsx offloads heavy I/O to a threadpool, perfect for Web APIs (FastAPI/Django).
Agile Encryption (Passwords)
✅ Native Read & Write
❌ No
openpyxl cannot read/write password-protected .xlsx files without 3rd-party decryption tools.
Threaded Comments
✅ Full Support (Conversations/Replies)
❌ No / Can be lost
pyopenxlsx supports modern Excel conversational comments and resolution states.
pyopenxlsx reuses style indices, saving massive amounts of memory on huge datasets.
Charts
⚠️ Basic (Bar, Line, etc.)
✅ Highly Advanced
openpyxl currently has more mature support for extremely complex/3D charts.
Environment
Pre-compiled Wheels required
Any Python env
pyopenxlsx provides wheels for major OS/Architectures via CI.
Installation
From PyPI (Recommended)
# Using pip
pip install pyopenxlsx
# Using uv
uv pip install pyopenxlsx
From Source
# Using uv
uv pip install .
# Or using pip
pip install .
Development Installation
uv pip install -e .
Quick Start
Create and Save a Workbook
from pyopenxlsx import Workbook
# Create a new workbook
with Workbook() as wb:
ws = wb.active
ws.title = "MySheet"
# Write data
ws["A1"].value = "Hello"
ws["B1"].value = 42
ws.cell(row=2, column=1).value = 3.14
# Save
wb.save("example.xlsx")
Custom Properties
from pyopenxlsx import Workbook
with Workbook() as wb:
# Set custom document properties
wb.custom_properties["Author"] = "Curry Tang"
wb.custom_properties["Project"] = "PyOpenXLSX"
wb.save("props.xlsx")
Hyperlinks
from pyopenxlsx import Workbook
with Workbook() as wb:
ws = wb.active
# One-shot helper: set display text + link (URL → external automatically)
ws.link("A1", "https://www.google.com", text="Google", tooltip="Search")
# Or explicit external / internal APIs
ws.add_hyperlink("A1", "https://www.google.com", tooltip="Search")
ws2 = wb.create_sheet("Data")
ws.link("A2", "Data!A1", text="See Data", internal=True)
wb.save("links.xlsx")
Defined Names (Named Ranges)
from pyopenxlsx import Workbook
with Workbook() as wb:
ws = wb.active
ws.write_rows(1, [["x"], [1], [2], [3]])
# Prefer define() — idempotent; accepts sheet title or Worksheet
wb.defined_names.define("SalesCol", "Sheet1!$A$2:$A$4")
wb.defined_names.define("LocalX", "Sheet1!$A$1", sheet=ws)
assert "SalesCol" in wb.defined_names
assert wb.defined_names["SalesCol"].refers_to() == "Sheet1!$A$2:$A$4"
wb.save("names.xlsx")
For writing massive datasets without consuming memory for Python objects, use the direct stream writer. Date/datetime values follow the same coercion and auto_date_formats rules as bulk writes.
from datetime import date
from pyopenxlsx import Workbook
with Workbook() as wb:
ws = wb.active
with ws.stream_writer() as writer:
writer.append_row(["ID", "When", "Value"])
for i in range(1_000_000):
writer.append_row([i, date(2023, 1, 1), 99.9])
wb.save("massive_data.xlsx")
API Documentation
The full API documentation has been split into individual modules for easier reading. Please refer to the docs/ directory:
pyopenxlsx is built for speed. By leveraging the C++ OpenXLSX-NX engine and providing optimized bulk operations, it significantly outperforms pure-Python alternatives.
Note: The following benchmarks were recorded on an Apple Silicon (arm64) M-series processor, comparing pyopenxlsx v1.3.1 against openpyxl.
Running benchmarks
# Developer suite (recommended; skips ~1M extreme writes)
uv run pytest tests/test_benchmark.py -m benchmark_fast --benchmark-only -q
# Extreme ~1M-cell writes (slow)
uv run pytest tests/test_benchmark.py -m benchmark_extreme --benchmark-only -q
# Export + compare against a baseline JSON
uv run pytest tests/test_benchmark.py -m benchmark_fast \
--benchmark-only --benchmark-json=benchmark.json
uv run python scripts/compare_benchmarks.py baseline.json benchmark.json
Groups include fair same-dtype writes (write_large_str / write_large_float),
date coercion (write_large_dates), mixed types, split read (read_point vs
read_scan), and symmetric iterate (iterate_cell / iterate_values).
Benchmarks (pyopenxlsx vs openpyxl)
Scenario
pyopenxlsx
openpyxl
Speedup
Load File (20,000 cells)
~2.5ms
~169.0ms
67x
Single Read (1 cell in large doc)
~4.4ms
~181.7ms
41x
Bulk Read / Iterate (20,000 cells)
~10.0ms
~136.3ms*
13.6x
Write Small (1,000 cells)
~3.5ms
~8.0ms
2.2x
Write Large (50,000 cells)
~95.1ms
~316.9ms
3.3x
Bulk Write Large (50,000 cells, numpy/range)
~17.4ms
N/A
18.2x
Extreme Write (1,000,000 cells)
~567ms
~6,172ms
10.8x
Bulk Write Extreme (1,000,000 cells, numpy)
~330ms
N/A
18.7x
* openpyxl bulk read timed using values_only=True.
Resource Usage (1,000,000 cells)
Library
Execution Time
Memory Delta
CPU Load
pyopenxlsx (bulk write)
~0.33s
~200 MB
~99%
openpyxl
~6.17s
~600 MB*
~99%
[!NOTE]
*Memory delta for openpyxl can be misleading due to Python's garbage collection timing during the benchmark. However, pyopenxlsx consistently shows lower memory pressure for bulk operations as data is handled primarily in C++.
Why is it faster?
C++ Foundation: Core operations happen in highly optimized C++. Recent updates eliminated shared_ptr heap allocations and deep copies for zero-allocation performance during high-throughput tasks.
Reduced Object Overhead: pyopenxlsx minimizes the creation of many Python Cell objects during bulk operations.
Efficient Memory Mapping: Leverages the memory-efficient design of OpenXLSX-NX.
Asynchronous I/O: Key operations are available as non-blocking coroutines to maximize throughput in concurrent applications.
Development
Run Tests
# Run all tests
uv run pytest
# With coverage
uv run pytest --cov=src/pyopenxlsx --cov-report=term-missing
License
BSD 3-Clause License.
The underlying OpenXLSX-NX library is licensed under the MIT License, and nanobind under a BSD-style license.
Alternatives
Use instead of pyopenxlsx: tools that do the same job, closest first.
Openpyxl-compatible Excel library with a Rust backend: speed up openpyxl code with one import change and edit .xlsx templates without losing formatting, conditional formatting, or data validation. WolfXL 2.0.21 measured 6.7-12.0x faster than openpyxl 3.1.5 on the committed read/write benchmark (small-file gains vary). MIT.