API Reference

SymPy

Symbolic mathematics library for Python supporting algebra, calculus, equation solving, and exact expressions.

Official Documentation ↗
CompatibilityThis documentation covers version v1.13. Check the official docs for the latest API surface.

Installation

pippip install sympy

Methods

Overview

SymPy is a symbolic mathematics library for Python supporting algebra, calculus, and exact equation solving. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.

Core APIs

  • symbols — Creates symbolic variables that expressions can be built from.
  • diff — Differentiates an expression symbolically with respect to one or more variables.
  • solve — Solves equations for the given symbols, returning exact solutions.

Example

import sympy as sp

x, y = sp.symbols('x y')
expr = x**2 + 3*y
print(expr)

Notes

Symbolic results are exact and often not in the form you expect; simplify or nsimplify before comparing. Evaluation is separate via evalf.

Verification

Differentiate x cubed and confirm the exact derivative is 3*x squared.

API reference evidence

Fetched from official sources on 2026-11-08T17:33:00+08:00 via WebFetch https://docs.sympy.org/latest/modules/solvers/solvers.html;WebFetch https://docs.sympy.org/latest/modules/core.html.

FAQ

How do I get a numeric result from a symbolic expression?
Use expr.evalf() or substitute values with expr.subs({x: 2}) then evaluate, since symbols stay exact until evaluated.
Why is solve returning a different form than expected?
solve returns exact expressions that may look rewritten; apply simplify or nsimplify to compare forms.
How do I compute a definite integral?
Pass bounds to integrate, for example sp.integrate(x**2, (x, 0, 1)), to get an exact definite result.