provably 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.so
5
+ dist/
6
+ build/
7
+ *.egg-info/
8
+ .eggs/
9
+ *.egg
10
+ .mypy_cache/
11
+ .ruff_cache/
12
+ .pytest_cache/
13
+ .coverage
14
+ htmlcov/
15
+ site/
16
+ .venv/
17
+ venv/
18
+ .env
19
+ .uv/
20
+ uv.lock
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2026-02-28)
4
+
5
+ Initial release.
6
+
7
+ - `@verified` decorator for Z3-backed formal verification of Python functions
8
+ - Refinement types via `typing.Annotated` (`Ge`, `Le`, `Gt`, `Lt`, `Between`, `NotEq`)
9
+ - Python AST → Z3 translator supporting arithmetic, comparisons, if/elif/else, early returns, min/max/abs
10
+ - Bounded `for i in range(N)` loop unrolling (N must be a compile-time constant)
11
+ - Proof certificates attached to functions as `func.__proof__`
12
+ - `ProofCertificate.to_json()` / `from_json()` for serialization
13
+ - Module-level constant resolution from function globals
14
+ - Compositionality via `contracts=` parameter
15
+ - `@runtime_checked` decorator for pre/post contract checking without Z3
16
+ - `verify_module()` for batch verification of all `@verified` functions in a module
17
+ - `configure()` for global settings (timeout, raise_on_failure, log_level)
18
+ - Convenience type aliases: `Positive`, `NonNegative`, `UnitInterval`
19
+ - Deprecated `strict=` parameter on `@verified`; replaced by `raise_on_failure=`
20
+ - Graceful handling of async functions (attach SKIPPED cert, no crash)
21
+ - Contract arity validation with actionable error messages
22
+ - Line number information in `TranslationError` messages
23
+ - `z3-solver` is a required dependency, installed automatically with `pip install provably`
provably-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tim Jacoby
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,178 @@
1
+ Metadata-Version: 2.4
2
+ Name: provably
3
+ Version: 0.1.0
4
+ Summary: Proof-carrying Python functions via Z3 — annotate, verify, ship.
5
+ Project-URL: Homepage, https://github.com/awkronos/provably
6
+ Project-URL: Documentation, https://awkronos.github.io/provably
7
+ Project-URL: Repository, https://github.com/awkronos/provably
8
+ Project-URL: Bug Tracker, https://github.com/awkronos/provably/issues
9
+ Project-URL: Changelog, https://github.com/awkronos/provably/blob/main/CHANGELOG.md
10
+ Author: Tim Jacoby
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: contracts,formal-verification,refinement-types,static-analysis,z3
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Topic :: Software Development :: Quality Assurance
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.10
26
+ Requires-Dist: z3-solver>=4.12
27
+ Provides-Extra: dev
28
+ Requires-Dist: hypothesis>=6.100; extra == 'dev'
29
+ Requires-Dist: mkdocs-autorefs>=1.0; extra == 'dev'
30
+ Requires-Dist: mkdocs-material>=9.5; extra == 'dev'
31
+ Requires-Dist: mkdocstrings[python]>=0.24; extra == 'dev'
32
+ Requires-Dist: mypy>=1.9; extra == 'dev'
33
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
34
+ Requires-Dist: pytest-cov>=6.0; extra == 'dev'
35
+ Requires-Dist: pytest-timeout>=2.2; extra == 'dev'
36
+ Requires-Dist: pytest>=8.0; extra == 'dev'
37
+ Requires-Dist: ruff==0.14.0; extra == 'dev'
38
+ Provides-Extra: docs
39
+ Requires-Dist: mkdocs-autorefs>=1.0; extra == 'docs'
40
+ Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
41
+ Requires-Dist: mkdocstrings[python]>=0.24; extra == 'docs'
42
+ Description-Content-Type: text/markdown
43
+
44
+ # provably
45
+
46
+ **Z3-backed formal verification for Python -- via decorators and refinement types**
47
+
48
+ [![PyPI version](https://img.shields.io/pypi/v/provably?color=gold&labelColor=0a0a0f)](https://pypi.org/project/provably/)
49
+ [![Python versions](https://img.shields.io/pypi/pyversions/provably?labelColor=0a0a0f)](https://pypi.org/project/provably/)
50
+ [![License](https://img.shields.io/badge/license-MIT-green?labelColor=0a0a0f)](LICENSE)
51
+ [![CI](https://github.com/awkronos/provably/actions/workflows/ci.yml/badge.svg)](https://github.com/awkronos/provably/actions/workflows/ci.yml)
52
+ [![Coverage](https://img.shields.io/badge/coverage-99%25-brightgreen?labelColor=0a0a0f)](https://github.com/awkronos/provably/actions/workflows/ci.yml)
53
+ [![Typed](https://img.shields.io/badge/types-mypy%20strict-blue?labelColor=0a0a0f)](https://mypy.readthedocs.io/)
54
+ [![Docs](https://img.shields.io/badge/docs-awkronos.github.io-blue?labelColor=0a0a0f)](https://awkronos.github.io/provably/)
55
+
56
+ ---
57
+
58
+ ```python
59
+ from provably import verified
60
+
61
+ @verified(
62
+ pre=lambda val, lo, hi: lo <= hi,
63
+ post=lambda val, lo, hi, result: (result >= lo) & (result <= hi),
64
+ )
65
+ def clamp(val: float, lo: float, hi: float) -> float:
66
+ if val < lo:
67
+ return lo
68
+ elif val > hi:
69
+ return hi
70
+ else:
71
+ return val
72
+
73
+ clamp.__proof__.verified # True — for ALL inputs where lo <= hi
74
+ str(clamp.__proof__) # "[Q.E.D.] clamp"
75
+ ```
76
+
77
+ `verified=True` is a mathematical proof. Z3 determined that **no input** satisfying
78
+ the precondition can violate the postcondition.
79
+
80
+ ## Install
81
+
82
+ ```bash
83
+ pip install provably
84
+ # or: uv add provably
85
+ ```
86
+
87
+ ## Examples
88
+
89
+ ### Pre/post contracts
90
+
91
+ ```python
92
+ @verified(
93
+ pre=lambda a, b: b > 0,
94
+ post=lambda a, b, result: (result >= 0) & (result < b),
95
+ )
96
+ def modulo(a: int, b: int) -> int:
97
+ return a % b
98
+
99
+ modulo.__proof__.verified # True
100
+ modulo.__proof__.solver_time_ms # ~2ms
101
+ ```
102
+
103
+ ### Refinement types
104
+
105
+ ```python
106
+ from typing import Annotated
107
+ from provably.types import Between, Gt, NonNegative
108
+
109
+ @verified(post=lambda p, x, result: result >= 0)
110
+ def scale(
111
+ p: Annotated[float, Between(0, 1)],
112
+ x: Annotated[float, Gt(0)],
113
+ ) -> NonNegative:
114
+ return p * x
115
+
116
+ scale.__proof__.verified # True
117
+ ```
118
+
119
+ ### Counterexample extraction
120
+
121
+ ```python
122
+ @verified(
123
+ pre=lambda n: n >= 0,
124
+ post=lambda n, result: result * result == n, # wrong
125
+ )
126
+ def bad_sqrt(n: int) -> int:
127
+ return n // 2
128
+
129
+ bad_sqrt.__proof__.counterexample # {'n': 3, '__return__': 1}
130
+ ```
131
+
132
+ ### Compositionality
133
+
134
+ ```python
135
+ @verified(
136
+ contracts={"my_abs": my_abs.__contract__},
137
+ post=lambda x, y, result: result >= 0,
138
+ )
139
+ def manhattan(x: float, y: float) -> float:
140
+ return my_abs(x) + my_abs(y)
141
+
142
+ manhattan.__proof__.verified # True
143
+ ```
144
+
145
+ ## Supported constructs
146
+
147
+ | Construct | Supported |
148
+ |---|---|
149
+ | `+`, `-`, `*`, `//`, `/`, `%`, `**n` | Yes |
150
+ | `<`, `<=`, `>`, `>=`, `==`, `!=` | Yes |
151
+ | `and`, `or`, `not`, `&`, `\|`, `~` | Yes |
152
+ | `if`/`elif`/`else`/ternary | Yes |
153
+ | `min`, `max`, `abs` | Yes |
154
+ | `Annotated` refinement types | Yes |
155
+ | Calls via `contracts=` | Yes |
156
+ | `while` loops, unbounded `for` | No |
157
+ | `for i in range(N)` (literal N, max 256) | Yes (unrolled) |
158
+ | Recursion | No |
159
+ | `str`, `list`, `dict` | No |
160
+
161
+ ## Comparison
162
+
163
+ | Library | Approach | Proof strength | Call-site overhead |
164
+ |---|---|---|---|
165
+ | **provably** | SMT / Z3 | Mathematical proof | Zero solver overhead |
166
+ | `deal` | Runtime contracts | Bug finding | Per-call |
167
+ | `icontract` | Runtime contracts | Bug finding | Per-call |
168
+ | `CrossHair` | Symbolic execution | Property testing | Test-time |
169
+ | `beartype` | Runtime types | Type checking | Per-call |
170
+
171
+ ## Links
172
+
173
+ - [Documentation](https://awkronos.github.io/provably/)
174
+ - [Getting started](https://awkronos.github.io/provably/getting-started/)
175
+ - [How it works](https://awkronos.github.io/provably/concepts/how-it-works/)
176
+ - [Self-proof](https://awkronos.github.io/provably/self-proof/)
177
+ - [API reference](https://awkronos.github.io/provably/api/decorators/)
178
+ - [Changelog](CHANGELOG.md) | [License](LICENSE) (MIT)
@@ -0,0 +1,135 @@
1
+ # provably
2
+
3
+ **Z3-backed formal verification for Python -- via decorators and refinement types**
4
+
5
+ [![PyPI version](https://img.shields.io/pypi/v/provably?color=gold&labelColor=0a0a0f)](https://pypi.org/project/provably/)
6
+ [![Python versions](https://img.shields.io/pypi/pyversions/provably?labelColor=0a0a0f)](https://pypi.org/project/provably/)
7
+ [![License](https://img.shields.io/badge/license-MIT-green?labelColor=0a0a0f)](LICENSE)
8
+ [![CI](https://github.com/awkronos/provably/actions/workflows/ci.yml/badge.svg)](https://github.com/awkronos/provably/actions/workflows/ci.yml)
9
+ [![Coverage](https://img.shields.io/badge/coverage-99%25-brightgreen?labelColor=0a0a0f)](https://github.com/awkronos/provably/actions/workflows/ci.yml)
10
+ [![Typed](https://img.shields.io/badge/types-mypy%20strict-blue?labelColor=0a0a0f)](https://mypy.readthedocs.io/)
11
+ [![Docs](https://img.shields.io/badge/docs-awkronos.github.io-blue?labelColor=0a0a0f)](https://awkronos.github.io/provably/)
12
+
13
+ ---
14
+
15
+ ```python
16
+ from provably import verified
17
+
18
+ @verified(
19
+ pre=lambda val, lo, hi: lo <= hi,
20
+ post=lambda val, lo, hi, result: (result >= lo) & (result <= hi),
21
+ )
22
+ def clamp(val: float, lo: float, hi: float) -> float:
23
+ if val < lo:
24
+ return lo
25
+ elif val > hi:
26
+ return hi
27
+ else:
28
+ return val
29
+
30
+ clamp.__proof__.verified # True — for ALL inputs where lo <= hi
31
+ str(clamp.__proof__) # "[Q.E.D.] clamp"
32
+ ```
33
+
34
+ `verified=True` is a mathematical proof. Z3 determined that **no input** satisfying
35
+ the precondition can violate the postcondition.
36
+
37
+ ## Install
38
+
39
+ ```bash
40
+ pip install provably
41
+ # or: uv add provably
42
+ ```
43
+
44
+ ## Examples
45
+
46
+ ### Pre/post contracts
47
+
48
+ ```python
49
+ @verified(
50
+ pre=lambda a, b: b > 0,
51
+ post=lambda a, b, result: (result >= 0) & (result < b),
52
+ )
53
+ def modulo(a: int, b: int) -> int:
54
+ return a % b
55
+
56
+ modulo.__proof__.verified # True
57
+ modulo.__proof__.solver_time_ms # ~2ms
58
+ ```
59
+
60
+ ### Refinement types
61
+
62
+ ```python
63
+ from typing import Annotated
64
+ from provably.types import Between, Gt, NonNegative
65
+
66
+ @verified(post=lambda p, x, result: result >= 0)
67
+ def scale(
68
+ p: Annotated[float, Between(0, 1)],
69
+ x: Annotated[float, Gt(0)],
70
+ ) -> NonNegative:
71
+ return p * x
72
+
73
+ scale.__proof__.verified # True
74
+ ```
75
+
76
+ ### Counterexample extraction
77
+
78
+ ```python
79
+ @verified(
80
+ pre=lambda n: n >= 0,
81
+ post=lambda n, result: result * result == n, # wrong
82
+ )
83
+ def bad_sqrt(n: int) -> int:
84
+ return n // 2
85
+
86
+ bad_sqrt.__proof__.counterexample # {'n': 3, '__return__': 1}
87
+ ```
88
+
89
+ ### Compositionality
90
+
91
+ ```python
92
+ @verified(
93
+ contracts={"my_abs": my_abs.__contract__},
94
+ post=lambda x, y, result: result >= 0,
95
+ )
96
+ def manhattan(x: float, y: float) -> float:
97
+ return my_abs(x) + my_abs(y)
98
+
99
+ manhattan.__proof__.verified # True
100
+ ```
101
+
102
+ ## Supported constructs
103
+
104
+ | Construct | Supported |
105
+ |---|---|
106
+ | `+`, `-`, `*`, `//`, `/`, `%`, `**n` | Yes |
107
+ | `<`, `<=`, `>`, `>=`, `==`, `!=` | Yes |
108
+ | `and`, `or`, `not`, `&`, `\|`, `~` | Yes |
109
+ | `if`/`elif`/`else`/ternary | Yes |
110
+ | `min`, `max`, `abs` | Yes |
111
+ | `Annotated` refinement types | Yes |
112
+ | Calls via `contracts=` | Yes |
113
+ | `while` loops, unbounded `for` | No |
114
+ | `for i in range(N)` (literal N, max 256) | Yes (unrolled) |
115
+ | Recursion | No |
116
+ | `str`, `list`, `dict` | No |
117
+
118
+ ## Comparison
119
+
120
+ | Library | Approach | Proof strength | Call-site overhead |
121
+ |---|---|---|---|
122
+ | **provably** | SMT / Z3 | Mathematical proof | Zero solver overhead |
123
+ | `deal` | Runtime contracts | Bug finding | Per-call |
124
+ | `icontract` | Runtime contracts | Bug finding | Per-call |
125
+ | `CrossHair` | Symbolic execution | Property testing | Test-time |
126
+ | `beartype` | Runtime types | Type checking | Per-call |
127
+
128
+ ## Links
129
+
130
+ - [Documentation](https://awkronos.github.io/provably/)
131
+ - [Getting started](https://awkronos.github.io/provably/getting-started/)
132
+ - [How it works](https://awkronos.github.io/provably/concepts/how-it-works/)
133
+ - [Self-proof](https://awkronos.github.io/provably/self-proof/)
134
+ - [API reference](https://awkronos.github.io/provably/api/decorators/)
135
+ - [Changelog](CHANGELOG.md) | [License](LICENSE) (MIT)
@@ -0,0 +1,123 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "provably"
7
+ version = "0.1.0"
8
+ description = "Proof-carrying Python functions via Z3 — annotate, verify, ship."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ authors = [
12
+ { name = "Tim Jacoby" },
13
+ ]
14
+ keywords = ["formal-verification", "z3", "contracts", "refinement-types", "static-analysis"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Topic :: Software Development :: Libraries :: Python Modules",
25
+ "Topic :: Software Development :: Quality Assurance",
26
+ "Typing :: Typed",
27
+ ]
28
+ requires-python = ">=3.10"
29
+ dependencies = ["z3-solver>=4.12"]
30
+
31
+ [project.optional-dependencies]
32
+ dev = [
33
+ "pytest>=8.0",
34
+ "pytest-cov>=6.0",
35
+ "pytest-timeout>=2.2",
36
+ "pytest-asyncio>=0.23",
37
+ "hypothesis>=6.100",
38
+ "mypy>=1.9",
39
+ "ruff==0.14.0",
40
+ "mkdocs-material>=9.5",
41
+ "mkdocstrings[python]>=0.24",
42
+ "mkdocs-autorefs>=1.0",
43
+ ]
44
+ docs = [
45
+ "mkdocs-material>=9.5",
46
+ "mkdocstrings[python]>=0.24",
47
+ "mkdocs-autorefs>=1.0",
48
+ ]
49
+
50
+ [project.urls]
51
+ Homepage = "https://github.com/awkronos/provably"
52
+ Documentation = "https://awkronos.github.io/provably"
53
+ Repository = "https://github.com/awkronos/provably"
54
+ "Bug Tracker" = "https://github.com/awkronos/provably/issues"
55
+ Changelog = "https://github.com/awkronos/provably/blob/main/CHANGELOG.md"
56
+
57
+ [tool.hatch.build.targets.sdist]
58
+ include = [
59
+ "/src",
60
+ "/tests",
61
+ "/LICENSE",
62
+ "/README.md",
63
+ "/CHANGELOG.md",
64
+ "/pyproject.toml",
65
+ ]
66
+
67
+ [tool.hatch.build.targets.wheel]
68
+ packages = ["src/provably"]
69
+
70
+ # ---------------------------------------------------------------------------
71
+ # Ruff
72
+ # ---------------------------------------------------------------------------
73
+
74
+ [tool.ruff]
75
+ src = ["src"]
76
+ line-length = 99
77
+ target-version = "py310"
78
+
79
+ [tool.ruff.lint]
80
+ select = ["E", "F", "W", "I", "UP", "B", "C4", "SIM", "TID"]
81
+ ignore = ["E501", "SIM105"]
82
+
83
+ [tool.ruff.lint.per-file-ignores]
84
+ "tests/**" = ["S101", "F401", "F811", "E402", "F841", "E731"] # tests: assert, unused imports, redefined, late imports, unused vars, lambda assign
85
+
86
+ # ---------------------------------------------------------------------------
87
+ # Mypy
88
+ # ---------------------------------------------------------------------------
89
+
90
+ [tool.mypy]
91
+ python_version = "3.10"
92
+ strict = true
93
+ warn_return_any = false
94
+ warn_unused_ignores = false
95
+ mypy_path = "src"
96
+
97
+ [[tool.mypy.overrides]]
98
+ module = "z3.*"
99
+ ignore_missing_imports = true
100
+
101
+ # ---------------------------------------------------------------------------
102
+ # Pytest
103
+ # ---------------------------------------------------------------------------
104
+
105
+ [tool.pytest.ini_options]
106
+ testpaths = ["tests"]
107
+ addopts = "-v --tb=short"
108
+ asyncio_mode = "auto"
109
+
110
+ # ---------------------------------------------------------------------------
111
+ # Coverage
112
+ # ---------------------------------------------------------------------------
113
+
114
+ [tool.coverage.run]
115
+ source = ["src/provably"]
116
+ branch = true
117
+
118
+ [tool.coverage.report]
119
+ exclude_lines = [
120
+ "pragma: no cover",
121
+ "if TYPE_CHECKING:",
122
+ "raise NotImplementedError",
123
+ ]
@@ -0,0 +1,73 @@
1
+ """Provably — proof-carrying Python via Z3.
2
+
3
+ Annotate functions with contracts, get automatic formal proofs.
4
+
5
+ from provably import verified
6
+ from typing import Annotated
7
+ from provably.types import Ge
8
+
9
+ @verified(
10
+ pre=lambda x: x >= 0,
11
+ post=lambda x, result: result >= x,
12
+ )
13
+ def double(x: float) -> float:
14
+ return x * 2
15
+
16
+ assert double.__proof__.verified # Z3-proven for ALL inputs
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ __version__ = "0.1.0"
22
+
23
+ from z3 import And, Implies, Not, Or
24
+
25
+ from .decorators import ContractViolationError, VerificationError, runtime_checked, verified
26
+ from .engine import (
27
+ ProofCertificate,
28
+ Status,
29
+ clear_cache,
30
+ configure,
31
+ verify_function,
32
+ verify_module,
33
+ )
34
+ from .translator import TranslationError
35
+ from .types import (
36
+ Between,
37
+ Ge,
38
+ Gt,
39
+ Le,
40
+ Lt,
41
+ NonNegative,
42
+ NotEq,
43
+ Positive,
44
+ UnitInterval,
45
+ )
46
+
47
+ __all__ = [
48
+ "verified",
49
+ "runtime_checked",
50
+ "VerificationError",
51
+ "ContractViolationError",
52
+ "TranslationError",
53
+ "verify_function",
54
+ "verify_module",
55
+ "ProofCertificate",
56
+ "Status",
57
+ "clear_cache",
58
+ "configure",
59
+ "Gt",
60
+ "Ge",
61
+ "Lt",
62
+ "Le",
63
+ "Between",
64
+ "NotEq",
65
+ "Positive",
66
+ "NonNegative",
67
+ "UnitInterval",
68
+ "And",
69
+ "Or",
70
+ "Not",
71
+ "Implies",
72
+ "__version__",
73
+ ]