Package: python-xlsxio
python-xlsxioWrapper for c libraryxlsxioSince the main library is written in c, and its wrapper is written in cython (which compiles in c), the read speed is much faster than libraries written in python (as can be seen in the benchmarks).This library also has streaming reading and does not load memory.Of the minuses, you should know in advance the data types of each column, or read everything as a string or bytes.InstallJust:pip install python-xlsxioIf you want speed up about 5% you can build from source:pip install cython python-xlsxio --no-binary python-xlsxioBenchmarks read xlsxHow is testing you can see inbenchmark/benchmark.pyFile xlsx generated with openpyxl and conteins mixed types, how is generated you can see inbenchmark/generate_xlsx.pyBig file - file with 100000 rowsSmall file - file with 100 rowsTest machine: Linux 5.4.44-1-MANJARO #1 SMP PREEMPT Wed Jun 3 14:48:07 UTC 2020 x86_64TitleMin sec executionCalls/secxlsxio read big file with types1.085840.92095xlsxio read big file without types0.937871.06625xlsxio read big file without types all in bytes0.882681.13292xlsxio read big file with types from memory1.095690.91267xlsxio read small file with types0.00128780.58583xlsxio read small file without types0.00117855.33007xlsxio read small file without types all in bytes0.0011905.32902xlsxio read small file with types from memory0.00129776.06377openpyxl read big file6.345120.1576openpyxl read big file from memory6.352870.15741openpyxl read small file0.0113188.40829openpyxl read small file from memory0.0113488.19221xlrd read big file4.108230.24341xlrd read big file from memory4.09110.24443xlrd read small file0.00486205.74491xlrd read small file from memory0.00503198.75329sxl read big file4.97880.20085sxl read big file from memory4.967940.20129sxl read small file0.00627159.49498sxl read small file from memory0.00619161.4445xlsx2csv read big file6.534660.15303xlsx2csv read big file from memory6.560240.15243xlsx2csv read small file0.0115786.4205xlsx2csv read small file from memory0.0114787.21896Fast start with read xlsximportxlsxioxlsxio_reader=xlsxio.XlsxioReader('file.xlsx')sheet=xlsxio_reader.get_sheet()data=sheet.read_data()sheet.close()xlsxio_reader.close()print(data)Or simply:importxlsxiowithxlsxio.XlsxioReader('file.xlsx')asreader:withreader.get_sheet()assheet:data=sheet.read_data()print(data)Full example for reading xlsx file in sheethello, and not reading at all in memory (write only rows, which have True in 5 column):importxlsxioimportdatetimetypes=[str,str,float,int,bool,datetime.datetime]withxlsxio.XlsxioReader('file.xlsx')asreader:withreader.get_sheet('hello',types=types)assheet:header=sheet.read_header()only_active=[]forrowinsheet.iter_rows():ifrow[4]:only_active.append(row)print(only_active)Usage read xlsxXlsxioReaderObject of xlsxdef __init__(self, filename, encoding: str = 'utf-8')Inittializating XlsxioReaderfilename - str (path to filename), bytes (loaded in memory file) or file like object (not BytesIO)encoding - encoding of xlsx filedef get_sheet_names(self) -> tupleReturn tuple of sheet names in xlsx filedef get_sheet(self, sheetname: Optional[str] = None, flags: int = XlsxioReadFlag.SKIP_EMPTY_ROWS, types: Optional[Iterable[type]] = None, default_type: type = str) -> XlsxioReaderSheetReturn XlsxioReaderSheet objectsheetname - name of sheet (if None, returns first sheet)flags - default is XlsxioReadFlag.SKIP_EMPTY_ROWS (Read more about flags). All possible flags:XlsxioReadFlag.SKIP_NONEXlsxioReadFlag.SKIP_EMPTY_ROWSXlsxioReadFlag.SKIP_EMPTY_CELLSXlsxioReadFlag.SKIP_ALL_EMPTYXlsxioReadFlag.SKIP_EXTRA_CELLSXlsxioReadFlag.SKIP_HIDDEN_ROWStypes - list of types by columns. example, if first column is integer, second - str, end third - float, you can pass:types=[int, str, float]. if fourth column will be, then will it default_type.
Possible types:bytesstrintfloatdatetime.datetimebooldefault_type - default type of columns if types not passed, default strdef close(self)Closes readerXlsxioReaderSheetObject of sheetdef __init__(self, xlsxioreader: XlsxioReader, sheetname: Optional[str] = None, flags: int = XlsxioReadFlag.SKIP_EMPTY_ROWS, types: Optional[Iterable[type]] = None, default_type: type = str)Initializet XlsxioReaderSheet object (it object initializes in xlsxioreader.get_sheet and about params you can read there)def read_row(self, ignore_type: bool = False) -> Optional[list]Reading next row in list. If rows does not exists return Noneignore_type - if this true, return row in default_type (convenient for heading)def read_header(self) -> Optional[list]Alias for read_row(True)def iter_rows(self) -> Iterable[list]Iterate rows while rows existsdef get_last_row_index(self) -> int:Getting last row index (returns 0 if not readed yet)def get_flags(self) -> int:Getting applied flagsdef read_data(self) -> List[list]Read all sheet rows, and first row in default_type. Method code:header=self.read_header()ifheaderisNone:return[]rows=list(self.iter_rows())rows.insert(0,header)returnrowsdef close(self)Closes sheet