Skip to main content

SQL-like queries for Excel files

Project description

exlsql

Query Excel files using SQL syntax. No database, no server — just point it at a .xlsx file, write a SQL string, and get your data back.


Installation

pip install exlsql

Quick Start

from exlsql import Query

q = Query(
    "SELECT 'First Name', 'Last Name', Age FROM Sheet1 WHERE Age > 30",
    excel_file="data.xlsx"
)

result = q.to_excel(q.parse(), type="dict")

Usage

Every query follows the same two steps:

q = Query(sql_string, excel_file="yourfile.xlsx")
parsed = q.parse()
result = q.to_excel(parsed, type="dict")  # or "list" or "file"

Supported SQL Syntax

SELECT columns

SELECT 'First Name', Age, Country FROM Sheet1

SELECT all columns

SELECT * FROM Sheet1

DISTINCT

SELECT DISTINCT Country FROM Sheet1

WHERE — comparisons

SELECT * FROM Sheet1 WHERE Age > 30
SELECT * FROM Sheet1 WHERE Age >= 18
SELECT * FROM Sheet1 WHERE Country = 'France'

WHERE — AND / OR

SELECT * FROM Sheet1 WHERE Age > 30 AND Country = 'France'
SELECT * FROM Sheet1 WHERE Country = 'France' OR Country = 'United States'

WHERE — IN

SELECT * FROM Sheet1 WHERE Country IN ('France', 'United States', 'China')

ORDER BY

SELECT 'First Name', Age FROM Sheet1 ORDER BY Age ASC
SELECT 'First Name', Age FROM Sheet1 ORDER BY Age DESC

Combined

SELECT 'First Name', Age, Country FROM Sheet1
WHERE Age > 25 AND Country = 'France'
ORDER BY Age DESC

Return Types

type Returns
"dict" (default) List of row dicts — [{'Name': 'Alice', 'Age': 32}, ...]
"list" Column-oriented dict — {'Name': ['Alice', ...], 'Age': [32, ...]}
"file" Writes result to yourfile_output.xlsx, returns the path
# dict (default)
q.to_excel(parsed)
q.to_excel(parsed, type="dict")

# list
q.to_excel(parsed, type="list")

# file
path = q.to_excel(parsed, type="file")
print(path)  # data_output.xlsx

Notes

  • FROM refers to the sheet name inside the Excel file, not the filename
  • Only .xlsx files are supported — passing any other format raises a ValueError
  • Column names with spaces must be wrapped in single or double quotes: 'First Name' or "First Name"
  • String values in WHERE must be wrapped in single quotes: WHERE Country = 'France'
  • Output files are always written alongside the input file as filename_output.xlsx

Error Handling

try:
    q = Query(sql, excel_file="data.csv")
except ValueError as e:
    print(e)  # Wrong file type, must be .xlsx

Common errors:

  • Wrong file type → ValueError: Wrong file type, must be .xlsx
  • Missing FROM → ValueError: Invalid sql syntax
  • Bad ORDER BY → ValueError: ORDER BY missing column
  • Invalid return type → ValueError: Invalid Parameter (list, dict, file)

Requirements

  • pandas
  • openpyxl

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

exlsql-0.1.3.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

exlsql-0.1.3-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file exlsql-0.1.3.tar.gz.

File metadata

  • Download URL: exlsql-0.1.3.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for exlsql-0.1.3.tar.gz
Algorithm Hash digest
SHA256 559be02567b856a27ed646608d1d61be307ce60ee5e5347f067c28fc36d62f12
MD5 f99dcf0b16dfafa04a8ae19086015c37
BLAKE2b-256 f1fe60ca5e71a49579557b22d682a15dd8c58a88a850e3d352b96b1353555e61

See more details on using hashes here.

File details

Details for the file exlsql-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: exlsql-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for exlsql-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8b213352e431f7d9b3b92f28f8d73d24d97a72c2d1ed9880dfa96be7dbf3b061
MD5 b6a676fe12de36e52d2b9ed7f3d426c5
BLAKE2b-256 1092f2e804b701cb21e08abc8839044872ab2cf84eedc124872161625c0fb200

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page