mpmath

Pure-Python library for arbitrary-precision floating-point arithmetic and numerical computation

Library
PyPI
v1.4.1
1,213 stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
86 /100 Excellent
Development Activity 100
Maintenance 72
Community 84
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
75 /100 Good
Architecture 80
Code Quality 82
Innovation 78
Learning Curve 60

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 matrices module
  • Optional interval arithmetic (iv context) and optional acceleration via gmpy2/python-gmp backends

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

Python
100%
Apache 2.0

Agno

AI Development · Automation · Devops

42,358

Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.

View details
93
Repo Health
87
Technical
66
Dependency
Built with
Python 100%
Updated 4 days ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,182

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.

View details
70
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 2 weeks ago
Python
62%
Apache 2.0

marimo

Data Engineering · Developer Tools

22,918

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.

View details
89
Repo Health
91
Technical
65
Dependency
Built with
Python 62%
TypeScript 37%
Updated 5 days ago
Python
94%
Apache 2.0

SWIRL

Data Engineering · Databases · Search

3,047

Federated AI search and RAG across 100+ enterprise sources—no data extraction, no vector database required.

View details
62
Repo Health
83
Technical
65
Dependency
Built with
Python 94%
Updated 6 days ago
C
76%
AGPL 3.0

TDengine

Databases

25,146

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.

View details
97
Repo Health
71
Technical
68
Dependency
Built with
C 76%
C++ 16%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers