Skip to main content

Run SQL expectation checks against a database.

Project description

small-expectations

Simple SQL-based expectations runner.

codecov PyPI Python Versions License Docs

Install

pip install small-expectations

Usage

Create smallex.toml:

[database]
engine = "sqlite"

[database.connection]
database = "example.db"

Supported engines:

  • sqlite
  • snowflake
  • databricks

Example snowflake config:

[database]
engine = "snowflake"

[database.connection]
account = "my-account"
user = "my-user"
password = "my-password"
warehouse = "my-warehouse"
database = "my-database"
schema = "public"

Example databricks config:

[database]
engine = "databricks"

[database.connection]
server_hostname = "adb-1234567890123456.7.azuredatabricks.net"
http_path = "/sql/1.0/warehouses/abc123"
access_token = "dapi..."

Add SQL files under tests/:

SELECT * FROM users WHERE email IS NULL;

You can define multiple tests in one SQL file with metadata comments:

-- smallex:test: no_null_emails
-- smallex:message: users.email should never be null
SELECT id, email
FROM users
WHERE email IS NULL;

-- smallex:test: no_duplicate_emails
-- smallex:message: users.email should be unique
SELECT email, COUNT(*) AS duplicates
FROM users
WHERE email IS NOT NULL
GROUP BY email
HAVING COUNT(*) > 1;

Metadata markers:

  • -- smallex:test: <name>: logical test name (used in output as file.sql::<name>).
  • -- smallex:message: <message>: failure message shown in terminal summary and failure details.

Run:

smallex run

Show command help:

smallex run --help

A test passes when the query returns zero rows and fails if it returns one or more rows. The terminal report follows a pytest-like style (session header, per-test ./F, failure details, and short summary info).

Failure rows output

By default, failing rows are not printed or exported.

You can configure this behavior:

smallex run \
  --failure-rows-mode terminal \
  --failure-rows-limit 5
smallex run \
  --failure-rows-mode csv \
  --failure-rows-csv-limit 10000 \
  --failure-rows-dir .smallex/failures
smallex run \
  --failure-rows-mode both \
  --failure-rows-limit 5 \
  --failure-rows-csv-limit 10000

Options:

  • --config: path to TOML config file (default: smallex.toml)
  • --tests-dir: root folder containing .sql test files (default: tests)
  • --color: auto | yes | no (default: auto)
  • --failure-rows-mode: none | terminal | csv | both (default: none)
  • --failure-rows-limit: top rows shown in terminal per failing test (default: 5)
  • --failure-rows-csv-limit: max rows written to CSV per failing test (default: 10000)
  • --failure-rows-dir: output directory for CSV files (default: .smallex/failures)

Testing

The test suite includes:

  • CLI + SQLite integration tests using a temporary local database.
  • Backend unit tests that mock Snowflake and Databricks connectors so no real cloud connections are required.

Documentation

This repository uses MkDocs + Material.

Run docs locally:

pip install ".[docs]"
mkdocs serve

Build static docs:

mkdocs build

GitHub Pages is deployed automatically from .github/workflows/docs.yml on pushes to main.

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

small_expectations-0.2.2.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

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

small_expectations-0.2.2-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file small_expectations-0.2.2.tar.gz.

File metadata

  • Download URL: small_expectations-0.2.2.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for small_expectations-0.2.2.tar.gz
Algorithm Hash digest
SHA256 0e6665fdd6d61cbf6bba21d33b6c09fb5afb7074db26095c89a1b5fcc184c1b4
MD5 082edf9615f710ef4f876a3d192e4165
BLAKE2b-256 ba0e04a794ad19ac3f2df5a95b31ecb3ce481ff6779c8f2ec4ce21e1f333454d

See more details on using hashes here.

File details

Details for the file small_expectations-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for small_expectations-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9320478cca6c3f09ea21d26760de3be99499f7b86e77eadd90ab95dca128b016
MD5 2f20c3bdeb54d96018f3a1b01b4f348b
BLAKE2b-256 523ec25736555e490f2128406adc4c30f9a6ee777dec062f9b96cd11befa1bda

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