hypaxel 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hypaxel-0.4.0/LICENSE +202 -0
- hypaxel-0.4.0/NOTICE +5 -0
- hypaxel-0.4.0/PKG-INFO +355 -0
- hypaxel-0.4.0/README.md +331 -0
- hypaxel-0.4.0/hypaxel/__init__.py +611 -0
- hypaxel-0.4.0/hypaxel/_hypaxel.pyi +188 -0
- hypaxel-0.4.0/hypaxel/py.typed +0 -0
- hypaxel-0.4.0/hypaxel/starlette.py +56 -0
- hypaxel-0.4.0/pyproject.toml +40 -0
- hypaxel-0.4.0/python/.gitignore +6 -0
- hypaxel-0.4.0/python/Cargo.lock +248 -0
- hypaxel-0.4.0/python/Cargo.toml +17 -0
- hypaxel-0.4.0/python/LICENSE +202 -0
- hypaxel-0.4.0/python/NOTICE +5 -0
- hypaxel-0.4.0/python/README.md +331 -0
- hypaxel-0.4.0/python/benchmarks/bench.py +142 -0
- hypaxel-0.4.0/python/benchmarks/read_bench.py +181 -0
- hypaxel-0.4.0/python/benchmarks/results/python-1m.json +119 -0
- hypaxel-0.4.0/python/benchmarks/results/python-read-1m.json +107 -0
- hypaxel-0.4.0/python/benchmarks/results/python-read.json +105 -0
- hypaxel-0.4.0/python/benchmarks/results/python.json +119 -0
- hypaxel-0.4.0/python/rustfmt.toml +2 -0
- hypaxel-0.4.0/python/scripts/smoke.py +17 -0
- hypaxel-0.4.0/python/src/lib.rs +821 -0
- hypaxel-0.4.0/python/src/reader.rs +509 -0
- hypaxel-0.4.0/python/tests/test_hypaxel.py +473 -0
- hypaxel-0.4.0/python/tests/test_reader.py +434 -0
- hypaxel-0.4.0/rust/Cargo.toml +12 -0
- hypaxel-0.4.0/rust/hypaxel/Cargo.toml +63 -0
- hypaxel-0.4.0/rust/hypaxel/LICENSE +202 -0
- hypaxel-0.4.0/rust/hypaxel/NOTICE +5 -0
- hypaxel-0.4.0/rust/hypaxel/README.md +390 -0
- hypaxel-0.4.0/rust/hypaxel/benches/write.rs +128 -0
- hypaxel-0.4.0/rust/hypaxel/examples/profile_rows.rs +32 -0
- hypaxel-0.4.0/rust/hypaxel/examples/read_bench.rs +148 -0
- hypaxel-0.4.0/rust/hypaxel/examples/write_bench.rs +112 -0
- hypaxel-0.4.0/rust/hypaxel/src/cell.rs +368 -0
- hypaxel-0.4.0/rust/hypaxel/src/engine.rs +865 -0
- hypaxel-0.4.0/rust/hypaxel/src/error.rs +110 -0
- hypaxel-0.4.0/rust/hypaxel/src/fit.rs +412 -0
- hypaxel-0.4.0/rust/hypaxel/src/lib.rs +118 -0
- hypaxel-0.4.0/rust/hypaxel/src/options.rs +278 -0
- hypaxel-0.4.0/rust/hypaxel/src/parts.rs +134 -0
- hypaxel-0.4.0/rust/hypaxel/src/read/mod.rs +511 -0
- hypaxel-0.4.0/rust/hypaxel/src/read/sheet.rs +840 -0
- hypaxel-0.4.0/rust/hypaxel/src/read/sst.rs +110 -0
- hypaxel-0.4.0/rust/hypaxel/src/read/styles.rs +186 -0
- hypaxel-0.4.0/rust/hypaxel/src/read/table.rs +156 -0
- hypaxel-0.4.0/rust/hypaxel/src/read/value.rs +339 -0
- hypaxel-0.4.0/rust/hypaxel/src/read/xml.rs +777 -0
- hypaxel-0.4.0/rust/hypaxel/src/read/zip.rs +347 -0
- hypaxel-0.4.0/rust/hypaxel/src/record_io.rs +161 -0
- hypaxel-0.4.0/rust/hypaxel/src/ser.rs +1121 -0
- hypaxel-0.4.0/rust/hypaxel/src/style.rs +680 -0
- hypaxel-0.4.0/rust/hypaxel/src/table.rs +400 -0
- hypaxel-0.4.0/rust/hypaxel/src/writer.rs +309 -0
- hypaxel-0.4.0/rust/hypaxel/src/xml.rs +185 -0
- hypaxel-0.4.0/rust/hypaxel/src/zip.rs +274 -0
- hypaxel-0.4.0/rust/hypaxel/tests/async_io.rs +68 -0
- hypaxel-0.4.0/rust/hypaxel/tests/common/mod.rs +66 -0
- hypaxel-0.4.0/rust/hypaxel/tests/layout.rs +299 -0
- hypaxel-0.4.0/rust/hypaxel/tests/reader.rs +984 -0
- hypaxel-0.4.0/rust/hypaxel/tests/records.rs +166 -0
- hypaxel-0.4.0/rust/hypaxel/tests/writer.rs +342 -0
hypaxel-0.4.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 vensas GmbH
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
hypaxel-0.4.0/NOTICE
ADDED
hypaxel-0.4.0/PKG-INFO
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hypaxel
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Classifier: Programming Language :: Rust
|
|
5
|
+
Classifier: Programming Language :: Python :: 3
|
|
6
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
7
|
+
Classifier: Topic :: Office/Business :: Financial :: Spreadsheet
|
|
8
|
+
Classifier: Typing :: Typed
|
|
9
|
+
Requires-Dist: pandas>=1.5 ; extra == 'pandas'
|
|
10
|
+
Requires-Dist: polars>=0.20 ; extra == 'polars'
|
|
11
|
+
Requires-Dist: starlette>=0.27 ; extra == 'starlette'
|
|
12
|
+
Provides-Extra: pandas
|
|
13
|
+
Provides-Extra: polars
|
|
14
|
+
Provides-Extra: starlette
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
License-File: NOTICE
|
|
17
|
+
Summary: High-performance, constant-memory streaming XLSX (Excel) writer and reader for Python, powered by Rust.
|
|
18
|
+
Keywords: excel,xlsx,spreadsheet,streaming,fastapi,pandas,polars
|
|
19
|
+
License-Expression: Apache-2.0
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
22
|
+
Project-URL: Repository, https://github.com/vensas/hypaxel
|
|
23
|
+
|
|
24
|
+
# Hypaxel for Python
|
|
25
|
+
|
|
26
|
+
**High-performance, constant-memory XLSX (Excel) writer and streaming reader for Python, powered by Rust.**
|
|
27
|
+
|
|
28
|
+
Hypaxel writes `.xlsx` files as a forward-only stream. Rows are converted, serialized and compressed
|
|
29
|
+
in native code as you write them, so memory stays flat whether you export 10 rows or 10 million.
|
|
30
|
+
It can stream a download to the browser while your query is still running.
|
|
31
|
+
|
|
32
|
+
- **Fast:** writes 100k rows × 10 columns in 0.07 s, about **50x faster than XlsxWriter** and
|
|
33
|
+
**90x faster than openpyxl**. DataFrames are about **30x faster** than `pandas.to_excel` and
|
|
34
|
+
`polars.write_excel`, with 9–34x less memory.
|
|
35
|
+
- **Streaming:** sync and async generators that plug into FastAPI/Starlette, Django and Flask
|
|
36
|
+
streaming responses.
|
|
37
|
+
- **Data you already have:** tuples and lists, dicts, dataclasses, named tuples, pydantic models,
|
|
38
|
+
pandas and polars DataFrames, sync and async iterables (e.g. async database cursors).
|
|
39
|
+
- **Real Excel types:** `date`, `datetime` (timezone-aware ones are written as local time), `time`,
|
|
40
|
+
`timedelta`, `Decimal`, numpy scalars, `bool`, and huge ints. NaN, None, NaT and pd.NA become
|
|
41
|
+
empty cells.
|
|
42
|
+
- **Styles and layout:** fonts, fills, borders, alignment, number formats, merged cells, frozen
|
|
43
|
+
panes, auto filters, Excel tables, row grouping, auto-fit columns, formulas, hidden sheets, tab colors.
|
|
44
|
+
- **Valid output:** checked with the Office Open XML schema validator and read back with openpyxl.
|
|
45
|
+
- **Fast reading:** `iter_rows` reads 100k rows × 10 columns in 0.13 s, about **26x faster than
|
|
46
|
+
openpyxl** and 3.5x faster than python-calamine, in bounded memory. `read_dataframe` builds a
|
|
47
|
+
pandas DataFrame 4–4.5x faster than `pandas.read_excel(engine="calamine")`, and a polars one
|
|
48
|
+
faster than fastexcel. See [Reading](#reading).
|
|
49
|
+
|
|
50
|
+
Hypaxel is built on the [`hypaxel` Rust crate](https://github.com/vensas/hypaxel/blob/main/rust/README.md). The [.NET version](https://github.com/vensas/hypaxel/blob/main/dotnet/README.md) uses the same design.
|
|
51
|
+
|
|
52
|
+
## Install
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install hypaxel
|
|
56
|
+
pip install "hypaxel[pandas]" # extras: pandas, polars, starlette
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Quick start
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import datetime as dt
|
|
63
|
+
import hypaxel
|
|
64
|
+
from hypaxel import Formula, Styled
|
|
65
|
+
|
|
66
|
+
with hypaxel.Writer("report.xlsx") as wb:
|
|
67
|
+
header = wb.add_style(bold=True, font_color="#FFFFFF", fill="#305496", align="center")
|
|
68
|
+
money = wb.add_style(num_format="#,##0.00")
|
|
69
|
+
|
|
70
|
+
ws = wb.add_worksheet("Sales", freeze_rows=1, column_widths=[20, 12, 14])
|
|
71
|
+
ws.write_row(["Product", "Date", "Revenue"], style=header)
|
|
72
|
+
ws.write_rows([
|
|
73
|
+
("Widget", dt.date(2024, 5, 1), Styled(1234.5, money)),
|
|
74
|
+
("Gadget", dt.date(2024, 5, 2), Styled(99.99, money)),
|
|
75
|
+
])
|
|
76
|
+
ws.write_row(["Total", None, Styled(Formula("SUM(C2:C3)"), money)])
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
One-liners:
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
hypaxel.to_xlsx(df, "orders.xlsx") # pandas or polars DataFrame
|
|
83
|
+
data: bytes = hypaxel.to_xlsx(orders) # list of dicts / dataclasses / models
|
|
84
|
+
hypaxel.to_xlsx(df, "out.xlsx", column_formats={"amount": "#,##0.00"})
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Reading
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
import hypaxel
|
|
91
|
+
|
|
92
|
+
for row in hypaxel.iter_rows("orders.xlsx", "Orders"): # sheet name or 0-based index
|
|
93
|
+
print(row) # ['Widget', 3, 9.99, datetime(...)]
|
|
94
|
+
|
|
95
|
+
records = hypaxel.read_records("orders.xlsx") # [{"Product": "Widget", ...}, ...]
|
|
96
|
+
df = hypaxel.read_dataframe("orders.xlsx") # pandas; library="polars" for polars
|
|
97
|
+
|
|
98
|
+
with hypaxel.open_workbook(upload_bytes) as wb: # path, bytes or binary file object
|
|
99
|
+
print(wb.sheet_names, wb.sheets, wb.date_1904)
|
|
100
|
+
for row in wb.rows("Orders", skip_empty=True):
|
|
101
|
+
...
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
- **Rows** are lists: `row[i]` is column `i + 1`, and a row ends at its last non-empty cell.
|
|
105
|
+
Missing rows come back as `[]`, so `enumerate(rows, 1)` gives Excel row numbers (pass
|
|
106
|
+
`skip_empty=True` to drop them).
|
|
107
|
+
- **Values** are `str`, `int` (integral numbers, as openpyxl returns them), `float`, `bool`,
|
|
108
|
+
`datetime.datetime` for dates, `datetime.time` for times of day, `datetime.timedelta` for
|
|
109
|
+
`[h]:mm` durations, error strings such as `"#N/A"`, and `None`. Formulas yield their cached
|
|
110
|
+
result. Dates are recognised from the cell's number format, in both date systems; times are
|
|
111
|
+
rounded to the millisecond.
|
|
112
|
+
- **Tables:** `wb.tables("Orders")` returns the sheet's Excel tables, one dict per table with the
|
|
113
|
+
keys that `add_table` takes (`first_row`, `first_col`, `last_row`, `last_col`, `name`, `columns`,
|
|
114
|
+
`style`, `header_row`, `autofilter`, `row_stripes`, `column_stripes`, `first_column`,
|
|
115
|
+
`last_column`, `totals_row`), from top to bottom, then left to right. Tables are stored apart
|
|
116
|
+
from the rows and are read only when you ask. A custom (non-built-in) table style reads as
|
|
117
|
+
`None`. `totals_row` tells whether the last row of the range is a totals row; such a table can
|
|
118
|
+
be read but not written.
|
|
119
|
+
- **Rows and columns:** the iterator returned by `wb.rows()` describes the row it returned last:
|
|
120
|
+
`row_number`, `outline_level`, `hidden`, `collapsed` and `height` (`None` when the row stores no
|
|
121
|
+
height). Rows that the file stores without values (a spacer row with a height, an empty hidden
|
|
122
|
+
row) come back as `[]` with default properties; open the workbook with
|
|
123
|
+
`include_empty_rows=True` to get their properties as well (such rows after the last value are
|
|
124
|
+
then returned too, and `skip_empty=True` still drops them). Before the first row it already has the sheet's `column_widths` (a list of
|
|
125
|
+
`(first_col, last_col, width, hidden)`, explicit and auto-fitted alike), `column_width(col)`,
|
|
126
|
+
`column_hidden(col)`,
|
|
127
|
+
`outline_summary_above` and `row_outline_levels`.
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
with hypaxel.open_workbook("orders.xlsx") as wb:
|
|
131
|
+
table = wb.tables("Orders")[0] # table["name"], table["columns"], ...
|
|
132
|
+
rows = wb.rows("Orders")
|
|
133
|
+
width = rows.column_width(2) # None = default width
|
|
134
|
+
for row in rows:
|
|
135
|
+
level, hidden = rows.outline_level, rows.hidden
|
|
136
|
+
```
|
|
137
|
+
- **Records:** `iter_records` / `read_records` use a header row (`header_row=1`). Empty header
|
|
138
|
+
cells become `column_<n>`, repeated names get the first free suffix of `_2`, `_3`, ... and rows without values are
|
|
139
|
+
skipped.
|
|
140
|
+
- **DataFrames:** `read_dataframe(source, sheet=0, *, header=True, library="pandas")`. polars needs
|
|
141
|
+
one type per column, so a column mixing text and dates arrives as text.
|
|
142
|
+
- **Memory:** rows are streamed. A path is read straight from disk; bytes and file objects are held
|
|
143
|
+
in memory once. Beyond that, memory is bounded by the workbook's shared string table and one
|
|
144
|
+
row. `max_shared_strings_bytes=` (default 1 GiB) caps the table for untrusted uploads.
|
|
145
|
+
- **Errors:** `FileNotFoundError` for missing files and `XlsxError` for everything else. Messages
|
|
146
|
+
name the problem, e.g. a legacy `.xls` or encrypted workbook, a sheet that does not exist (with
|
|
147
|
+
the sheets that do), or a damaged part.
|
|
148
|
+
|
|
149
|
+
## Records and DataFrames
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
@dataclass
|
|
153
|
+
class Order:
|
|
154
|
+
id: int
|
|
155
|
+
customer: str
|
|
156
|
+
amount: float
|
|
157
|
+
placed: dt.date
|
|
158
|
+
|
|
159
|
+
wb = hypaxel.Writer("orders.xlsx")
|
|
160
|
+
hypaxel.write_records(wb, "Orders", orders, column_formats={"amount": "#,##0.00", "placed": "yyyy-mm-dd"})
|
|
161
|
+
hypaxel.write_dataframe(wb, "Summary", summary_df, index=True)
|
|
162
|
+
wb.finish()
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
The first record defines the columns. `write_records` accepts dicts, dataclasses, named tuples,
|
|
166
|
+
pydantic models, objects with `__dict__` or `__slots__`, and tuples. Every table gets a bold,
|
|
167
|
+
frozen header row, an auto filter, and column widths estimated from the headers.
|
|
168
|
+
|
|
169
|
+
DataFrames are converted column-wise in chunks, so memory stays bounded even for very large
|
|
170
|
+
frames.
|
|
171
|
+
|
|
172
|
+
## Streaming web responses
|
|
173
|
+
|
|
174
|
+
**FastAPI / Starlette**
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
from hypaxel.starlette import XlsxResponse
|
|
178
|
+
|
|
179
|
+
@app.get("/orders.xlsx")
|
|
180
|
+
def orders(): # sync generator: runs in Starlette's thread pool
|
|
181
|
+
return XlsxResponse(hypaxel.stream_records(load_orders()), filename="orders.xlsx")
|
|
182
|
+
|
|
183
|
+
@app.get("/live.xlsx")
|
|
184
|
+
async def live(): # async source, e.g. an async DB cursor
|
|
185
|
+
rows = await conn.stream("SELECT id, customer, amount FROM orders")
|
|
186
|
+
return XlsxResponse(hypaxel.astream_rows(rows, header=["Id", "Customer", "Amount"]), filename="live.xlsx")
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Django**
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
from django.http import StreamingHttpResponse
|
|
193
|
+
|
|
194
|
+
def export(request):
|
|
195
|
+
response = StreamingHttpResponse(
|
|
196
|
+
hypaxel.stream_records(Order.objects.values("id", "customer", "amount").iterator()),
|
|
197
|
+
content_type=hypaxel.CONTENT_TYPE,
|
|
198
|
+
)
|
|
199
|
+
response["Content-Disposition"] = 'attachment; filename="orders.xlsx"'
|
|
200
|
+
return response
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**Flask:** `Response(hypaxel.stream_rows(rows, header=[...]), mimetype=hypaxel.CONTENT_TYPE)`
|
|
204
|
+
|
|
205
|
+
| Generator | Source |
|
|
206
|
+
| --- | --- |
|
|
207
|
+
| `stream_rows(rows, header=...)` | iterable of rows |
|
|
208
|
+
| `stream_records(records)` | iterable of dicts, dataclasses, models, ... |
|
|
209
|
+
| `stream_dataframe(df)` | pandas or polars DataFrame |
|
|
210
|
+
| `astream_rows(rows, header=...)` | async or sync iterable of rows |
|
|
211
|
+
| `astream_records(records)` | async or sync iterable of records |
|
|
212
|
+
|
|
213
|
+
**Custom layouts:** for full control (several sheets, styles, merges), use an in-memory writer and
|
|
214
|
+
`drain()`:
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
def export():
|
|
218
|
+
wb = hypaxel.Writer() # dest=None → in memory
|
|
219
|
+
ws = wb.add_worksheet("Data")
|
|
220
|
+
for batch in batches():
|
|
221
|
+
ws.write_rows(batch)
|
|
222
|
+
if chunk := wb.drain(): # roughly every 64 KiB of compressed output
|
|
223
|
+
yield chunk
|
|
224
|
+
yield wb.finish()
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## API overview
|
|
228
|
+
|
|
229
|
+
| | |
|
|
230
|
+
| --- | --- |
|
|
231
|
+
| `Writer(dest=None, *, compression_level=1, shared_strings=False, flush_threshold=65536, date_1904=False)` | `dest`: path, binary file object, or `None` (in memory) |
|
|
232
|
+
| `Writer.add_style(bold=, italic=, underline=, strikethrough=, font_name=, font_size=, font_color=, fill=, border=, border_color=, border_bottom=, align=, valign=, wrap=, indent=, rotation=, num_format=)` | returns a `Style`. Identical styles are shared |
|
|
233
|
+
| `Writer.add_worksheet(name, *, freeze_rows=, freeze_columns=, column_widths=, hidden=, show_grid_lines=, tab_color=, autofit=, autofit_sample_rows=, autofit_max_width=, row_outline_levels=, outline_summary_above=)` | returns a `Worksheet`. The previous sheet is completed |
|
|
234
|
+
| `Writer.drain()` / `Writer.finish()` | in-memory chunks / complete the workbook |
|
|
235
|
+
| `Worksheet.write_row(values, style=None, *, height=, outline_level=, hidden=, collapsed=)`, `write_rows(rows)`, `write_columns(columns)`, `write_dicts(records, keys)` | bulk writers, with the loops running in Rust |
|
|
236
|
+
| `Worksheet.write(value)`, `skip_cells(n)`, `end_row()`, `begin_row(height=, style=, *, outline_level=, hidden=, collapsed=)`, `skip_rows(n)` | cell-by-cell control. A begun row is filled by the next write |
|
|
237
|
+
| `Worksheet.merge_cells(r1, c1, r2, c2)`, `autofilter(r1, c1, r2, c2)` | ranges (1-based, inclusive) |
|
|
238
|
+
| `Worksheet.add_table(r1, c1, r2, c2, *, columns=, name=, style="TableStyleMedium2", header_row=, autofilter=, row_stripes=, column_stripes=, first_column=, last_column=)` | Excel table; `columns` must equal the header texts |
|
|
239
|
+
| `Formula("SUM(A1:A9)")`, `Styled(value, style)` | special cell values |
|
|
240
|
+
| `open_workbook(source, *, max_shared_strings_bytes=1 GiB, include_empty_rows=False)` → `Reader` | `source`: path, bytes or binary file object; a context manager |
|
|
241
|
+
| `Reader.sheet_names`, `Reader.sheets`, `Reader.date_1904`, `Reader.rows(sheet=0, *, skip_empty=False)`, `Reader.close()` | `rows` iterates lists; several iterators can be open at once |
|
|
242
|
+
| `Reader.tables(sheet=0)` | the sheet's Excel tables as dicts with `add_table`'s keys |
|
|
243
|
+
| `RowIterator.row_number`, `outline_level`, `hidden`, `collapsed`, `height` | properties of the row returned last |
|
|
244
|
+
| `RowIterator.column_widths`, `column_width(col)`, `column_hidden(col)`, `outline_summary_above`, `row_outline_levels` | sheet layout, available before the first row |
|
|
245
|
+
| `iter_rows` / `read_rows`, `iter_records` / `read_records`, `read_dataframe` | one-call readers; see [Reading](#reading) |
|
|
246
|
+
|
|
247
|
+
### Tables, row grouping and auto-fit
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
ws = wb.add_worksheet("Regions", autofit=True, row_outline_levels=1, outline_summary_above=True)
|
|
251
|
+
ws.write_row(["Region", "Revenue"])
|
|
252
|
+
ws.write_row(["North", 300])
|
|
253
|
+
ws.write_row(["Store A", 120], outline_level=1)
|
|
254
|
+
ws.write_row(["Store B", 180], outline_level=1, hidden=True)
|
|
255
|
+
ws.add_table(1, 1, ws.row, 2, columns=["Region", "Revenue"], name="Regions", style="TableStyleMedium9")
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
- `autofit=True` holds back the sheet's output until `autofit_sample_rows` rows (default 1,000,
|
|
259
|
+
at most 8 MiB of XML) have been measured, then writes the widths and streams as usual. Explicit
|
|
260
|
+
`column_widths` win; formulas and merged cells are not measured.
|
|
261
|
+
- `row_outline_levels` declares the deepest grouping level up front, because Excel reads it before
|
|
262
|
+
the rows.
|
|
263
|
+
- Table names are unique in the workbook; tables cannot overlap each other, merged cells or an
|
|
264
|
+
`autofilter` range.
|
|
265
|
+
|
|
266
|
+
## Performance
|
|
267
|
+
|
|
268
|
+
The same 10-column dataset as the .NET and Rust benchmarks (int, 2× str, 2× float, datetime,
|
|
269
|
+
bool, int, unique str, float). Python 3.13, macOS 26.6, Apple M1 Max, XlsxWriter 3.3.3, openpyxl
|
|
270
|
+
3.1.5, pandas 3.1.1, polars 2.1.0. Peak Python memory is measured with `tracemalloc` in a separate,
|
|
271
|
+
untimed run; the workbook is written to memory, so the figures include the output. Run it yourself
|
|
272
|
+
with `python benchmarks/bench.py 100000`.
|
|
273
|
+
|
|
274
|
+
| 100,000 rows | seconds | rows/s | peak Python memory |
|
|
275
|
+
| --- | ---: | ---: | ---: |
|
|
276
|
+
| **hypaxel** `write_rows` | **0.07** | **~1,380,000** | 5 MB (the output itself) |
|
|
277
|
+
| **hypaxel** `stream_rows` | **0.08** | **~1,310,000** | 11 MB |
|
|
278
|
+
| xlsxwriter (constant_memory) | 3.74 | 26,700 | 7 MB |
|
|
279
|
+
| openpyxl (write_only) | 6.35 | 15,800 | 7 MB |
|
|
280
|
+
| **hypaxel** pandas DataFrame* | **0.20** | 509,000 | 16 MB |
|
|
281
|
+
| pandas.to_excel (xlsxwriter)* | 6.82 | 14,700 | 147 MB |
|
|
282
|
+
| **hypaxel** polars DataFrame* | **0.17** | 581,000 | 8 MB |
|
|
283
|
+
| polars.write_excel* | 4.86 | 20,600 | 268 MB |
|
|
284
|
+
|
|
285
|
+
\* includes building the DataFrame from the row list.
|
|
286
|
+
|
|
287
|
+
| 1,000,000 rows | seconds | rows/s | peak Python memory |
|
|
288
|
+
| --- | ---: | ---: | ---: |
|
|
289
|
+
| **hypaxel** `write_rows` | **0.74** | **~1,360,000** | 53 MB (the output itself) |
|
|
290
|
+
| **hypaxel** `stream_rows` | **0.73** | **~1,370,000** | 106 MB |
|
|
291
|
+
| xlsxwriter (constant_memory) | 37.94 | 26,400 | 60 MB |
|
|
292
|
+
| openpyxl (write_only) | 63.97 | 15,600 | 66 MB |
|
|
293
|
+
| **hypaxel** pandas DataFrame* | **2.03** | 493,000 | 163 MB |
|
|
294
|
+
| pandas.to_excel (xlsxwriter)* | 69.87 | 14,300 | 1,446 MB |
|
|
295
|
+
| **hypaxel** polars DataFrame* | **2.22** | 450,000 | 53 MB |
|
|
296
|
+
| polars.write_excel* | 50.77 | 19,700 | 2,550 MB |
|
|
297
|
+
|
|
298
|
+
Hypaxel's own memory stays flat: what grows is the output buffer (53 MB at 1M rows), which a
|
|
299
|
+
streaming response sends instead of keeping.
|
|
300
|
+
|
|
301
|
+
### Reading
|
|
302
|
+
|
|
303
|
+
The same 10 columns plus a header row, saved with a shared string table as Excel does. Every reader
|
|
304
|
+
runs in its own process; peak RSS covers the whole process (Python, modules and native memory);
|
|
305
|
+
imports are not timed. All readers return the same non-empty cells. Python 3.13, macOS 26.6,
|
|
306
|
+
Apple M1 Max, openpyxl 3.1.5, python-calamine 0.9.1, fastexcel 0.21.0, pandas 3.1.1, polars 2.1.0.
|
|
307
|
+
Run it yourself with `python benchmarks/read_bench.py 100000`.
|
|
308
|
+
|
|
309
|
+
| 100,000 rows (5.5 MB) | seconds | peak RSS |
|
|
310
|
+
| --- | ---: | ---: |
|
|
311
|
+
| **hypaxel** `iter_rows` | **0.13** | **27 MB** |
|
|
312
|
+
| python-calamine `iter_rows` | 0.45 | 105 MB |
|
|
313
|
+
| openpyxl (read_only) | 3.39 | 63 MB |
|
|
314
|
+
| **hypaxel** `read_dataframe` (pandas) | **0.17** | 179 MB |
|
|
315
|
+
| pandas.read_excel (calamine) | 0.71 | 314 MB |
|
|
316
|
+
| pandas.read_excel (openpyxl) | 4.16 | 198 MB |
|
|
317
|
+
| **hypaxel** `read_dataframe` (polars) | **0.18** | 142 MB |
|
|
318
|
+
| fastexcel `to_polars` | 0.23 | 187 MB |
|
|
319
|
+
|
|
320
|
+
| 1,000,000 rows (55 MB) | seconds | peak RSS |
|
|
321
|
+
| --- | ---: | ---: |
|
|
322
|
+
| **hypaxel** `iter_rows` | **1.30** | **68 MB** |
|
|
323
|
+
| python-calamine `iter_rows` | 4.46 | 862 MB |
|
|
324
|
+
| openpyxl (read_only) | not run | not run |
|
|
325
|
+
| **hypaxel** `read_dataframe` (pandas) | **1.79** | 920 MB |
|
|
326
|
+
| pandas.read_excel (calamine) | 8.10 | 2,266 MB |
|
|
327
|
+
| pandas.read_excel (openpyxl) | not run | not run |
|
|
328
|
+
| **hypaxel** `read_dataframe` (polars) | **1.84** | 799 MB |
|
|
329
|
+
| fastexcel `to_polars` | 2.45 | 928 MB |
|
|
330
|
+
|
|
331
|
+
openpyxl is skipped at 1M rows because it is too slow at that size.
|
|
332
|
+
|
|
333
|
+
## Notes and limits
|
|
334
|
+
|
|
335
|
+
- **Write order:** rows are written top to bottom, and one worksheet at a time. Column widths
|
|
336
|
+
and frozen panes are set in `add_worksheet`.
|
|
337
|
+
- **Formulas:** they are stored without cached results; Excel recalculates them when the file
|
|
338
|
+
opens.
|
|
339
|
+
- **Long text:** text over 32,767 characters raises `XlsxError`. The offending cell is left
|
|
340
|
+
empty and the file stays valid.
|
|
341
|
+
- **GIL:** the GIL is held while writing (values are read from Python objects), so use threads
|
|
342
|
+
for parallel exports of separate files.
|
|
343
|
+
- **Reading:** cached formula results are read, not formula text. Styles (other than date
|
|
344
|
+
detection), merged ranges, comments and hyperlinks are not read.
|
|
345
|
+
|
|
346
|
+
## Development
|
|
347
|
+
|
|
348
|
+
```bash
|
|
349
|
+
cd python
|
|
350
|
+
uv venv && uv pip install maturin pytest pytest-asyncio pandas polars numpy openpyxl xlsxwriter fastapi httpx pydantic
|
|
351
|
+
# read benchmark extras: uv pip install python-calamine fastexcel pyarrow
|
|
352
|
+
.venv/bin/maturin develop --release
|
|
353
|
+
.venv/bin/python -m pytest
|
|
354
|
+
```
|
|
355
|
+
|