cobra
COBRApy is a package for constraint-based modeling of metabolic networks.
What it is and what it does
COBRApy is a Python framework for building and analyzing constraint-based models of metabolic networks at genome scale. It provides infrastructure for creating metabolic models, managing reactions and metabolites, and accessing mathematical solvers (CPLEX, Gurobi, GLPK) through the optlang interface. The package implements standard COBRA methods including flux balance analysis (FBA), flux variability analysis (FVA), and gene deletion simulations to predict metabolic behavior and gene essentiality.
The package is designed as both a standalone tool and a foundation for building specialized COBRA-related Python packages. It depends on numpy for numerical computation, pandas for data manipulation, pydantic for model validation, and python-libsbml for reading SBML model files. Solvers are accessed through optlang, with GLPK automatically available via swiglpk. The package targets researchers in systems biology, metabolic engineering, and computational biology who need to model and analyze organism metabolism at scale.
Use it for:
- Predict metabolic flux distributions and growth rates under different nutrient conditions using flux balance analysis.
- Identify essential genes by simulating single and multiple gene knockouts to assess impact on growth.
- Perform flux variability analysis to determine the range of possible reaction rates consistent with optimal growth.
- Load, modify, and validate genome-scale metabolic models in SBML format for strain design workflows.
- Build custom analysis pipelines by extending COBRApy classes for domain-specific metabolic research.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
COBRApy is a constraint-based modeling package for genome-scale metabolic network analysis, providing flux balance analysis, flux variability analysis, gene deletion analysis, and access to mathematical solvers.
Yes. COBRApy is production-stable (active maintenance, release 3 days old, 579 GitHub stars) with low install friction and no known vulnerabilities. The dual GPL/LGPL copyleft license requires source disclosure but is standard for academic bioinformatics. Install if you need genome-scale metabolic modeling; the twelve runtime dependencies are justified by the package's scope and are well-maintained.
Install
cobra on PyPI
pip
pip install cobrauv
uv add cobrapoetry
poetry add cobraInstalling cobra
Before you install
Low install friction with a pure-wheel distribution. Active maintenance with a release 3 days old and recent commits. Twelve runtime dependencies including numpy, pandas, optlang, and swiglpk introduce some complexity, but the package is production-stable.
License in practice
Dual-licensed under LGPL-2.0-or-later or GPL-2.0-or-later (copyleft). You may choose which license to use, but either choice requires source disclosure and derivative work licensing under the same terms.
Quickstart
pip install cobra
import cobra
model = cobra.io.read_sbml_model('model.xml')
solution = model.optimize()
Requires a compatible mathematical solver (CPLEX, Gurobi, or GLPK via swiglpk) to be installed or configured for optimization to work.
Verify before relying
- Whether all 12 runtime dependencies are required for basic usage or only for specific features (e.g., array support for MATLAB models).
- Performance characteristics and scalability limits for large genome-scale models.
- Compatibility with specific solver versions beyond the general optlang interface.
Package facts
| License | LGPL-2.0-or-later OR GPL-2.0-or-later (copyleft) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 12 — appdirs, depinfo, future, httpx, numpy, optlang, pandas, pydantic, python-libsbml, rich, ruamel.yaml, swiglpk |
| Maintenance | actively maintained — 3 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 91,149/month — #13,535 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: cobra-0.32.1-py2.py3-none-any.whl
Keywords: metabolism, biology, constraint-based, linear programming, mixed-integer, optimization, flux-balance analysis, reconstruction
Tags
More Bio-Informatics packages
NetworkX provides data structures and…
permissive · top 1,000 on PyPI
biopythonBiopython provides Python tools for…
unclear · top 5,000 on PyPI
firecrawl-pyClient library for the Firecrawl API that…
permissive · top 5,000 on PyPI
intervaltreeA self-balancing interval tree data structure…
permissive · top 5,000 on PyPI
albumentationsAlbumentations applies image transformations to…
permissive · top 5,000 on PyPI
PubChemPyPubChemPy is a Python wrapper around the…
permissive · top 5,000 on PyPI
cvxpyCVXPY is a Python modeling language for…
permissive · top 5,000 on PyPI
swiglpkswiglpk provides direct Python bindings to the…
copyleft · top 15,000 on PyPI
pyomoPyomo is a Python framework for formulating and…
permissive · top 5,000 on PyPI
scanpyScanpy is a toolkit for preprocessing,…
permissive · top 5,000 on PyPI
optlangOptlang formulates and solves linear,…
permissive · top 15,000 on PyPI
linopylinopy builds linear, integer, and quadratic…
permissive · top 15,000 on PyPI
cvxoptcvxopt is a Python library for solving convex…
unclear · top 5,000 on PyPI
gseapyPerforms gene set enrichment analysis (GSEA) on…
permissive · top 15,000 on PyPI
PuLPPuLP is a linear and mixed-integer programming…
permissive · top 5,000 on PyPI
docplexModeling library for building and solving…
permissive · top 15,000 on PyPI