Skip to main content

z3-py compatible API for Pyodide (browser) via SMT-LIB2 text protocol

Project description

z3-pyodide

A pure-Python Z3 theorem prover package that works in the browser via Pyodide. Provides a z3-py compatible API using the SMT-LIB2 text protocol, communicating with Z3 compiled to WebAssembly.

Live Demo

Quick Example

from z3_pyodide import *

x, y = Ints('x y')
s = Solver()
s.add(x + y == 10)
s.add(x > 0, y > 0)
s.add(x > y)

if s.check() == sat:
    m = s.model()
    print(f"x = {m[x]}, y = {m[y]}")  # x = 9, y = 1

Features

  • z3-py compatible APIInt, Real, Bool, BitVec, Array, Solver, Optimize, ForAll, Exists, Datatype, and more
  • Pure Python — zero dependencies, installable via micropip in Pyodide
  • Dual backend — subprocess (CPython) and WebAssembly (Pyodide), auto-detected
  • SMT-LIB2 protocol — generates SMT-LIB2 text, sends to Z3, parses results

Supported theories

Theory Types Operations
Integers Int, IntVal +, -, *, /, %, comparisons
Reals Real, RealVal arithmetic, ToReal, ToInt
Booleans Bool, BoolVal And, Or, Not, Implies, Xor
BitVectors BitVec, BitVecVal bitwise ops, shifts, Extract, Concat, ZeroExt, SignExt
Arrays Array Select, Store, K (constant arrays)
Datatypes Datatype enums, records, recursive types, mutual recursion
Quantifiers ForAll, Exists with uninterpreted Function
Optimization Optimize minimize, maximize

Installation

In Pyodide (browser)

import micropip
await micropip.install('z3_pyodide')  # once published to PyPI

Local development (CPython)

pip install z3-solver  # provides the Z3 binary
pip install -e .       # install z3_pyodide

Running the example page locally

bash examples/setup.sh    # downloads Z3 WASM (~17 MB, one time)
python3 examples/server.py  # serves on http://localhost:8000

Running tests

pip install z3-solver pytest
pytest tests/ -v

Architecture

Python code  →  AST (ExprRef, BoolRef, ArithRef, ...)
                  ↓
             SMT-LIB2 text generation
                  ↓
             Backend (subprocess z3 or WASM z3)
                  ↓
             S-expression parser  →  Model extraction

The package builds a Python AST with operator overloading (x + y == 10), serializes it to SMT-LIB2 text, sends it to Z3 via either a local subprocess or a WASM Web Worker, and parses the results back into Python objects.

License

MIT

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

z3_pyodide-0.1.0.tar.gz (61.7 kB view details)

Uploaded Source

Built Distribution

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

z3_pyodide-0.1.0-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

Details for the file z3_pyodide-0.1.0.tar.gz.

File metadata

  • Download URL: z3_pyodide-0.1.0.tar.gz
  • Upload date:
  • Size: 61.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for z3_pyodide-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c4b46f7d6dc97a606f56222f394f37a617636e6d54733f1e6692d4d8bb8e1b10
MD5 aa03d881457b936737d2f1ce69eb93ec
BLAKE2b-256 d830eb1d014998f51ad0a38646b36754a2ca61fcd15b9d050780391e39810243

See more details on using hashes here.

Provenance

The following attestation bundles were made for z3_pyodide-0.1.0.tar.gz:

Publisher: publish.yml on alcides/z3-pyodide

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file z3_pyodide-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: z3_pyodide-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 28.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for z3_pyodide-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f0974ab3197c3b1efd9b366e94df7d455ab507fd712bcd6e825f6c8231bcb107
MD5 50248b257eea97430b647292241007f5
BLAKE2b-256 7e3db72bd60bf64319beca03264a5d7e4d38e42ffefacfe34cf9e873a30c5d0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for z3_pyodide-0.1.0-py3-none-any.whl:

Publisher: publish.yml on alcides/z3-pyodide

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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