{"id":23436,"library":"cobra","title":"COBRApy","description":"COBRApy (0.31.1) is a Python package for constraint-based modeling of metabolic networks. It enables building, simulating, and analyzing genome-scale metabolic models using flux balance analysis (FBA) and related methods. Releases occur several times a year, with a focus on stability and new features.","status":"active","version":"0.31.1","language":"python","source_language":"en","source_url":"https://github.com/opencobra/cobrapy","tags":["metabolic modeling","constraint-based modeling","fba","systems biology"],"install":[{"cmd":"pip install cobra","lang":"bash","label":"Install from PyPI"},{"cmd":"pip install cobra[optlang]","lang":"bash","label":"Install with default solver (optlang)"}],"dependencies":[{"reason":"Default LP solver interface (GLPK, CPLEX, Gurobi). Optional but recommended.","package":"optlang","optional":true},{"reason":"Required for DataFrame-based results and model I/O.","package":"pandas","optional":false},{"reason":"Required for SBML file support.","package":"libsbml","optional":true}],"imports":[{"note":"cobra.core provides internals; public API is from cobra.","wrong":"from cobra.core import Model","symbol":"Model","correct":"from cobra import Model"},{"note":"Public API from cobra top-level.","wrong":"from cobra.core import Reaction","symbol":"Reaction","correct":"from cobra import Reaction"},{"note":"Top-level import is correct.","wrong":"from cobra.core import Metabolite","symbol":"Metabolite","correct":"from cobra import Metabolite"},{"note":"Use flux_analysis.pfba, flux_analysis.single_gene_deletion, etc.","wrong":"from cobra.flux_analysis import pfba","symbol":"flux_analysis","correct":"from cobra import flux_analysis"}],"quickstart":{"code":"from cobra import Model, Reaction, Metabolite\nmodel = Model('example')\n# Add reaction: A -> B\nreaction = Reaction('R1')\nreaction.name = 'A to B'\nreaction.subsystem = 'Exchange'\nreaction.lower_bound = 0.  # irreversible\nreaction.upper_bound = 1000.\nmetabolite_a = Metabolite('A_c', compartment='c')\nmetabolite_b = Metabolite('B_c', compartment='c')\nreaction.add_metabolites({metabolite_a: -1, metabolite_b: 1})\nmodel.add_reactions([reaction])\nmodel.objective = 'R1'  # maximize flux through R1\nsolution = model.optimize()\nprint(solution.objective_value)","lang":"python","description":"Create a simple model, add a reaction, set objective, and solve using FBA."},"warnings":[{"fix":"Install cobra[optlang] and use optlang.glpk_interface (or other solver interfaces).","message":"In cobra 0.31, the default solver interface changed to optlang. If you rely on the older glpk interface directly, your code may break.","severity":"breaking","affected_versions":">=0.31"},{"fix":"Use model.objective = {reaction: 1} or reaction.objective_coefficient = 1 for a single reaction.","message":"Setting model.objective = reaction_object does not automatically change the objective coefficient; you must set coefficient explicitly via model.objective = {reaction: 1} or reaction.objective_coefficient = 1.","severity":"gotcha","affected_versions":"all"},{"fix":"Replace cobra.io.sbml.write_sbml with cobra.io.write_sbml_model.","message":"The method 'cobra.io.sbml.write_sbml' is deprecated; use 'cobra.io.write_sbml_model' instead.","severity":"deprecated","affected_versions":">=0.30"},{"fix":"Use solution.fluxes['REACTION_ID'] instead of solution['REACTION_ID'].","message":"Flux balance analysis results are stored in cobra.Solution which is not subscriptable; use solution.fluxes (pandas Series) to access individual fluxes.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'0.31.1':3 'analysi':30 'analyz':21 'balanc':29 'base':11,53 'biolog':57 'build':18 'cobrapi':1,2 'constraint':10,52 'constraint-bas':9,51 'enabl':17 'fba':31,55 'featur':48 'flux':28 'focus':43 'genom':23 'genome-scal':22 'metabol':14,25,49 'method':34 'model':12,26,50,54 'network':15 'new':47 'occur':36 'packag':7 'python':6 'relat':33 'releas':35 'scale':24 'sever':37 'simul':19 'stabil':45 'system':56 'time':38 'use':27 'year':40","created_at":"2026-05-01T08:07:46.052562+00:00","updated_at":"2026-05-01T08:07:46.052562+00:00","problems":[{"fix":"Run 'pip install cobra' in your terminal.","cause":"cobra is not installed or virtual environment not activated.","error":"ModuleNotFoundError: No module named 'cobra'"},{"fix":"Use model.objective = 'R1' for a single reaction or model.objective = {'R1': 1, 'R2': 0.5} for multiple.","cause":"Setting model.objective = ['R1', 'R2'] incorrectly (list instead of dict or single reaction).","error":"ValueError: objective must be a scalar (reaction) or dict of reactions to coefficients"},{"fix":"Install optlang: 'pip install cobra[optlang]' or install a solver like GLPK.","cause":"optlang not installed and no solver (e.g., GLPK, CPLEX) available.","error":"No solver interface found"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.31.1","cli_name":"","cli_version":null,"type":"library","homepage":"https://opencobra.github.io/cobrapy","github":"https://github.com/opencobra/cobrapy","docs":"https://cobrapy.readthedocs.io","changelog":null,"pypi":"https://pypi.org/project/cobra/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-29","last_verified":"2026-06-29","next_check":"2026-07-29","install_tag":null}}