Metadata-Version: 2.5
Name: sverify
Version: 0.9.0
Summary: Contracts and incremental views, proven in Lean, on DuckDB, Polars, Spark and Snowflake
Project-URL: Homepage, https://github.com/AlexanderNenninger/substrait-lean
Project-URL: Documentation, https://alexandernenninger.github.io/substrait-lean/
Project-URL: Source, https://github.com/AlexanderNenninger/substrait-lean
Project-URL: Issues, https://github.com/AlexanderNenninger/substrait-lean/issues
Author-email: Alexander Nenninger <alexander.nenninger@live.de>
License-Expression: MPL-2.0 AND Apache-2.0
License-File: LICENSE
License-File: src/sverify/ibis_substrait/LICENSE
Requires-Python: >=3.12
Requires-Dist: ibis-framework>=12.0.0
Requires-Dist: packaging>=23
Requires-Dist: pyarrow-hotfix>=0.6
Requires-Dist: pyarrow>=26.0.0
Requires-Dist: sqlglot<30.18,>=30.8.0
Requires-Dist: substrait>=0.37.0
Requires-Dist: sverify-duckdb==0.9.0
Provides-Extra: all
Requires-Dist: deltalake>=1.6.6; extra == 'all'
Requires-Dist: hypothesis>=6.170.14; extra == 'all'
Requires-Dist: ibis-framework[duckdb]>=12.0.0; extra == 'all'
Requires-Dist: openlineage-python<2,>=1.55.0; extra == 'all'
Requires-Dist: pyarrow>=26.0.0; extra == 'all'
Requires-Dist: pyiceberg[pyarrow,sql-sqlite]>=0.12.0; extra == 'all'
Requires-Dist: pytest>=9.2.0; extra == 'all'
Requires-Dist: pyyaml>=6.0; extra == 'all'
Requires-Dist: sverify-duckdb[run]==0.9.0; extra == 'all'
Requires-Dist: sverify-polars[run]==0.9.0; extra == 'all'
Requires-Dist: sverify-spark[run]==0.9.0; extra == 'all'
Provides-Extra: delta
Requires-Dist: deltalake>=1.6.6; extra == 'delta'
Provides-Extra: duckdb
Requires-Dist: ibis-framework[duckdb]>=12.0.0; extra == 'duckdb'
Requires-Dist: sverify-duckdb[run]==0.9.0; extra == 'duckdb'
Provides-Extra: flight
Requires-Dist: pyarrow>=26.0.0; extra == 'flight'
Provides-Extra: iceberg
Requires-Dist: pyiceberg[pyarrow,sql-sqlite]>=0.12.0; extra == 'iceberg'
Provides-Extra: odcs
Requires-Dist: pyyaml>=6.0; extra == 'odcs'
Provides-Extra: openlineage
Requires-Dist: openlineage-python<2,>=1.55.0; extra == 'openlineage'
Provides-Extra: polars
Requires-Dist: sverify-polars[run]==0.9.0; extra == 'polars'
Provides-Extra: secrets-aws
Requires-Dist: boto3>=1.35; extra == 'secrets-aws'
Provides-Extra: secrets-azure
Requires-Dist: azure-identity>=1.17; extra == 'secrets-azure'
Requires-Dist: azure-keyvault-secrets>=4.8; extra == 'secrets-azure'
Provides-Extra: secrets-gcp
Requires-Dist: google-cloud-secret-manager>=2.20; extra == 'secrets-gcp'
Provides-Extra: secrets-keychain
Requires-Dist: keyring>=25; extra == 'secrets-keychain'
Provides-Extra: spark
Requires-Dist: ibis-framework[duckdb]>=12.0.0; extra == 'spark'
Requires-Dist: sverify-duckdb[run]==0.9.0; extra == 'spark'
Requires-Dist: sverify-spark[run]==0.9.0; extra == 'spark'
Provides-Extra: testing
Requires-Dist: hypothesis>=6.170.14; extra == 'testing'
Requires-Dist: pytest>=9.2.0; extra == 'testing'
Description-Content-Type: text/markdown

# sverify

