Science

Libraries for scientific computing. Also see Python-for-Scientists.

Underneath most Python scientific computing libraries sits NumPy's array. SciPy adds algorithms on top, and Numba compiles loops that won't vectorize.

How to choose:

  • Arrays and vectorized math: NumPy
  • Optimization, integration, interpolation, and linear algebra: SciPy
  • Numeric loops that won't vectorize: Numba
  • Exact, symbolic math: SymPy
  • Regression, time series, and hypothesis tests: statsmodels
  • Biological sequences and file formats: Biopython; molecules: RDKit
  • Physical units: Pint; astronomy: Astropy; seismology: ObsPy
  • Bayesian models: PyMC
  • Discrete-event simulations: SimPy; agent-based models: Mesa
  • Graphs and networks: NetworkX
  • Planar geometry: Shapely
  • Colour science: Colour; math animations: Manim

Listed in editorial order, grouped by use case. Click a column header to re-sort the whole list.

Press / to search. Tags open their category. Click a row for details.

Search and filter

Results

Row number Tags

Core 3 projects

A fundamental package for scientific computing with Python.
numpy/github.com/numpy/numpy /33,198 stars /
Fundamental algorithms for scientific computing in Python.
scipy/github.com/scipy/scipy /15,166 stars /
A NumPy-aware JIT compiler for Python, using LLVM.
numba/github.com/numba/numba /11,194 stars /

Symbolic Mathematics 1 project

A Python library for symbolic mathematics.
sympy/github.com/sympy/sympy /15,046 stars /

Statistics 1 project

Statistical modeling and econometrics in Python.

Biology and Chemistry 2 projects

Cheminformatics and machine learning software.
rdkit/github.com/rdkit/rdkit /3,650 stars /
Biopython is a set of freely available tools for biological computation.
biopython/github.com/biopython/biopython /5,250 stars /

Physics and Engineering 3 projects

Operate and manipulate physical quantities with units and dimensional analysis.
hgrecco/github.com/hgrecco/pint /2,820 stars /
A community Python library for astronomy.
astropy/github.com/astropy/astropy /5,406 stars /
A Python toolbox for seismology.
obspy/github.com/obspy/obspy /1,343 stars /

Simulation and Modeling 3 projects

Probabilistic programming and Bayesian modeling in Python.
pymc-devs/github.com/pymc-devs/pymc /9,827 stars /
A process-based discrete-event simulation framework.
An agent-based modeling framework for building, analyzing, and visualizing complex system simulations.
mesa/github.com/mesa/mesa /3,925 stars /

Graphs and Networks 1 project

High-productivity software for complex networks.
networkx/github.com/networkx/networkx /17,369 stars /

Computational Geometry 1 project

Manipulation and analysis of geometric objects in the Cartesian plane.
shapely/github.com/shapely/shapely /4,533 stars /

Other 2 projects

Implementing a comprehensive number of colour theory transformations and algorithms.
An animation engine for explanatory math videos.

Science guide

NumPy gives you a multidimensional array and fast routines that run on it. Write whole-array expressions instead of Python loops: vectorization and broadcasting push the element-by-element work into compiled C code, and your code reads closer to the math. For random numbers, create a Generator with default_rng() and call its methods.

SciPy is a collection of algorithms built on NumPy, split into subpackages by domain, like optimize, integrate, interpolate, linalg, and stats. Its docs recommend using those subpackages as namespaces: from scipy import optimize, then optimize.curve_fit(). For linear algebra, use scipy.linalg over numpy.linalg. It has everything NumPy's module has and more, and it's always compiled with BLAS/LAPACK, so it may run faster.

Numba is a just-in-time compiler that works best on code that uses NumPy arrays and functions, and loops. NumPy wants vector operations, but Numba is happy with plain loops, so it fits the numeric code you can't vectorize. Put @jit on the function and let Numba decide when and how to optimize. Keep pandas out of those functions: Numba doesn't understand it, so that code runs in the interpreter with Numba's overhead on top.

