matrixb.source package

Submodules

matrixb.source.base module

class matrixb.source.base.SourceBase(filename=None, worksheet=None, header_ignore=0, postheader_ignore=0, footer_ignore=0, **matrixparams)[source]

Bases: object

classmethod export_to(matrix, destination, topmatter=None, autosize=False)[source]

The export_to class method is designed to export a matrixb matrix to the source type. This method is abstract in the base class, and implementers should override it to export correctly. In many cases, this will be delegated to from the Matrixb.export() method, which attempts to identify the export based on the file extension.

Parameters:
  • matrix (matrixb.Matrix) – The Matrix object to export.
  • destination – The full path to the destination to export the data to.
  • topmatter (list|str, optional) – A line or lines to appear above the exported matrix.
  • autosize (bool) – This parameter may be removed in the future - the original intent was for Excel and ODS files to autosize the columns, but that’s not very generic.

TODO: Changing autosize to a more generic format configuration may be in order.

filename
footer_ignore
get_matrix(worksheet=None, **additionalparams)[source]

Gets the matrixb.Matrix for the current parameters.

Parameters:
  • worksheet (str) – Specifies a worksheet name, for sources that can have multiple worksheet matrices. The default is the worksheet property; if None and there are multiple worksheets, it will choose either the active or default, based on the functions available in the underlying handler class.
  • other keyword parameters will be passed directly to the matrix init call alongside any unrecognized parameters that were passed into the source's init call. It is therefore possible that invalid parameters passed into the SourceBase constructor will lead to a deferred Exception when get_matrix is called. (All) –
Returns:

A matrixb.Matrix given the current parameters.

header_ignore
ignored_header
ignored_postheader
next_row()[source]
nonemptyre = re.compile('\\s*\\S')
open()[source]
open_stream()[source]
postheader_ignore
skip_postheader()[source]
skip_rows(count)[source]
worksheet
worksheets

Worksheets returns a list of worksheet names available for this matrix class. By default, and if it is not a traditional spreadsheet with multiple possible worksheets, it should return a 1-element list of [‘<default>’]. Otherwise, when subclassing MatrixSource, the programmer should defined _worksheets based on the possible values

matrixb.source.csv module

class matrixb.source.csv.CSV(*args, encoding='utf-8-sig', csvdialect='excel', **kwargs)[source]

Bases: matrixb.source.base.SourceBase

classmethod export_cell(cell)[source]
classmethod export_to(matrix, filename, topmatter=None, autosize=None)[source]

The export_to class method to export a matrixb matrix to a CSV file.

Parameters:
  • matrix (matrixb.Matrix) – The Matrix object to export.
  • filename (str) – The full path to send the file.
  • topmatter (list|str, optional) – Lines to appear above the exported table.
  • autosize – This parameter is not used, only maintained for consistency with the export_to interface.
next_row()[source]

next() for csv matrix sources, which translates empty strings to None and skips blank lines.

open_stream()[source]
skip_rows(count)[source]

matrixb.source.googlesheet module

class matrixb.source.googlesheet.GoogleSheet(*args, **kwargs)[source]

Bases: matrixb.source.base.SourceBase

next_row()[source]
open_stream()[source]
skip_rows(count)[source]
worksheet

matrixb.source.resident module

class matrixb.source.resident.Resident(matrix, **kwargs)[source]

Bases: matrixb.source.base.SourceBase

next_row()[source]
open_stream()[source]
skip_rows(count)[source]

matrixb.source.xls module

class matrixb.source.xls.XLS(*args, **kwargs)[source]

Bases: matrixb.source.base.SourceBase

classmethod export_to(matrix, filename, topmatter=None, autosize=None)[source]

The export_to class method to export a matrixb matrix to a modern Excel (‘.xlsx’) file.

Parameters:
  • matrix (matrixb.Matrix) – The Matrix object to export.
  • filename (str) – The full path to send the file.
  • topmatter (list|str, optional) – Lines to appear above the exported table.
  • autosize (bool) – TODO.
next_row()[source]
open_stream()[source]
skip_rows(count)[source]
worksheet

matrixb.source.xlsx module

class matrixb.source.xlsx.XLSX(*args, **kwargs)[source]

Bases: matrixb.source.base.SourceBase

classmethod export_to(matrix, filename, topmatter=None, autosize=None)[source]

The export_to class method to export a matrixb matrix to a modern Excel (‘.xlsx’) file.

Parameters:
  • matrix (matrixb.Matrix) – The Matrix object to export.
  • filename (str) – The full path to send the file.
  • topmatter (list|str, optional) – Lines to appear above the exported table.
  • autosize (bool) – TODO.
iterator
next_row()[source]
open_stream()[source]
skip_rows(count)[source]
worksheet
worksheets

Worksheets returns a list of worksheet names available for this matrix class. By default, and if it is not a traditional spreadsheet with multiple possible worksheets, it should return a 1-element list of [‘<default>’]. Otherwise, when subclassing MatrixSource, the programmer should defined _worksheets based on the possible values

Module contents

class matrixb.source.Importer[source]

Bases: object

Kept to maintain legacy code

matrixb.source.factory(source, *args, **kwargs)[source]

A function to allow for the generic import of any file-based source.

Parameters:
  • source – A key that determines the source. The following are recognized. For any other source type, instantiate the source object directly: 1. filename with a known extension (csv, ods, xls, xlsx) 2. matrix (list of lists) 3. A Google Spreadsheet ID. It is assumed that an alphanumeric character string of >10 characters that matches w{10,} is such a sheet.
  • other parameters are delegated to the matrix source class without validation. It is assumed that the source class or subclass will handle them. (All) –
Returns:

An object that is the appropriate descendant of SourceBase.

matrixb.source.find_source_class(extension=None, filename=None)[source]

Returns a valid source class given the paramers passed in.

Parameters:
  • extension (str, optional) – The file extension the source class is based on. Should be just the extension. Case insensitive; the ‘period’ is allowed, but not expected). Examples: ‘CSV’, ‘xlsx’, ‘.ods’)
  • filename (str, optional) – A full filename, form which the extension will be extracted.
Returns:

A matrixb.source.SourceBase class for the given extension, if one exists. None if the extension is identified but no source class exists.

Raises:

Exception if no extension could be determined.