Registry / ai-ml / pysmt
library0.9.6pypypi✓ verified 87d ago

PySMT is a Python library designed for solver-agnostic manipulation and solving of Satisfiability Modulo Theories (SMT) formulae. It provides a unified API to define, manipulate, and solve SMT problems using various SMT-LIB compliant solvers. The library is actively maintained, with regular releases, and its current stable version is 0.9.6.

pip install pysmt
INSTALL
IMPORT
SIG · PYSMT
P
pysmt
ai-mlpythonv0.9.6
Install
1.8s avg
Import
101ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.107s · 20.6MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.8s · import 0.095s · 21MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Symbol, And, Not, is_sat
from pysmt.shortcuts import Symbol, And, Not, is_sat
The `pysmt.shortcuts` module provides the most commonly used functions and operators for formula construction and solving.
INT, BOOL
from pysmt.typing import INT, BOOL
Data types for SMT variables (symbols) are defined in `pysmt.typing`.
Solver
from pysmt.shortcuts import Solver
For incremental solving or explicit solver control, use the `Solver` class from `shortcuts`.

This quickstart demonstrates defining Boolean SMT variables, constructing a logical formula, checking its satisfiability using a shortcut, performing variable substitution, and using an explicit solver to extract a model.

from pysmt.shortcuts import Symbol, And, Not, is_sat, Solver from pysmt.typing import BOOL # Define Boolean symbols varA = Symbol("A", BOOL) varB = Symbol("B", BOOL) # Construct a formula: (A AND (NOT B)) f = And([varA, Not(varB)]) # Check satisfiability using a shortcut res_f = is_sat(f) print(f"Formula '{f}' is SAT? {res_f}") # Perform a substitution: replace B with A in f, resulting in (A AND (NOT A)) g = f.substitute({varB: varA}) res_g = is_sat(g) print(f"Formula '{g}' is SAT? {res_g}") # Example with explicit solver and model extraction with Solver(name="z3", suppress_warnings=True) as solver: solver.add_assertion(f) if solver.solve(): print(f"Model for '{f}':") for s in [varA, varB]: print(f" {s} = {solver.get_value(s)}") else: print(f"'{f}' is UNSAT")
pysmt --version
Debug
Known issues
breakingPython 2.7 support was officially dropped in PySMT version 0.9.0. Versions 0.9.0 and later only support Python 3+. The last release to support Python 2.7 was 0.8.0.
fix
Upgrade to Python 3.5+ (recommended) or higher. For Python 2.7, use PySMT <0.9.0.
affects: >=0.9.0
gotchaWhen `pysmt.shortcuts` is imported, infix notation (e.g., `a & b`) is enabled by default. While convenient for quick experimentation, it can make complex code less clear by blurring the line between Python and SMT operators. For clarity, prefer explicit textual operators (e.g., `And(a, b)`).
fix
Import specific textual operators from `pysmt.shortcuts` (e.g., `from pysmt.shortcuts import And, Or, Not`) and use them directly for better code readability and to avoid unexpected operator precedence issues.
affects: All versions
gotchaSMT solvers are not direct Python dependencies of PySMT. While `pip install pysmt` installs the library, you need to explicitly install at least one solver (e.g., Z3, MathSAT) using `python -m pysmt install --<solver-name>` to perform actual solving. Solvers need to have their Python bindings accessible, potentially requiring `PYTHONPATH` adjustments for custom installations.
fix
Run `python -m pysmt install --<solver-name>` (e.g., `python -m pysmt install --z3`) to install a solver. If issues persist, check `pysmt-install --check` and ensure your `PYTHONPATH` includes the solver bindings directory, especially for non-standard installations.
affects: All versions
breakingThe classes `Integer`, `Fraction`, and `Numerals` were moved to `pysmt.constants` in version 0.6.0. Methods from `pysmt.utils` also moved to `pysmt.constants`. The `pysmt.numeral` module was removed.
fix
Update imports and references to use `pysmt.constants.Fraction` (or `Integer`, `Numerals`) instead of previous locations like `pysmt.numeral` or `pysmt.utils`.
affects: >=0.6.0
deprecatedThe methods `Solver.declare_variable` and `Solver.set_options` were removed in PySMT version 0.9.5.
fix
Remove calls to `Solver.declare_variable` as variables are typically declared via `Symbol()` and added to the solver with `add_assertion()`. For solver options, consult the documentation for solver-specific configuration or use the `Solver` constructor's `options` argument if available.
affects: >=0.9.5
Errors
Common errors & fixes
pysmt.exceptions.NoSolverAvailableError: No Solver is available
This error occurs when PySMT attempts to perform a solving operation (e.g., `is_sat()`, `Solver().solve()`) but cannot find an installed and accessible SMT solver. This could be because no solver was installed, or its Python bindings are not correctly configured.
fix
Install a solver using `python -m pysmt install --<solver-name>` (e.g., `python -m pysmt install --z3`). Verify installation with `pysmt-install --check`. If the solver was installed manually or in a non-standard location, ensure its Python bindings directory is added to your `PYTHONPATH`.
TypeError: unsupported operand type(s) for &: 'FNode' and 'bool'
This typically happens when mixing PySMT's infix operators (which expect `FNode` objects on both sides) with standard Python boolean literals or expressions without explicit conversion. For example, `f & True` might raise this if `True` isn't wrapped as a PySMT Boolean constant.
fix
Ensure all operands in SMT expressions are `FNode` objects. For Python boolean literals, use `Bool(True)` or `Bool(False)` from `pysmt.shortcuts`. Better yet, use explicit logical operators like `And()`, `Or()`, `Not()` to avoid ambiguity and improve clarity.
Solver installed, but `pysmt-install --check` or `is_sat()` still reports it as unavailable.
Even if `pysmt-install --<solver-name>` completes without errors, the Python bindings for the solver might not be correctly located by PySMT, particularly if they are installed in a non-default location or if the `PYTHONPATH` environment variable is not properly configured.
fix
After running `python -m pysmt install`, check the output for the location of the installed bindings. If they are not in a standard `site-packages` directory, you might need to manually add the path to your `PYTHONPATH` environment variable. For example, `export PYTHONPATH=$HOME/.smt_solvers/python_bindings:$PYTHONPATH`.
Upgrade
Version history
0.9.6latest on PyPI · released Jun 24, 2024
Audit
Dependencies
gmpy2optionalOptional, for efficient multi-precision number handling. Defaults to Python's fractions module if not installed.
CythonoptionalOptional, used to improve performance of some internal components, e.g., SMT-LIB parser.
Agent activity
16 hits · last 30 days
node
12
OpenAI (training)
1
Resources
pysmt — pip install pysmt · libregistry