SymPy does symbolic math: expressions stay exact, not approximate, and it's written entirely in Python. Its best practices keep symbolic and numeric code apart: model the problem in SymPy, then turn the result into a function with lambdify() that runs on NumPy arrays. Define symbols with symbols() and the assumptions you know, like positive=True, so more expressions simplify. Build expressions from those symbols, not from strings.

statsmodels estimates statistical models, runs hypothesis tests, and explores data, and most of its results are verified against another statistical package. SciPy's stats docs send regression, linear models, and time series analysis to statsmodels, while scipy.stats keeps the probability distributions and statistical tests. Write your model as an R-style formula on a pandas DataFrame, like smf.ols("y ~ x", data=df).fit(), and read the fit with summary().

Biopython parses bioinformatics file formats like FASTA and GenBank, queries online services like NCBI, and gives you a standard sequence class. Read sequence files with Bio.SeqIO.parse(), or Bio.SeqIO.read() when a file holds one record. When you query NCBI through Bio.Entrez, pass your email so NCBI can contact you if there's a problem. RDKit is a cheminformatics toolkit with its core in C++, for 2D and 3D molecular operations and descriptors for machine learning. To compare molecules, create a fingerprint generator for the fingerprint type you want, the docs' most consistent way to get fingerprints.

Pint handles physical quantities: a value times a unit, in any numeric type. In a package, create one UnitRegistry in a single place and import it everywhere, since quantities from different registries don't mix. Astropy is a common core package for astronomy, with affiliated packages around it. Import the subpackage you need, like from astropy import units as u, and never import with *. ObsPy is a framework for processing seismological data: read() loads SAC, MiniSEED, and other formats into a Stream of Traces, and its FDSN client fetches data from data centers.

PyMC builds Bayesian models with a simple Python API and fits them with Markov chain Monte Carlo or variational inference. Declare the variables inside a with pm.Model(): block, which adds them to the model for you, and let pm.sample() pick the samplers. Validate the model with posterior predictive checks, and run prior predictive checks too, which its docs call a crucial part of the Bayesian workflow.

SimPy runs discrete-event simulations. Each process is a Python generator that yields events and waits for them, and shared resources model congestion points like servers and checkout counters. Request a resource in a with block so it's released for you. Its docs call it overkill for fixed-step simulations whose processes don't interact or share resources. Mesa builds agent-based models from core components like spatial grids, shows them in the browser, and hands the results to Python's data tools. Its best practices put the model class in model.py and the agents in agents.py, with an optional browser visualization in app.py. Its DataCollector collects model-level and agent-level data.

NetworkX is for the creation, manipulation, and study of complex networks. Pick the graph class first: Graph, DiGraph, MultiGraph, or MultiDiGraph. Store numeric edge data under the weight key, which algorithms like Dijkstra's shortest path read by default. Its drawing functions are basic, since its main goal is graph analysis, not visualization, so export the graph to a dedicated visualization tool.

Shapely wraps the GEOS library for manipulation and analysis of planar geometric objects. For many geometries, put them in a NumPy array and call its vectorized functions instead of a Python loop. It doesn't read or write data files or transform coordinate systems. Operations presume the features sit in the same Cartesian plane, so project your data to a plane before you measure it.

Colour provides algorithms and datasets for colour science. Manim generates animations of technical concepts from Python code. It comes in more than one edition, and the one listed here is the community-maintained one its docs recommend, especially for beginners. Each animation lives in the construct() method of a Scene subclass, with helper functions outside the class.

Keep your data in NumPy arrays as it moves between most of these libraries. ObsPy already holds each trace's samples in one, and Colour recommends them as input. For results you can reproduce, seed your random numbers: pass a seed to default_rng() in NumPy, and give your Mesa model a seed argument.

Know a project that belongs here?

Tell us what it does and why it stands out.