Skip to main content

A production-ready auto-active verification system for Python, similar to Dafny and Verus

Project description

Veripy

A production-ready auto-active verification system for Python, similar to Dafny and Verus.

Overview

Veripy transforms Python code verification from a work-in-progress into a production-ready system with automatic invariant inference, comprehensive error reporting, and a professional CLI.

Soundness note

Veripy is not sound for full Python today. The core VC engine is intended to be sound for a restricted, “verification-oriented” subset (roughly: side-effect-free code over int/bool plus mathematical arrays, with structured if/while, and user-supplied invariants), and it rejects or approximates many Python features (exceptions, dynamic dispatch, aliasing/mutation semantics of real lists/dicts/objects, etc.).

Recent work is moving toward a Dafny/Boogie-style explicit heap model for aliasing + mutation (lists/dicts/fields as references) and for exception safety (e.g., bounds and div/mod by zero become proof obligations). This is still a work in progress and many Python features remain unsupported.

Key Features

Auto-Active Verification

  • Automatic loop invariant inference
  • Type-based constraint generation
  • Arithmetic lemma automation
  • Multiple inference strategies (NONE, SIMPLE, AGGRESSIVE, FULL)

Production Readiness

  • Professional CLI with multiple commands
  • Rich terminal output with syntax highlighting
  • JSON output for CI/CD
  • Comprehensive error reporting with counterexamples
  • Source location tracking

Recursive Functions

  • Termination checking with decreases clauses
  • Tail recursion detection
  • Call graph analysis

Installation

pip install py-veripy

For development:

make install-dev

Usage

Basic Verification

import veripy as vp

vp.enable_verification()

@vp.verify(requires=['x > 0'], ensures=['ans == x * 2'])
def double(x: int) -> int:
    return x * 2

vp.verify_all()

Deppy-Style Contracts

import veripy as vp

vp.enable_verification()
vp.scope("demo")

@vp.verify()
@vp.requires("x > 0")
@vp.guarantee("result > x")
def succ(x: int) -> int:
    return x + 1

vp.verify_all()

Veripy normalizes Deppy-style result postconditions to its internal ans binding and also exposes lightweight sidecar metadata helpers such as @vp.about(...), @vp.proof_for(...), and @vp.z3_hint(...).

Lean4 Export

import veripy as vp

@vp.verify(requires=["x > 0"], ensures=["ans > x"])
def succ(x: int) -> int:
    return x + 1

cert = vp.compile_to_lean(succ)
print(cert.render())

# Optional, if Lean is installed locally:
# cert.verify_with_lean()

The Lean backend now exports Veripy's actual heap-lowered VC obligations rather than re-translating raw Python syntax. In practice that means the generated Lean theorems track the same pre => wp and side-condition formulas the SMT backend checks, including summary assumptions for verified callees and explicit heap state binders when lists/dicts/fields are involved.

CLI Usage

# Verify files
veripy verify file.py

# With counterexamples and statistics
veripy verify --counterexample --statistics file.py

# JSON output for CI/CD
veripy verify --output json file.py

Auto-Active Features

from veripy.auto_active import auto_infer_invariants

invariants = auto_infer_invariants({
    "loop_var": "i",
    "init": 0,
    "condition": "i < n",
    "body": []
})

Architecture

veripy/
├── core/           # Verification condition generation, AST transformation
├── auto_active/    # Auto-active features (invariant inference, lemmas)
├── cli/            # Command-line interface
├── parser/         # Syntax parsing
├── typecheck/      # Type checking
├── error_reporter.py
├── recursive.py
└── prettyprint.py

Development

make test          # Run tests
make test-cov      # With coverage
make lint          # Linting
make format        # Formatting
make typecheck     # Type checking
make check         # All checks

Dependencies

  • z3-solver - SMT solver
  • rich - Terminal output
  • click - CLI framework
  • pyparsing - Expression parsing
  • apronpy - Abstract interpretation

Related Work

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

py_veripy-0.1.1.tar.gz (105.6 kB view details)

Uploaded Source

Built Distribution

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

py_veripy-0.1.1-py3-none-any.whl (124.7 kB view details)

Uploaded Python 3

File details

Details for the file py_veripy-0.1.1.tar.gz.

File metadata

  • Download URL: py_veripy-0.1.1.tar.gz
  • Upload date:
  • Size: 105.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for py_veripy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 240dda9895446bddd161f34abc08f17d055170b89e68f07e777ccb968309ee4b
MD5 a09d611bb7b5fde4b69ba2b8557307da
BLAKE2b-256 24a6cae0ff9e455141dbe844320302651f47c96f7344d17375f9afe62f0a65a5

See more details on using hashes here.

File details

Details for the file py_veripy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: py_veripy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 124.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for py_veripy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1e1159c17694ff61758a7b0040470e319eb2f0171c5ab00160acc42d6efd9863
MD5 4d513dd3c8354a5b712f18157df7e1f9
BLAKE2b-256 a746ae9d9772c8cf74eb6c44b2fa0744d7fbcc3783e817969ea9aa99798c12da

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