Python binding for Rust's library for reading excel and odf file - calamine
Project Links
Meta
Author: Dmitriy <dimastbk@proton.me>
Requires Python: >=3.8
Classifiers
Development Status
- 4 - Beta
License
- OSI Approved :: MIT License
Programming Language
- Rust
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
python-calamine
Python binding for beautiful Rust's library for reading excel and odf file - calamine.
Is used
Installation
Pypi:
pip install python-calamine
Conda:
conda install -c conda-forge python-calamine
Example
from python_calamine import CalamineWorkbook
workbook = CalamineWorkbook.from_path("file.xlsx")
workbook.sheet_names
# ["Sheet1", "Sheet2"]
workbook.get_sheet_by_name("Sheet1").to_python()
# [
# ["1", "2", "3", "4", "5", "6", "7"],
# ["1", "2", "3", "4", "5", "6", "7"],
# ["1", "2", "3", "4", "5", "6", "7"],
# ]
By default, calamine skips empty rows/cols before data. For suppress this behaviour, set skip_empty_area
to False
.
from python_calamine import CalamineWorkbook
workbook = CalamineWorkbook.from_path("file.xlsx").get_sheet_by_name("Sheet1").to_python(skip_empty_area=False)
# [
# [", ", ", ", ", ", "],
# ["1", "2", "3", "4", "5", "6", "7"],
# ["1", "2", "3", "4", "5", "6", "7"],
# ["1", "2", "3", "4", "5", "6", "7"],
# ]
Also, you can use monkeypatch for pandas for use this library as engine in read_excel()
(only pandas 2.0 and 2.1 are supported).
Pandas 2.2 and above have built-in support of python-calamine.
from pandas import read_excel
from python_calamine.pandas import pandas_monkeypatch
pandas_monkeypatch()
read_excel("file.xlsx", engine="calamine")
# 1 2 3 4 5 6 7
# 0 1 2 3 4 5 6 7
# 1 1 2 3 4 5 6 7
Also, you can find additional examples in tests.
Development
You'll need rust installed.
# clone this repo or your fork
git clone git@github.com:dimastbk/python-calamine.git
cd python-calamine
# create a new virtual env
python3 -m venv env
source env/bin/activate
# install dev dependencies and install python-calamine
pip install -e .[dev]
# lint code
pre-commit run --all-files
# test code
pytest
Apr 02, 2025
0.3.2
Nov 06, 2024
0.3.1
Nov 04, 2024
0.3.0
Jul 18, 2024
0.2.3
Jul 15, 2024
0.2.2
Feb 29, 2024
0.2.0
Dec 01, 2023
0.1.7
Sep 04, 2023
0.1.6
Sep 04, 2023
0.1.5
Jun 28, 2023
0.1.4
Jun 13, 2023
0.1.3
May 23, 2023
0.1.2
May 01, 2023
0.1.1
Mar 26, 2023
0.1.0
Feb 06, 2023
0.0.8
Jan 27, 2023
0.0.7
Jan 09, 2023
0.0.6
Nov 09, 2022
0.0.5
Oct 26, 2022
0.0.4
Oct 06, 2021
0.0.3
Sep 02, 2021
0.0.2