Skip to main content

xlsx_data_stream

A lightweight Python library for efficiently generating Excel files from large datasets or async data streams. Designed for:

  • low memory usage (streams data row-by-row);
  • sync and async support;
  • dynamic formatting (per-column number formats, additional sheets, e.t.c).

Refer to the tests/ and get_xlsx_file_stream/get_xlsx_file_stream_async docstrings for usage examples and details about the API. Proper documentation currently lacks, so you might need to read the code.

Installation

Using pip:

pip install xlsx_data_stream

Using poetry:

poetry add xlsx_data_stream

Usage

Synchronous interface

from xlsx_data_stream import ColumnDescription, get_xlsx_file_stream


chunks = get_xlsx_file_stream(
    [
        ColumnDescription(field="a"),
        ColumnDescription(field="b", number_format="0"),
        ColumnDescription(field="c", number_format="0.00"),
    ],
    [
        {"a": "text", "b": 1.2345, "c": 1.2345}
        for _ in range(1000)
    ],
)

with open("output.xlsx", "wb") as fh:
    for chunk in chunks:
        fh.write(chunk)

Asynchronous interface

import asyncio

from xlsx_data_stream import ColumnDescription, get_xlsx_file_stream_async


async def data():
    for _ in range(1000):
        yield {"a": "text", "b": 1.2345, "c": 1.2345}


async def main():
    chunks = get_xlsx_file_stream_async(
        [
            ColumnDescription(field="a"),
            ColumnDescription(field="b", number_format="0"),
            ColumnDescription(field="c", number_format="0.00"),
        ],
        data(),
    )

    with open("output.xlsx", "wb") as fh:
        async for chunk in chunks:
            fh.write(chunk)


asyncio.run(main())

convert_cell_value_to_excel_string

from datetime import datetime, timezone

from xlsx_data_stream import convert_cell_value_to_excel_string

assert convert_cell_value_to_excel_string(10, timezone.utc) == '10'

assert convert_cell_value_to_excel_string(None, timezone.utc) == ''

assert convert_cell_value_to_excel_string(
    datetime(2020, 1, 1, 10, tzinfo=timezone.utc),
    timezone.utc,
) == '43831.416666666664'

Mentions

Metadata

Release files for xlsx-data-stream 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xlsx-data-stream 0.0.1
File Size Uploaded
xlsx_data_stream-0.0.1.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xlsx-data-stream 0.0.1
File Interpreter ABI Platform
xlsx_data_stream-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.4 kB

Release files / xlsx_data_stream-0.0.1.tar.gz

Download URL xlsx_data_stream-0.0.1.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8decd173ab40e1f5cf14b6486e133a36a869dd8aa3a63f06510b876933ee0c33
BLAKE2b-256 checksum
How to use checksums
1ea37b20a7eebf4a3785c0aeec56301590ba515c76a3beaa40bcef3e6dbcc7b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.12.9 Linux/6.8.0-1021-azure

Release files / xlsx_data_stream-0.0.1-py3-none-any.whl

Download URL xlsx_data_stream-0.0.1-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ccf17ed739ad01a9b0ad2f8def3c8a28952613d7b4112cce9ed1374041e5a159
BLAKE2b-256 checksum
How to use checksums
9d165f1acd708efd2dfe35018a8bfcb79bb06beecc6b7e0d741d80c2e5bbc649
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.2 CPython/3.12.9 Linux/6.8.0-1021-azure

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page