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.
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 API —
Int,Real,Bool,BitVec,Array,Solver,Optimize,ForAll,Exists,Datatype, and more - Pure Python — zero dependencies, installable via
micropipin 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4b46f7d6dc97a606f56222f394f37a617636e6d54733f1e6692d4d8bb8e1b10
|
|
| MD5 |
aa03d881457b936737d2f1ce69eb93ec
|
|
| BLAKE2b-256 |
d830eb1d014998f51ad0a38646b36754a2ca61fcd15b9d050780391e39810243
|
Provenance
The following attestation bundles were made for z3_pyodide-0.1.0.tar.gz:
Publisher:
publish.yml on alcides/z3-pyodide
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
z3_pyodide-0.1.0.tar.gz -
Subject digest:
c4b46f7d6dc97a606f56222f394f37a617636e6d54733f1e6692d4d8bb8e1b10 - Sigstore transparency entry: 1133032665
- Sigstore integration time:
-
Permalink:
alcides/z3-pyodide@bd6ee66452e00fe61aad66d89e6733034ae650f2 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/alcides
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bd6ee66452e00fe61aad66d89e6733034ae650f2 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0974ab3197c3b1efd9b366e94df7d455ab507fd712bcd6e825f6c8231bcb107
|
|
| MD5 |
50248b257eea97430b647292241007f5
|
|
| BLAKE2b-256 |
7e3db72bd60bf64319beca03264a5d7e4d38e42ffefacfe34cf9e873a30c5d0b
|
Provenance
The following attestation bundles were made for z3_pyodide-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on alcides/z3-pyodide
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
z3_pyodide-0.1.0-py3-none-any.whl -
Subject digest:
f0974ab3197c3b1efd9b366e94df7d455ab507fd712bcd6e825f6c8231bcb107 - Sigstore transparency entry: 1133032697
- Sigstore integration time:
-
Permalink:
alcides/z3-pyodide@bd6ee66452e00fe61aad66d89e6733034ae650f2 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/alcides
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bd6ee66452e00fe61aad66d89e6733034ae650f2 -
Trigger Event:
release
-
Statement type: