Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## in progress

- Connectors: Added source adapter for the XLSX file format

## 2026/07/02 v0.5.0

- Connectors: Updated to Asana client v5
Expand Down
1 change: 1 addition & 0 deletions omniload/core/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"dune": "omniload.source.dune.api:DuneSource",
"dynamodb": "omniload.source.dynamodb.api:DynamoDBSource",
"elasticsearch": "omniload.source.elasticsearch.api:ElasticsearchSource",
"excel": "omniload.source.excel.api:ExcelSource",
"facebookads": "omniload.source.facebook_ads.api:FacebookAdsSource",
"file": "omniload.source.filesystem.api:LocalFilesystemSource",
"fireflies": "omniload.source.fireflies.api:FirefliesSource",
Expand Down
71 changes: 71 additions & 0 deletions omniload/source/excel/adapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# https://github.com/dlt-hub/dlt-studio/blob/devel/dlt/sources/_core_source_templates/filesystem_pipeline.py
from typing import Any, Iterable, Optional

import dlt
import polars as pl
from dlt.extract import DltResource
from dlt.extract import Incremental as dlt_incremental


@dlt.source(name="excel", max_table_nesting=0)
def excel_source(
uri: str,
table: str,
**kwargs: Any,
) -> Iterable[DltResource]:
"""
Read from an Excel spreadsheet.

Args:
uri (str): A filesystem path to the Excel file.
table (str): The name of the sheet to read from the spreadsheet.

Returns:
Iterable[DltResource]: Resources with data.
"""

incremental_key = kwargs.get("incremental_key")
merge_key = kwargs.get("merge_key")

def reader(
incremental: Optional[dlt_incremental[Any]] = None,
):
df = pl.read_excel(uri, sheet_name=table)

if incremental_key and incremental_key not in df.columns:
raise ValueError(
f"incremental_key '{incremental_key}' not found in sheet '{table}'"
)

rows = df.rows(named=True)

if incremental_key and incremental and incremental.start_value:
rows = [
row
for row in rows
if row.get(incremental_key) is not None
and row[incremental_key] >= incremental.start_value
]

return rows

write_disposition = "merge" if merge_key else "replace"

resource = dlt.resource(
reader,
name=table,
write_disposition=write_disposition,
)(
incremental=dlt_incremental(
incremental_key or "",
initial_value=kwargs.get("interval_start"),
end_value=kwargs.get("interval_end"),
range_end="closed",
range_start="closed",
)
)

if merge_key:
resource.apply_hints(merge_key=merge_key)

return resource
10 changes: 10 additions & 0 deletions omniload/source/excel/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class ExcelSource:
def handles_incrementality(self) -> bool:
return False

def dlt_source(self, uri: str, table: str, **kwargs):
path = uri.split("://", 1)[1]

from omniload.source.excel.adapter import excel_source

return excel_source(path, table, **kwargs)
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ dependencies = [
"duckdb-engine<0.18",
"elasticsearch<10",
"facebook-business<26",
"fastexcel<1",
"flatten-json<0.2",
"gcsfs",
"google-ads<32",
Expand All @@ -103,6 +104,7 @@ dependencies = [
"oracledb<5",
"orjson<4",
"pendulum>=3,<4",
"polars<2",
"psycopg2-binary<3",
"py-machineid<2",
"pyairtable<4",
Expand Down
Binary file added tests/assets/create_replace.xlsx
Binary file not shown.
19 changes: 19 additions & 0 deletions tests/warehouse/storage/test_excel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pathlib import Path

from tests.util import invoke_ingest_command


def test_excel_source(tmp_path):
assets_path = Path(__file__).parent.parent.parent / "assets"
dest = tmp_path / "output.csv"
result = invoke_ingest_command(
f"excel://{assets_path}/create_replace.xlsx",
"create_replace",
f"csv://{dest}",
"test.foo",
print_output=False,
)
assert result.exit_code == 0

content = Path(dest).read_text()
assert "AGILENT TECHNOLOGIES INC" in content
Loading