Python symbolic math libraries

Updated Nov 2026

Python symbolic math libraries manipulate mathematical expressions as symbols rather than as floating-point numbers. A computer algebra system simplifies, differentiates, and solves expressions before code generation turns the result into numerical functions. These libraries let engineers, researchers, and AI agents derive and check mathematical models in code.

Popularity

SymPy has the most monthly downloads in this comparison, at 169.9M.

LibraryMonthly downloadsStarsLast releaseLicense
SymPy
169.9M
15.1KApr 2025BSD
Z3
8.2M
13.0KNov 2026MIT
CVXPY
5.3M
6.4KSep 2026Apache-2.0
CasADi
4.1M
2.3KOct 2026LGPL-3.0-or-later
PyTensor
1.5M
654Nov 2026BSD-3-Clause
Pyomo
1.2M
2.6KJun 2026BSD-3-Clause
SymEngine
365.8K
189Oct 2026MIT
pySMT
47.9K
641Jun 2024Apache-2.0
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Features compared

LibrarySymbolic derivative expressionsSymbolic antiderivativesDCP rule checksBit-vector SMT queries
SymPyBuilt-inBuilt-inUnsupportedUnsupported
Z3UnsupportedUnsupportedUnsupportedBuilt-in
CVXPYUnsupportedUnsupportedBuilt-inUnsupported
CasADiBuilt-inUnsupportedUnsupportedUnsupported
PyTensorBuilt-inUnsupportedUnsupportedUnsupported
PyomoBuilt-inUnsupportedUnsupportedUnsupported
SymEngineBuilt-inUnsupportedUnsupportedUnsupported
pySMTUnsupportedUnsupportedUnsupportedVia plugin
Built-inVia pluginNot supported

Libraries and code examples

Performs symbolic calculus, equation solving, and expression manipulation.

Downloads / mo
169.9M
Stars
15.1K
Last release
1.14.0
License
BSD

Strengths

  • Handles symbolic calculus. Compute derivatives, integrals, limits, and series expansions.
  • Generates code for numerical use. Generate source code for later compilation or inclusion in another project.

Limitations

  • Assumptions control simplification. Declare positive or real symbols when those properties justify a simplification.
  • lambdify needs trusted expressions. Keep unsanitized input out of lambdify.

Quickstart

From intro.html
$ pip install sympy
from sympy import symbols, diff, cos

x = symbols('x')
derivative = diff(cos(x), x)

SymPy examples

From open-source projects on GitHub

Solves SMT problems.

Downloads / mo
8.2M
Stars
13.0K
Last release
5.4.1.0
License
MIT

Quickstart

From README.md
$ pip install z3-solver
from z3 import Real, simplify

x = Real('x')
expression = simplify(x + 0)

Z3 examples

From open-source projects on GitHub

Models convex optimization problems in Python.

Downloads / mo
5.3M
Stars
6.4K
Last release
1.9.3
License
Apache-2.0

Quickstart

From cvxpy.transforms.html
$ pip install cvxpy
from cvxpy import Variable
from cvxpy.transforms import linearize

x = Variable()
x.value = 2.0
tangent = linearize(x ** 2)

CVXPY examples

From open-source projects on GitHub

Builds symbolic models with automatic differentiation for numerical optimization.

Downloads / mo
4.1M
Stars
2.3K
Last release
3.8.2
License
LGPL-3.0-or-later

Strengths

  • Computes model derivatives. Build Jacobians and gradients from symbolic model expressions.
  • Generates self-contained C code. Export supported function objects as C code.

Limitations

  • Existing models need CasADi syntax. Reimplement existing models with CasADi expressions before using its differentiation tools.
  • Algebraic manipulation is limited. Choose a computer algebra system for broader symbolic expression manipulation.

Quickstart

From docs.md
$ pip install casadi
import casadi as ca

x = ca.SX.sym('x')
derivative = ca.jacobian(ca.sin(x), x)

CasADi examples

From open-source projects on GitHub

Compiles mathematical expressions for evaluation on CPUs and GPUs.

Downloads / mo
1.5M
Stars
654
Last release
3.3.8
License
BSD-3-Clause

Quickstart

From gradients.html
$ pip install pytensor
import pytensor
import pytensor.tensor as pt

x = pt.dscalar('x')
derivative = pt.grad(x ** 2, x)
evaluate = pytensor.function([x], derivative)
value = evaluate(3.0)

Models optimization problems.

Downloads / mo
1.2M
Stars
2.6K
Last release
6.10.1
License
BSD-3-Clause
$ pip install pyomo
from pyomo.environ import ConcreteModel, Var
from pyomo.core.expr.calculus.derivatives import differentiate, Modes

model = ConcreteModel()
model.x = Var(initialize=2)
derivative = differentiate(model.x ** 2, wrt=model.x, mode=Modes.reverse_symbolic)

Exposes the C++ SymEngine symbolic manipulation library to Python.

Downloads / mo
365.8K
Stars
189
Last release
0.15.0
License
MIT

Strengths

  • Creates numerical callbacks. Turn symbolic expressions into callbacks accepting real or complex numerical inputs.
  • Expands symbolic expressions. Build expressions with symbols and expand their products.

Limitations

  • LLVM needs a compatible build. Select the LLVM backend only in builds compiled with LLVM support.
  • Source builds need matching core. Use the supported SymEngine core revision when building the Python wrapper.

Quickstart

From README.md
$ pip install symengine
from symengine import Symbol

x, y = Symbol('x'), Symbol('y')
expanded = ((x + y) ** 2).expand()

Manipulates and solves SMT formulas across solvers.

Downloads / mo
47.9K
Stars
641
Last release
0.9.6
License
Apache-2.0

Quickstart

From shortcuts.py
$ pip install pysmt
from pysmt.shortcuts import Symbol, Int, Plus, simplify
from pysmt.typing import INT

x = Symbol('x', INT)
expression = simplify(Plus(x, Int(0)))

pySMT examples

From open-source projects on GitHub

FAQ

SymPy suits general computer algebra, symbolic calculus, and equation solving. CVXPY and Pyomo suit optimization models. Z3 suits satisfiability problems over arithmetic, Boolean, and bit-vector expressions. CasADi suits numerical optimization that needs automatic derivatives.

SymPy is a computer algebra system in Python for symbolic calculus, equation solving, and expression manipulation. It also generates code for numerical use.

CVXPY is a domain-specific language for modeling convex optimization problems in Python.

Pyomo is an optimization modeling framework with algebraic modeling expressions and interfaces to solvers.

CasADi builds symbolic models with automatic differentiation for numerical optimization and generates self-contained C code. Existing models must be rewritten in CasADi syntax.

For coding agents

Found your symbolic math library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official