sheetwise.core module

Main SpreadsheetLLM class integrating all components (Offline Edition).

class sheetwise.core.NumpyEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: JSONEncoder

Custom JSON encoder to handle NumPy data types.

default(obj)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return super().default(o)
class sheetwise.core.SpreadsheetLLM(compression_params=None, enable_logging=False)[source]

Bases: object

Main class integrating all SheetWise components. Includes Offline SQL and JSON export capabilities.

__init__(compression_params=None, enable_logging=False)[source]

Initialize SheetWise framework.

Parameters:
  • compression_params (Dict[str, Any]) – Parameters for SheetCompressor

  • enable_logging (bool) – Enable detailed logging for debugging

load_from_file(filepath)[source]

Load spreadsheet from file with robust type detection. Detects file type using magic numbers (signatures) rather than extensions.

Return type:

DataFrame

query_sql(df, sql_query, params=None)[source]

Run a SQL query against the DataFrame using DuckDB with enhanced security.

Parameters:
  • df (DataFrame) – The dataframe to query (registered as table ‘input_data’)

  • sql_query (str) – SQL query. Use ‘input_data’ to refer to the dataframe. Example: “SELECT * FROM input_data WHERE Year > ?”

  • params (Union[list, Dict[str, Any], None]) – Optional parameters for the query to prevent SQL injection. Supports list (for ‘?’) or dict (for ‘$name’) parameters.

Return type:

DataFrame

Returns:

Result as a new DataFrame

encode_to_json(df)[source]

Encode compressed spreadsheet data into structured JSON. Ideal for piping into other scripts or APIs.

Return type:

str

auto_configure(df)[source]

Auto-configure compression parameters.

Return type:

Dict[str, Any]

compress_and_encode_for_llm(df)[source]

Original Markdown encoding (retained for compatibility).

Return type:

str

encode_compressed_for_llm(compressed_result)[source]

Generate text representation (Markdown).

Return type:

str

process_qa_query(df, query)[source]

Process QA query using Chain of Spreadsheet.

Return type:

Dict[str, Any]

encode_vanilla(df, include_format=False)[source]
Return type:

str

compress_spreadsheet(df)[source]
Return type:

Dict[str, Any]

get_encoding_stats(df)[source]

Get basic statistics.

Return type:

Dict[str, Any]