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 to re-sort the whole list.

Press / to search. Tap a tag to filter. Click any 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 / /837,469,024 downloads/month
Fundamental algorithms for scientific computing in Python.
scipy/github.com/scipy/scipy / /306,513,498 downloads/month
A NumPy-aware JIT compiler for Python, using LLVM.
numba/github.com/numba/numba / /54,602,012 downloads/month

Symbolic Mathematics 1 project

A Python library for symbolic mathematics.
sympy/github.com/sympy/sympy / /131,609,443 downloads/month

Statistics 1 project

Statistical modeling and econometrics in Python.
statsmodels/github.com/statsmodels/statsmodels / /33,699,157 downloads/month

Biology and Chemistry 2 projects

Cheminformatics and Machine Learning Software.
rdkit/github.com/rdkit/rdkit / /5,754,330 downloads/month
Biopython is a set of freely available tools for biological computation.
biopython/github.com/biopython/biopython / /4,781,120 downloads/month

Physics and Engineering 3 projects

Operate and manipulate physical quantities with units and dimensional analysis.
hgrecco/github.com/hgrecco/pint / /5,678,084 downloads/month
A community Python library for Astronomy.
astropy/github.com/astropy/astropy / /2,908,275 downloads/month
A Python toolbox for seismology.
obspy/github.com/obspy/obspy / /181,712 downloads/month

Simulation and Modeling 3 projects

Probabilistic programming and Bayesian modeling in Python.
pymc-devs/github.com/pymc-devs/pymc / /1,333,244 downloads/month
A process-based discrete-event simulation framework.
gitlab.com/team-simpy/simpy /495,377 downloads/month
An agent-based modeling framework for building, analyzing, and visualizing complex system simulations.
mesa/github.com/mesa/mesa / /50,554 downloads/month

Graphs and Networks 1 project

A high-productivity software for complex networks.
networkx/github.com/networkx/networkx / /205,958,414 downloads/month

Computational Geometry 1 project

Manipulation and analysis of geometric objects in the Cartesian plane.
shapely/github.com/shapely/shapely / /62,163,436 downloads/month

Other 2 projects

Implementing a comprehensive number of colour theory transformations and algorithms.
colour-science/github.com/colour-science/colour / /306,663 downloads/month
An animation engine for explanatory math videos.
ManimCommunity/github.com/ManimCommunity/manim / /144,852 downloads/month

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.