Written and maintained by CASRAI Editorial Board
Published
On this page
COBRApy is an open-source Python package for constraint-based modeling of metabolic networks: researchers use it to load, build, edit and simulate genome-scale metabolic models, for example with flux balance analysis. The name expands to COnstraints-Based Reconstruction and Analysis for Python, and it is software, not a snake.
What COBRApy is and is not
COBRApy was introduced in 2013 by Ebrahim, Lerman, Palsson and Hyduke in BMC Systems Biology (volume 7, article 74, doi 10.1186/1752-0509-7-74). The paper presents it as a Python counterpart to the COBRA Toolbox for MATLAB. Its abstract says the MATLAB toolbox was not designed to capture the complexity inherent in integrated biological networks, and that COBRApy takes an object-oriented approach to represent that complexity. It does not need MATLAB, although it includes an interface to the COBRA Toolbox so that legacy MATLAB code can still be used, and it supports parallel processing.
The package belongs to the openCOBRA Project, which the paper describes as a community effort for freely available constraint-based modeling software. The project lives under the opencobra organization on GitHub. The PyPI description of the cobra package is a single sentence: a package for constraint-based modeling of metabolic networks.
COBRApy is a modeling library, not a wet-lab tool and not a model database. It runs the optimization problems defined by a metabolic model; the biology, the curation of the reconstruction and the choice of constraints remain the researcher’s responsibility. For the underlying method, see the CASRAI explanation of computational reproducibility, which applies directly to how a simulation should be reported.
Core objects and the basic workflow
The getting-started documentation (checked 2026-11-20) shows the typical sequence. A model is loaded with cobra.io.load_model, which can fetch bundled examples named “textbook”, “iJO1366” and “salmonella”. The “textbook” model represents E. coli core metabolism and has 95 reactions, 72 metabolites and 137 genes. A model holds three kinds of objects, each stored in a cobra.DictList and retrievable by identifier with get_by_id().
| Object | What the documentation says it carries |
|---|---|
| Reaction | Bounds (reaction.bounds), a gene-reaction rule, and a mass-balance check (check_mass_balance()); new reactions can be built from a string of metabolite identifiers and a reversibility arrow |
| Metabolite | A name, a chemical formula, a charge and a compartment |
| Gene | Linked to reactions through the gene-reaction rule, which is how gene deletions are mapped to reaction effects |
Two habits from the documentation matter for correctness. First, changes can be made inside a with model as model: block, which reverts them when the block ends, so a knockout or a changed bound does not silently persist into the next analysis. Second, an analysis is run with model.optimize(), and the result is read from model.objective.value. Because the objective and the bounds together define the answer, both should be reported whenever a flux value is quoted.
Features by research task
The documentation for version 0.32.1 lists what the package covers. The data table below organizes that list by the task a researcher is trying to perform; it is compiled from the documentation’s own feature list and the 2013 paper.
In practice this means a small project can stay inside one library from model import to export. A group that receives a model as an SBML file can read it, test its consistency with flux variability analysis, compare growth under different media, run single and double gene deletions, and write the edited model back to SBML or JSON. A group that mainly wants a flux prediction needs only the load, constrain and optimize steps. The documentation also offers many worked examples as notebooks, which are the quickest way to see a method used end to end.
Methods named across the documentation and the repository README include flux balance analysis (FBA), flux variability analysis (FVA), parsimonious FBA (pFBA), geometric FBA, MOMA, loopless FBA, flux sampling, gapfilling and dynamic FBA (dFBA). CASRAI does not yet describe each method in a separate page; consult the cited documentation and the method’s original publication for the mathematics before relying on a result.
Solvers
COBRApy does not solve the linear programs itself. According to the solver documentation (checked 2026-11-20), it supports GLPK, Gurobi and CPLEX through optlang, a separate package at github.com/biosustain/optlang. A solver is selected by assigning to model.solver, for example model.solver = 'glpk', and the object stored there is an optlang model. The documentation also notes that COBRApy’s own older solver interfaces are deprecated and will be removed, so code written against optlang is the safer pattern for new work.
Solver choice is a reproducibility detail, not a cosmetic one: Gurobi and CPLEX are commercial products with their own licenses, whereas GLPK is the freely available option named in the documentation. Different solvers can return different but equally optimal flux distributions when an optimum is not unique, which is one reason flux variability analysis and sampling exist in the same package.
Install, license and citation
The repository README (checked 2026-11-20) gives the installation command as pip install cobra and recommends doing it inside a virtual environment. Loading MATLAB model files needs the extra pip install cobra[array]. PyPI lists version 0.32.1, released on 11 August 2026, with Python classifiers from 3.8 to 3.11; check the current PyPI page for the interpreter version you run before assuming support.
The package is released under both the GPL and the LGPL, version 2 or later, and PyPI shows the license expression as “LGPL-2.0-or-later OR GPL-2.0-or-later”. Researchers who redistribute software built on COBRApy should read the license text and, where an institution is involved, the guidance on a software license agreement; this page is not legal advice.
The README asks users to cite the 2013 paper, doi:10.1186/1752-0509-7-74. A DOI of this kind points to the paper, while the software version you ran is a separate fact that you must state yourself.
Reproducibility checklist for a COBRApy analysis
The following checklist is assembled from the sources above. Each item corresponds to something the documentation or paper says can change the result or how it is interpreted.
- Package version. Record the exact
cobraversion, for example 0.32.1, which was the latest on PyPI on 2026-11-20. Treat it as part of the method, as with any versioned model or tool. - Model source and size. Name the model and where it came from. For a bundled example, state the name passed to
load_model; for the “textbook” model, the documented counts are 95 reactions, 72 metabolites and 137 genes, so a different count signals a different file. - Constraints and objective. Report changed bounds, medium composition, knockouts and the objective function, since
model.optimize()returns the optimum of exactly that problem. - Solver. State which optlang-supported solver (GLPK, Gurobi or CPLEX) was used and whether it was set explicitly through
model.solver. - File formats. Say whether the model was read from SBML, JSON, YAML, MATLAB or Pickle, because the documentation lists all of these and they do not carry identical information.
- Mass balance. Run
check_mass_balance()on reactions you add or edit and report the outcome. - Environment. Keep a pinned requirements file in a virtual environment, as the README recommends, and deposit it with the code; the open-source software entry explains why licensing and archiving belong with the deposit.
- Citation. Cite the 2013 paper and, separately, the version of the software.
Is COBRApy about snakes?
No. “COBRA” in COBRApy is an acronym for COnstraints-Based Reconstruction and Analysis, and “py” signals the Python programming language. The query “cobrapy” is often read as two animal names, which is why the questions people ask alongside it include snake comparisons, but the package has nothing to do with animals. Neither word in the package name refers to a reptile, and this page does not cover animal biology.
Common misunderstandings
- “COBRApy predicts what an organism does.” It computes optima and ranges under the constraints you supply; the output is only as good as the reconstruction and the constraints.
- “It needs MATLAB.” The 2013 paper states that it does not; the MATLAB interface exists for legacy code.
- “The solver is built in.” Solving is delegated to GLPK, Gurobi or CPLEX through optlang.
- “cobra and COBRApy are different packages.” The PyPI package named
cobrais described as COBRApy; the project is the same one.
Frequently asked questions
Who would win, a cobra or a python?
This question is about snakes and is outside the scope of this page. In the software, “cobra” and “python” are not animals: COBRA is a modeling approach and Python is the programming language the package is written in.
What are the key differences between a python and a cobra?
In the context of COBRApy, Python is a general-purpose programming language, whereas COBRA (constraint-based reconstruction and analysis) is a set of methods for metabolic network modeling. COBRApy implements those methods in Python, as described in the 2013 paper.
Is a python a cobra?
No. Python is the language and COBRA is the method family; COBRApy is the package that joins them. See the sections above on what the package is and does.
What is COBRApy used for?
It is used to load, build and edit metabolic network models and to analyze them with constraint-based methods such as FBA, FVA, pFBA, flux sampling, deletion analysis and gapfilling, according to the version 0.32.1 documentation.
How do I install COBRApy?
The repository README gives pip install cobra, ideally in a virtual environment, and pip install cobra[array] for loading MATLAB models.
Which license does COBRApy use?
The README states that it is released under both the GPL and the LGPL, version 2 or later; PyPI shows “LGPL-2.0-or-later OR GPL-2.0-or-later”.
How should I cite COBRApy?
The README gives the 2013 paper: Ebrahim A, Lerman JA, Palsson BO, Hyduke DR, BMC Systems Biology 7:74, doi 10.1186/1752-0509-7-74. Also report the software version you used.
Sources
- COBRApy documentation: home and feature list (version 0.32.1), checked 2026-11-20
- COBRApy documentation: Getting started, checked 2026-11-20
- COBRApy documentation: Solvers, checked 2026-11-20
- Python Package Index: cobra, checked 2026-11-20
- GitHub: opencobra/cobrapy README, checked 2026-11-20
- PubMed: COBRApy: COnstraints-Based Reconstruction and Analysis for Python (BMC Systems Biology 2013;7:74), checked 2026-11-20
Data: COBRApy capabilities by research task (documentation version 0.32.1)
Compiled from the COBRApy 0.32.1 documentation feature list, getting-started and solvers pages, and the 2013 BMC Systems Biology paper abstract, grouping documented capabilities by the task a researcher performs. Read 2026-11-20.
Period covered: 2013/2026.
| Research task | Documented capability | Source |
|---|---|---|
| Reading and writing models | SBML, JSON, YAML, MATLAB, Pickle | Documentation feature list |
| Building and editing models | Load, build and edit models; custom constraints, variables and objectives | Documentation feature list |
| Flux prediction | FBA, pFBA, geometric FBA, loopless FBA, production envelopes, dynamic FBA (dFBA) | Documentation feature list |
| Flux ranges and sampling | Flux variability analysis (FVA), flux sampling | Documentation feature list |
| Gene and reaction knockouts | Single and double gene deletion, single and double reaction deletion | Documentation feature list |
| Model quality and curation | Consistency testing (FVA, FASTCC), gapfilling, mass-balance check on reactions, growth media | Documentation feature list; Getting started |
| Solving | GLPK, Gurobi, CPLEX through optlang, selected with model.solver | Solvers page |
| Relation to MATLAB | No MATLAB required; interface to the COBRA Toolbox for legacy code; parallel processing support | 2013 paper abstract |
Sources
- COBRApy documentation (version 0.32.1) (accessed 2026-11-20)
- COBRApy documentation: Getting started (accessed 2026-11-20)
- COBRApy documentation: Solvers (accessed 2026-11-20)
- COBRApy: COnstraints-Based Reconstruction and Analysis for Python (PubMed 23927696) (accessed 2026-11-20)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







