5.4. Table loader classes

5.4.1. TableData

class simplesqlite.loader.data.TableData[source]

namedtuple() to represent the table data structure.

table_name

Name of the table.

header_list

List of header names.

record_list

List of records of the table.

5.4.2. TableLoader class

class simplesqlite.loader.interface.TableLoader(source)[source]

Bases: simplesqlite.loader.interface.TableLoaderInterface

Abstract class of table data file loader.

table_name

Table name string.

source

Table data source to load.

5.4.3. CsvTableLoader class

class simplesqlite.loader.csv.core.CsvTableLoader(source)[source]

Bases: simplesqlite.loader.interface.TableLoader

Abstract class of CSV table loader.

header_list

Attribute names of the table. Use the first line of the csv file as attribute list if header_list is empty.

delimiter

A one-character string used to separate fields. Defaults to ",".

quotechar

A one-character string used to quote fields containing special characters, such as the delimiter or quotechar, or which contain new-line characters. Defaults to '"'.

encoding

Encoding of the CSV data.

load()
make_table_name()

5.4.4. CsvTableFileLoader class

class simplesqlite.loader.CsvTableFileLoader(file_path=None)[source]

Bases: simplesqlite.loader.csv.core.CsvTableLoader

Concrete class of CSV file loader.

table_name

Table name string. Defaults to %(filename)s.

load()[source]

Load table data from a CSV file.

Returns:Loaded table data. Table name is determined by make_table_name().
Return type:iterator of TableData
Raises:InvalidDataError – If the CSV data is invalid.

See also

csv.reader()

make_table_name()[source]

Make table name string from table_name. Following format specifiers are replaced with specific string.

format specifier value after the replacement
%(filename)s filename
Returns:Table name.
Return type:str

5.4.5. CsvTableTextLoader class

class simplesqlite.loader.CsvTableTextLoader(text)[source]

Bases: simplesqlite.loader.csv.core.CsvTableLoader

Concrete class of CSV text loader.

load()[source]

Load table data from a CSV text.

Returns:Loaded table data.
Return type:iterator of TableData
Raises:InvalidDataError – If the CSV data is invalid.

See also

csv.reader()

make_table_name()

5.4.6. JsonTableFileLoader class

class simplesqlite.loader.JsonTableFileLoader(file_path=None)[source]

Bases: simplesqlite.loader.interface.TableLoader

Concrete class of JSON file loader.

load()[source]

Load a JSON file from source that includes table data. First, single table data in a file, acceptable JSON schema is as follows:

{
    "type": "array",
    "items": {
        "type": "object",
        "additionalProperties": {
            "anyOf": [
                {"type": "string"},
                {"type": "number"},
                {"type": "null"},
            ],
        },
    },
}

Second, multiple table data in a file, acceptable JSON schema is as follows:

{
    "type": "object",
    "additionalProperties": {
        "type": "array",
        "items": {
            "type": "object",
            "additionalProperties": {
                "anyOf": [
                    {"type": "string"},
                    {"type": "number"},
                    {"type": "null"}
                ]
            }
        }
    }
}

The table name string is making from table_name. Following format specifiers are replaced with specific string.

format specifier value after the replacement
%(filename)s Filename. Defaults to single JSON table.
%(key)s Key of the table data (only for multiple JSON table). Defaults to multiple JSON table.
Returns:Loaded table data.
Return type:iterator of TableData
make_table_name()[source]

5.4.7. JsonTableTextLoader class

class simplesqlite.loader.JsonTableTextLoader(text)[source]

Bases: simplesqlite.loader.interface.TableLoader

load()[source]

Load a JSON text from source that includes table data.

Returns:Loaded table data.
Return type:iterator of TableData

5.4.8. SpreadSheetLoader class

class simplesqlite.loader.spreadsheet.core.SpreadSheetLoader(source)[source]

Bases: simplesqlite.loader.interface.TableLoader

Abstract class of table data. Especially spreadsheets that consists multiple rows.

table_name

Table name string. Defaults to %(sheet)s.

start_row

The first row to search header row.

5.4.9. ExcelTableFileLoader class

class simplesqlite.loader.ExcelTableFileLoader(file_path=None)[source]

Bases: simplesqlite.loader.spreadsheet.core.SpreadSheetLoader

Concrete class of Microsoft Excel TM file loader.

load()[source]

Load table data from an Excel file. This method will automatically search the header row start from start_row. Conditions of the header row is that all of the columns has value (except empty columns).

Returns:Loaded table data. Return one TableData for each sheet in the workbook. Table name is determined by make_table_name().
Return type:iterator of TableData
Raises:InvalidDataError – If the header row is not found.
make_table_name()[source]

Make table name string from table_name. Following format specifiers are replaced with specific string.

format specifier value after the replacement
%(filename)s Filename of the workbook
%(sheet)s Name of the sheet
Returns:Table name.
Return type:str

5.4.10. GoogleSheetsTableLoader class

class simplesqlite.loader.GoogleSheetsTableLoader(file_path=None)[source]

Bases: simplesqlite.loader.spreadsheet.core.SpreadSheetLoader

Concrete class of Google Spreadsheet loader.

Requirements:

load()[source]

Load table data from a Google Spreadsheet. This method will automatically search the header row start from start_row. Conditions of the header row is that all of the columns has value (except empty columns).

Returns:Loaded table data. Return one TableData for each sheet in the workbook. Table name is determined by make_table_name().
Return type:iterator of TableData
Raises:InvalidDataError – If the header row is not found.
make_table_name()[source]

Make table name string from table_name. Following format specifiers are replaced with specific string.

format specifier value after the replacement
%(filename)s Filename of the workbook
%(title)s Name of the spreadsheet
Returns:Table name.
Return type:str