> Sverify is a working prototype. Its Lean proofs, its checker and its Python
> code still need a human audit before anyone relies on their results.
>
> [How this project is built](https://github.com/AlexanderNenninger/substrait-lean/blob/v0.9.0/docs/how-this-is-built.md)
> says who writes it and what you can check yourself.

Sverify proves a data pipeline's contracts in Lean before it runs, keeps the
result up to date from Delta and Iceberg changes, and runs the checked plan on
DuckDB, Polars and Spark.

It finds the bugs that tests on sample data miss:

* A duplicate that arrives late, or a payment that is reversed, in an incremental job ([the tour's first notebook](https://molab.marimo.io/github/AlexanderNenninger/substrait-lean/blob/published/notebooks/01_duplicate_payments.py)).
* Ties and NaN readings that change a window's result, and SQL that only runs alike on some engines ([second notebook](https://molab.marimo.io/github/AlexanderNenninger/substrait-lean/blob/published/notebooks/02_sensor_alerts.py)).
* A dbt test on a point-in-time join to a type-2 dimension, proved as a contract, and the promises a left join's NULL padding breaks ([third notebook](https://molab.marimo.io/github/AlexanderNenninger/substrait-lean/blob/published/notebooks/03_orders_mart.py), [what a left join keeps](https://github.com/AlexanderNenninger/substrait-lean/blob/v0.9.0/docs/proved-theorems.md#contracts)).
* Division by zero, integer overflow and bad casts ([the runtime-error theorems](https://github.com/AlexanderNenninger/substrait-lean/blob/v0.9.0/docs/proved-theorems.md#runtime-errors)).

[How sverify compares](https://github.com/AlexanderNenninger/substrait-lean/blob/v0.9.0/docs/comparison.md) with dbt tests, Great Expectations, Soda and data contracts says what it does not do.

## In thirty lines

```python
import pyarrow as pa
import sverify as sv
from ibis import _
from sverify.io import Changes, StaticSource

orders = StaticSource(  # in memory; DeltaSource and IcebergSource work the same way
    pa.table({"id": [1, 2], "customer": ["ada", "bob"], "amount": [30, 5]}), name="orders"
)


# The upper bound on amount keeps `amount * 2` within 64 bits. Leave it out and
# the report names the bound to declare.
@sv.transform(
    requires={"orders": [_.amount >= 0, _.amount < 1_000_000_000, sv.unique("id")]},
    ensures=[_.doubled >= 22, _.doubled.notnull(), sv.unique("id")],
)
def big_orders(orders):
    return orders.filter(orders.amount > 10).select(orders.id, doubled=orders.amount * 2)


big = orders.pipe(big_orders)  # proved here, before any data runs
big.refresh()  # computed, on DuckDB by default
orders.apply(Changes(inserts=[(3, "cy", 50)], deletes=[(1, "ada", 30)]))
big.refresh(engine="polars", route="auto")  # updated from the changes alone, on Polars
assert big.to_arrow().to_pylist() == [{"id": 3, "doubled": 100}]
print(big_orders.report)
# proved
# The output guarantees:
#   doubled ≥ 22
#   doubled is never NULL
#   no two rows share id
# ...
```

`print(big_orders.report.details())` goes on with the evidence for each engine, and `sverify check` prints the same contract.
A postcondition that does not follow is refused before anything runs, with the precondition that would make it hold
([Contracts](https://github.com/AlexanderNenninger/substrait-lean/blob/v0.9.0/docs/how-to-contracts.md)).

## Install

```bash
# skip: installs software on the reader's machine
pip install 'sverify[duckdb]'      # or: uv add 'sverify[duckdb]'; verifies and runs plans on DuckDB, the default engine
pip install sverify                # verifies only, runs nothing
pip install 'sverify[all]'         # with every engine in the 1.x promise and both table formats
```

Linux and macOS (Python 3.12 and later); Windows through WSL2.
[Install](https://github.com/AlexanderNenninger/substrait-lean/blob/v0.9.0/docs/how-to-install.md) has the extras, the wheels and the nightly builds.

In CI, `sverify check pipelines/orders.py` proves every transform and node in the file and exits 0 when all are proved, 1 when one is not, and 3 when a construct is outside sverify's model; `--format sarif` writes a report for GitHub's code scanning ([the command line](https://github.com/AlexanderNenninger/substrait-lean/blob/v0.9.0/docs/how-to-command-line.md#the-command-line)).

## Go on from here

* [Getting started](https://alexandernenninger.github.io/substrait-lean/examples/examples.html), ten steps from a first contract to Substrait's own semantics, and [the tour](https://github.com/AlexanderNenninger/substrait-lean/tree/v0.9.0/notebooks), three guides that run locally with `uvx marimo edit --sandbox notebooks`.
* [The how-to pages](https://github.com/AlexanderNenninger/substrait-lean/blob/v0.9.0/docs/tasks.md), one task each, and [what sverify proves](https://github.com/AlexanderNenninger/substrait-lean/blob/v0.9.0/docs/what-sverify-proves.md).
* [The site](https://alexandernenninger.github.io/substrait-lean/): the API reference of the released version, the [ledgers](https://alexandernenninger.github.io/substrait-lean/ledgers/) of upstream bugs and engine facts, and [skills](https://alexandernenninger.github.io/substrait-lean/skills.html) for coding agents.
* [Status](https://github.com/AlexanderNenninger/substrait-lean/blob/v0.9.0/docs/stability.md#status) and the [repository](https://github.com/AlexanderNenninger/substrait-lean), to work on sverify.

## License

Sverify is licensed under the [Mozilla Public License 2.0](https://github.com/AlexanderNenninger/substrait-lean/blob/v0.9.0/LICENSE) (MPL-2.0), file by file: your own code stays yours, and a modified version of sverify's own files stays under the MPL with its source shared.
`python/src/sverify/ibis_substrait/` is derived from [ibis-substrait](https://github.com/ibis-project/ibis-substrait) and stays under the [Apache License 2.0](https://github.com/AlexanderNenninger/substrait-lean/blob/v0.9.0/python/src/sverify/ibis_substrait/LICENSE).
