stingray.implementations

Workbook Implementations

See http://www.python-excel.org/ for a list of implementations. Of these, we choose a few to handle XLSX, ODS, and Numbers.

We use xlrd and openpyxl directly, even through pyexcel provides a uniform wrapper. This package, also, provides a uniform wrapper. In the long run, it might be helpful to more carefully distinguish schema-processing from the pyexcel workbook processing.

We could use odfpy to read ODS directly.

XLS

.XLS files are unpacked via xlrd.

Note that this is only for historical .XLS files.

See https://xlrd.readthedocs.io/en/latest/

class stingray.implementations.XLSUnpacker

Wrapper around xlrd.

close() None

Closes the XLS file.

instance_iter(name: str, **kwargs: Any) Iterator[WBInstance]

Yields rows of this sheet of this workbook.

Parameters:
  • name – Name of the sheet to process.

  • kwargs – Additional keyword args (Ignored)

Yields:

WBInstance rows from the workbook

open(name: Path, file_object: IO | None = None, **kwargs: Any) None

Open an XLS file.

Parameters:
  • namePath for the workbook

  • file_object – Optional open file to use; if omitted, name is opened.

  • kwargs – Additional KW Args to apply to the unpacker.

sheet_iter() Iterator[str]

Yields names of the sheets in this workbook.

class stingray.implementations.XLS_Workbook(name: str | Path, **kwargs: Any)

Facade for XLS Workbooks.

close() None

Closes this workbook.

XLSX

.XLSX files are unpacked with Openpyxl.

See https://openpyxl.readthedocs.io/en/stable/

class stingray.implementations.XLSXUnpacker

Wrapper around openpyxl.

close() None

Closes the XLSX file.

instance_iter(name: str, **kwargs: Any) Iterator[WBInstance]

Yields rows from the given sheet.

Parameters:
  • name – sheet name

  • kwargs – additional kw args (not used)

Yields:

WBInstance rows from the workbook

open(name: Path, file_object: IO | None = None, **kwargs: Any) None

Opens the XLSX file.

Parameters:
  • namePath to the workbook.

  • file_object – Optional open file to use; if omitted, name is opened.

  • kwargs – KW Args provided to openpyxl

sheet_iter() Iterator[str]

yields sheet names from this workbook.

class stingray.implementations.XLSX_Workbook(name: str | Path, **kwargs: Any)

Facade for XLSX Workbooks.

close() None

Closes the workbook.

ODS

.ODS files are unpacked with pyexcel.

See http://docs.pyexcel.org/en/latest/

Pyexcel seems to cover a wide variety of formats. It might be helpful to delegate more of the implementations to PyExcel.

class stingray.implementations.ODSUnpacker

Wrapper around pyexcel_ods3.

close() None

Closes the ODS file.

instance_iter(name: str, **kwargs: Any) Iterator[WBInstance]

Yields individual rows from the current sheet.

Parameters:
  • name – Sheet name

  • kwargs – Additional kw args (not used)

Yields:

WBInstance of worksheet rows.

open(name: Path, file_object: IO | None = None, **kwargs: Any) None

Opens the ODS file.

Parameters:
  • namePath to the workbook.

  • file_object – Optional open file to use; if omitted, name is opened.

  • kwargs – KW Args provided to pyexcel

sheet_iter() Iterator[str]

Yields names of the sheets in this workbook.

class stingray.implementations.ODS_Workbook(name: str | Path, **kwargs: Any)

Facade for XLSX Workbooks.

close() None

Closes the workbook.

Numbers

.NUMBERS files are unpacked by numbers-parser.

See https://pypi.org/project/numbers-parser/

class stingray.implementations.NumbersUnpacker

Wrapper around numbers_parser.

close() None

Closes the numbers file.

instance_iter(name: str, **kwargs: Any) Iterator[WBInstance]

Yields individual rows from the current sheet.

Parameters:
  • name – Sheet::Table composite name

  • kwargs – Additional kw args (not used)

Yields:

WBInstance of worksheet rows.

open(name: Path, file_object: IO | None = None, **kwargs: Any) None

Opens the numbers file.

Parameters:
  • namePath to the workbook.

  • file_object – Optional open file to use; if omitted, name is opened.

  • kwargs – KW Args provided to numbers_parser

sheet_iter() Iterator[str]

Yields the names of sheets and tables. The names take the form of sheet::table.

class stingray.implementations.Numbers_Workbook(name: str | Path, **kwargs: Any)

Facade for XLSX Workbooks.

close() None

Closes the workbook.