Logo
Libraries and SDKs,  Molecular Biology

CobraPy

Date Published

COBRApy (Constraint-Based Reconstruction and Analysis in Python) is a community-maintained, open-source package that brings established COBRA methods to Python. It provides simple, object-oriented abstractions for Models, Reactions and Metabolites and implements the standard toolbox of constraint-based techniques — flux balance analysis (FBA), flux variability analysis (FVA), parsimonious FBA (pFBA), deletion analyses (single and combinatorial gene/reaction knockouts), MOMA/ROOM and various sampling and optimization workflows. The project is designed both as a user-facing analytical package and as a stable infrastructure for developers building higher-level tools (visualizers, strain-design frameworks, community models) on a shared data model and API. At its core COBRApy focuses on building, reading and writing metabolic models and solving the associated linear (and some quadratic) optimization problems. Models can be constructed programmatically or loaded from common exchange formats (SBML, MATLAB .mat, JSON), inspected and edited (exchange, sink and demand reactions, reversibility flags, bounds, GPR rules). COBRApy delegates optimization to optlang, a solver-agnostic interface that lets you switch between backends such as GLPK, CPLEX, Gurobi, OSQP, COIN-OR CBC or HiGHS without changing higher‑level code. Because solver binaries are external, COBRApy itself is a pure-Python package and installation is straightforward via pip or conda-forge; documentation, examples and numerous IPython notebooks are available on ReadTheDocs and the project’s GitHub repository. Features emphasize both routine and advanced workflows. Out of the box COBRApy supports FBA, FVA (including loopless variants and parallel execution), growth-medium management, context-specific deletion screens and computation of gene essentiality. It provides utilities for tailored constraints, custom variables and objectives, and has explicit support for dynamic flux balance analysis (dFBA) with routines to set up and run time-course simulations. The package also includes sampling tools to explore feasible flux spaces, helpers for minimal media computations, and functions for exporting LP problems and solver states to aid debugging. Many heavy computations can be parallelized using Python multiprocessing or IPython parallelism, allowing scaling to larger model sets or parameter sweeps. COBRApy sits at the center of a rich ecosystem of complementary tools. Visualization and map-building tools such as Escher can display model fluxes and contextualize results; model quality and reproducibility are supported by memote; strain design and metabolic engineering workflows often layer on top of COBRApy via packages like Cameo and StrainDesign; MICOM and other community-focused packages enable multi-species community model construction and trade-off analyses. Integration examples and pipelines — from model reconstruction bridging ModelSEED with COBRApy (Mackinac) to thermodynamics-based and enzyme-constrained extensions — illustrate how COBRApy serves as the stable computational backbone for many published workflows. The project is actively developed by an open community, released under GPL/LGPL licenses, and supported by documentation, example notebooks and community channels (GitHub issues, Google Group, Gitter) for troubleshooting and contribution.