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

Download files

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

Source Distribution

xlsx_data_stream-0.0.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

xlsx_data_stream-0.0.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file xlsx_data_stream-0.0.1.tar.gz.

File metadata

  • Download URL: xlsx_data_stream-0.0.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.9 Linux/6.8.0-1021-azure

File hashes

Hashes for xlsx_data_stream-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8decd173ab40e1f5cf14b6486e133a36a869dd8aa3a63f06510b876933ee0c33
MD5 9514dd53d01eccf808dfaa1076d44bd0
BLAKE2b-256 1ea37b20a7eebf4a3785c0aeec56301590ba515c76a3beaa40bcef3e6dbcc7b4

See more details on using hashes here.

File details

Details for the file xlsx_data_stream-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: xlsx_data_stream-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.9 Linux/6.8.0-1021-azure

File hashes

Hashes for xlsx_data_stream-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ccf17ed739ad01a9b0ad2f8def3c8a28952613d7b4112cce9ed1374041e5a159
MD5 d1f65bccc6e6752f90f4f26510a7fb94
BLAKE2b-256 9d165f1acd708efd2dfe35018a8bfcb79bb06beecc6b7e0d741d80c2e5bbc649

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 files

Supported by

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