mpmath
Pure-Python library for arbitrary-precision floating-point arithmetic and numerical computation
Repository Health
Technical Analysis
mpmath implements arbitrary-precision real and complex floating-point arithmetic in Python, letting users compute with hundreds or thousands of digits of precision instead of the fixed 53-bit precision of native floats. Beyond basic arithmetic, it provides a comprehensive library of special functions (gamma, zeta, Bessel, hypergeometric, elliptic functions), numerical calculus (integration, differentiation, root-finding, ODE solving), and arbitrary-precision linear algebra.
Written and maintained by Fredrik Johansson, mpmath is a foundational dependency of SymPy (which uses it for numerical evaluation) and is used throughout the scientific Python ecosystem wherever exact-precision or high-precision numerical results are required, such as verifying symbolic results or evaluating special functions to guaranteed accuracy.
What You Get
- Arbitrary-precision real (
mpf) and complex (mpc) floating-point types with configurable precision - A large catalog of special functions: gamma, zeta, Bessel, hypergeometric, elliptic integrals, polylogarithms, and more
- Numerical calculus tools: adaptive quadrature, numerical differentiation, root-finding, and ODE solvers, all at arbitrary precision
- Arbitrary-precision matrix and linear algebra support via the
matricesmodule - Optional interval arithmetic (
ivcontext) and optional acceleration viagmpy2/python-gmpbackends
Common Use Cases
- Verifying or cross-checking symbolic math results numerically (this is exactly how SymPy uses mpmath internally)
- Evaluating special functions (Bessel, zeta, gamma, elliptic) to high precision for scientific computing
- Computing constants like pi or e to thousands of digits, or running high-precision numerical experiments
- Numerically solving equations, integrals, or ODEs where standard 64-bit floats lose accuracy
- Research and educational use requiring guaranteed numerical precision beyond hardware float limits
Under The Hood
Architecture
mpmath is organized around a set of interchangeable numerical “contexts” (ctx_mp.py for the default arbitrary-precision context, ctx_fp.py for a fast fixed-precision float context, ctx_iv.py for interval arithmetic), with libmp/ providing the low-level big-integer-backed floating-point kernel that every context builds on; functions/ and calculus/ layer special functions and numerical algorithms on top of whichever context is active, and matrices/ adds arbitrary-precision linear algebra.
Tech Stack
Pure Python by default (no compiled extensions required), with optional acceleration by installing gmpy2 or python-gmp for faster big-integer arithmetic; packaged with modern setuptools/setuptools-scm, targets Python 3.10+, and integrates with numpy/matplotlib only for its optional test and plotting extras.
Code Quality
The project has an extensive tests/ directory covering functions, calculus, matrices, and identification routines, plus flake518 linting and pytest-cov coverage tracking configured in develop extras; documentation is unusually thorough for a numerical library, with dedicated .rst pages for basics, contexts, calculus, matrices, and technical internals.
API Design
The primary interface mirrors ordinary Python numeric usage (mpmath.mpf('1.5'), mpmath.sqrt(2)) while precision is controlled globally via mpmath.mp.dps, making basic use approachable; deeper features like switching numerical contexts or configuring interval arithmetic require reading the context-specific docs, giving it a moderate learning curve for advanced use.
Used by 5 apps in this directory
Agno
Devops · AI Development · Automation
Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.
Helicone
Monitoring · AI Development · Analytics
An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.
marimo
Developer Tools · Data Engineering
A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.
SWIRL
Search · Databases · Data Engineering
Federated AI search and RAG across 100+ enterprise sources—no data extraction, no vector database required.
TDengine
Databases
A high-performance, open-source time-series database built in C for IoT, connected vehicles, and industrial monitoring workloads, with built-in stream processing, caching, and data subscription.