Skip to main content

Asynchronous xlsx files generator

Project description

aioxlsxstream

Generate the xlsx file prior to downloading or of a very large file that you do not want to store entirely on disk or on memory. Generated excel workbook contain only one sheet. All data writes as strings.

Installation

pip install aioxlsxstream

Requirements

  • Python 3.8+

Simple exapmle

import aioxlsxstream
import asyncio

async def main():
    async def rows_generaor():
        async def row_cells_generator(row):
            for col in range(5):
                yield row*5 + col
        for row in range(10):
            yield row_cells_generator(row)

    xlsx_file = aioxlsxstream.XlsxFile()
    xlsx_file.write_sheet(rows_generaor())

    with open("example.xlsx", "wb") as f:
        async for data in xlsx_file:
            f.write(data)

asyncio.run(main())

aiohttp Example

from aiohttp import web, hdrs
import aioxlsxstream

async def rows_generaor():
    async def row_cells_generator(row):
        for col in range(5):
            yield row*5 + col
    for row in range(10):
        yield row_cells_generator(row)

async def handle(request):
    filename = "example.xlsx"
    response = web.StreamResponse(
        status=200,
        headers={
            hdrs.CONTENT_TYPE: "application/octet-stream",
            hdrs.CONTENT_DISPOSITION: (f"attachment; " f'filename="{filename}"; '),
        },
    )
    await response.prepare(request)

    xlsx_file = aioxlsxstream.XlsxFile()
    xlsx_file.write_sheet(rows_generaor())

    async for data in xlsx_file:
        await response.write(data)
    return response

app = web.Application()
app.add_routes([web.get('/', handle)])

if __name__ == '__main__':
    web.run_app(app)

Project details


Download files

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

Source Distribution

aioxlsxstream-1.0.0.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

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

aioxlsxstream-1.0.0-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file aioxlsxstream-1.0.0.tar.gz.

File metadata

  • Download URL: aioxlsxstream-1.0.0.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.15 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.5

File hashes

Hashes for aioxlsxstream-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9a5c9756c23f6cc74f9699c31a0e037cf0fee23e9cae3b6de1da40181cd6eea2
MD5 15d89d189139a699a076a15aa81553ac
BLAKE2b-256 600a35e43f6cd4c2196a37202e2f56129372e9dc12c649f55c8af793cf1af398

See more details on using hashes here.

File details

Details for the file aioxlsxstream-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: aioxlsxstream-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.15 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.5

File hashes

Hashes for aioxlsxstream-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9bdc6bcd7cfd107b8115730e642a4f8f7d6a9dbc97eafedac4b7f29dbd3d9b2
MD5 957d8eb4d9ec33973bf112026a844f03
BLAKE2b-256 db38ea2b884ea819411291224085cbe6724e2d240033f679b0b8ebbb6dd41de6

See more details on using hashes here.

Supported by

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