Supported Data Sources & Unified Locator Syntax#
GenericData (and the Location column of Excel
driver workbooks) accepts a single, unified locator syntax across flat
files, spreadsheets, COBOL copybook + mainframe extract pairs, and any
SQLAlchemy-compatible database backend.
You can specify any data source in two clean, interchangeable ways:
Unified URI / Scheme Strings (or plain file paths with optional
#Sheet/#Tablefragments) — ideal for the CLI, Excel driver workbooks (test_driver.xlsx), and concise Python calls.Structured :class:`~dataspector.core.DataSourceSpec` (or ``dict``) — ideal for typed Python pipelines and YAML/JSON configurations.
Unified URI / Scheme Reference#
Source Category |
Unified Locator Examples |
|---|---|
Single Files (Auto or Explicit Scheme) |
|
Excel Sheets & HDF5 Keys |
|
COBOL Copybook + Mainframe Extract Pair |
|
Embedded Databases (SQLite, DuckDB, MS Access) |
|
SQL Server, PostgreSQL, MySQL, MariaDB, Oracle & More |
|
Tip
Environment Variable Interpolation (Keep Secrets Out of Excel & YAML)
Any locator string (and uri /
data) automatically expands
${VAR_NAME} placeholders from os.environ:
postgresql+psycopg://${PG_USER}:${PG_PASSWORD}@db.internal:5432/prod#public.fact_sales
${DATABASE_URL}#public.fact_sales
cobol://${COPYBOOK_DIR}/acct.cbl::${EXTRACT_DIR}/acct.dat?encoding=cp500
Because credentials are resolved at runtime, analysts can safely commit and share Excel driver workbooks without ever embedding database passwords.
Database Backends & Optional Extras (SQLAlchemy)#
DataSpector uses SQLAlchemy (included by default) to inspect tables, count rows with dialect-safe SQL quoting, and stream records across database flavours. SQLite works out of the box with zero extra installs; for other backends, install the lightweight optional extra matching your database:
Backend / Format |
Install Command |
Example Locator URL |
|---|---|---|
SQLite |
Included with |
|
PostgreSQL |
|
|
MySQL / MariaDB |
|
|
Oracle (thin mode) |
|
|
DuckDB |
|
|
Snowflake |
|
|
All pure-wheel SQL drivers |
|
Installs |
SQL Server & MS Access (ODBC) |
|
|
Parquet |
|
|
Note
Any other SQLAlchemy dialect (Snowflake, BigQuery, Redshift, Trino,
ClickHouse) also works immediately as long as its SQLAlchemy dialect package
is installed in your environment — just append #<table_name> or
#<schema>.<table_name> to the standard SQLAlchemy connection URL.
Structured Python & YAML Specification (DataSourceSpec)#
For programmatic pipelines or YAML/JSON configs where explicit fields are
clearer than URL query strings, pass a DataSourceSpec
dataclass (or an equivalent dict) directly to
GenericData or
run_checks_on_location():
import dataspector
from dataspector import DataSourceSpec, GenericData
# 1. PostgreSQL table with explicit schema
pg_source = GenericData(
DataSourceSpec(
uri="postgresql+psycopg://${PG_USER}:${PG_PASS}@db.internal:5432/warehouse",
format="postgres",
table="finance.fact_transactions",
)
)
# 2. COBOL copybook + EBCDIC binary extract (even with a non-standard extension)
cobol_source = DataSourceSpec(
uri="layouts/account_layout.txt",
format="cobol",
data="extracts/accounts_cp500.dat",
options={"encoding": "cp500", "include_filler": False},
)
results = dataspector.run_checks_on_location(
cobol_source,
[("source_exists", {}), ("record_count_greater_than", {"nrows": 0})],
)
# 3. Fixed-width text file disguised with a .bin extension (dict form)
fwf_source = GenericData(
{
"format": "fwf",
"uri": "drops/daily_fixed.bin",
"options": {"widths": [10, 25, 12]},
}
)
Inline Query Parameters vs. reader_options#
Query parameters in unified URI strings (such as
cobol://layout.cbl::data.dat?encoding=cp500&include_filler=false or
fwf://fixed.txt?widths=[4,6]) are automatically parsed into Python types
(booleans, numbers, lists, strings) and merged into
reader_options. Explicit
reader_options passed to GenericData (or the
Reader Arguments column in an Excel driver workbook) override any matching
inline query keys.
Migrating from v1.x Bracket / Tuple Locators#
In DataSpector 2.0, the legacy bracketed ([...][...]) and tuple locator
formats were removed in favor of the unified URI/scheme syntax and
DataSourceSpec:
Removed v1.x Syntax |
v2.0 Unified Replacement |
|---|---|
|
|
|
|
|
|
|
|