Skip to main content

Docx and Excel File handler for Streamlit or Dash

Project description

Xfilios

Excel and Docx FileIO handlers in the client side for Streamlit (in future Dash will also be considered) Framework. The library provides easy to use classes to encode or decode Docx and Excel at the client side. The following core features are available in the library:

  • Convert an uploaded Docx-file into base64 encoded string to send over HTTP post request (a wrapper over python-docx package)
  • Convert Data received from an HTTP get/post request into Downloadable Excel file (a wrapper over pandas and openpyxl)
  • Combine multiple data source into multi-sheet Downloadable Excel file at the frontend (a wrapper using pandas ReadExcel function with openpyxl)

This package is actually a wrapper over pandas and python-docx package. It is possible to extend other fileIO types like csv, text etc in further release.

DocxHandler

When a Docx file is uploaded into streamlit, it consider the content as a file like object. The package xfilios provide a class called DocxHandler which has a class method can receive a file like object and will return a DocxHandler object. After create a handler object it easy to convert the content into base64 encoded string to send it over a Rest API as follows:

import streamlit as st
from xfilios.docx import DocxHandler

def docx_handler_demo():
    st.title('Demo of xfilios DocxHandler')
    content = st.file_uploader("Upload Docx File", type="docx")
    if content:
        handler = DocxHandler.from_file_like(content)
        # Now you can send the encoded string over Http post request
        document_base_64 = handler.to_base64_str()
        # requests.post(body={"data": document_base_64})
        st.text("Here is the base64 encoded document {}...".format(document_base_64[:10]))

        # Or if you received a base64 encoded binary document you can create a downloadable link
        download_link = handler.create_download_link(filename="demo.docx")
        download_text = f"Please Download the document back {download_link}"
        st.markdown(download_text, unsafe_allow_html=True)

image info

TableHandler and ExcelHandler The TableHandler and ExcelHandler can work together to achieve the same functionality like DocxHandler. After you upload a Excel file you can use TableHandler to collect the content of the file. If you have multiple table you can load all the tables and wrap them with TableHandler and create a list of TableHandler and hand it over to ExcelHandler. ExcelHandler will finally create a downloadable Excel file where each table will an Excel sheet.

import streamlit as st
from xfilios.table import TableHandler
from xfilios.excel import ExcelHandler

def excel_handler_demo():
    st.title('Demo of xfilios ExcelHandler')
    content = st.file_uploader("Upload Docx File", type="xlsx")
    if content:
        # Each table handler will consist one table
        table_handler = TableHandler.from_file_like(content)
        # You can put multiple table handler into a list [table_handler1, table_handler2 ...]
        excel_handlers = ExcelHandler([table_handler])
        download_link = excel_handlers.create_download_link(filename="demo.xlsx")
        download_text = f"Please Download the File back {download_link}"
        st.markdown(download_text, unsafe_allow_html=True)
        st.markdown("Here is the content of the file")
        st.table(table_handler.get_data_as_dataframe())

image info

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

xfilios-0.0.4.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

xfilios-0.0.4-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file xfilios-0.0.4.tar.gz.

File metadata

  • Download URL: xfilios-0.0.4.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for xfilios-0.0.4.tar.gz
Algorithm Hash digest
SHA256 1e9d9f23b7c8bbb29c8b2cc7ef5ebd6136c0b1bc3007aee0824d46a02fa2f86c
MD5 a1fb63a04f3673c588f5342e079e568c
BLAKE2b-256 9b587e2ffffe3a6bba071454e0a95e1b83c2a42fbe077fc27c1b0b47f936c79e

See more details on using hashes here.

File details

Details for the file xfilios-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: xfilios-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for xfilios-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 51aa434a262f92a7827cc2c97df166038b08bedb33ca3321fbe20ef9bc1e8ba9
MD5 b41143b8cc3df8b25de29d999b5378c6
BLAKE2b-256 69b3543f9c9fad4678b08215b2e395ffac10da76eaa6fa40dfd6d0453392d00c

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