# Cobrapy

Constraint-based metabolic modeling (COBRA).

- Repository: https://github.com/synthetic-sciences/openscience (4321 stars)
- Category: Engineering
- License: GPL-2.0 license
- Last updated: 2026-10-30
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add synthetic-sciences/openscience --skill cobrapy -g -a claude-code -y`
Codex: `npx skills add synthetic-sciences/openscience --skill cobrapy -g -a codex -y`
Cursor: `npx skills add synthetic-sciences/openscience --skill cobrapy -g -a cursor -y`
Gemini CLI: `npx skills add synthetic-sciences/openscience --skill cobrapy -g -a gemini-cli -y`

## Description

Constraint-based metabolic modeling (COBRA). FBA, FVA, gene knockouts, flux sampling, SBML models, for systems biology and metabolic engineering analysis.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# COBRApy - Constraint-Based Reconstruction and Analysis

## Overview

COBRApy is a Python library for constraint-based reconstruction and analysis (COBRA) of metabolic models, essential for systems biology research. Work with genome-scale metabolic models, perform computational simulations of cellular metabolism, conduct metabolic engineering analyses, and predict phenotypic behaviors.

## Core Capabilities

COBRApy provides comprehensive tools organized into several key areas:

### 1. Model Management

Load existing models from repositories or files:
```python
from cobra.io import load_model

# Load bundled test models
model = load_model("textbook")  # E. coli core model
model = load_model("ecoli")     # Full E. coli model
model = load_model("salmonella")

# Load from files
from cobra.io import read_sbml_model, load_json_model, load_yaml_model
model = read_sbml_model("path/to/model.xml")
model = load_json_model("path/to/model.json")
model = load_yaml_model("path/to/model.yml")
```

Save models in various formats:
```python
from cobra.io import write_sbml_model, save_json_model, save_yaml_model
write_sbml_model(model, "output.xml")  # Preferred format
save_json_model(model, "output.json")  # For Escher compatibility
save_yaml_model(model, "output.yml")   # Human-readable
```

### 2. Model Structure and Components

Access and inspect model components:
```python
# Access components
model.reactions      # DictList of all reactions
model.metabolites    # DictList of all metabolites
model.genes          # DictList of all genes

# Get specific items by ID or index
reaction = model.reactions.get_by_id("PFK")
metabolite = model.metabolites[0]

# Inspect properties
print(reaction.reaction)        # Stoichiometric equation
print(reaction.bounds)          # Flux constraints
print(reaction.gene_reaction_rule)  # GPR logic
print(metabolite.formula)       # Chemical formula
print(metabolite.compartment)   # Cellular location
```

### 3. Flux Balance Analysis (FBA)

The rest: https://github.com/synthetic-sciences/openscience/blob/HEAD/backend/cli/skills/biology/cobrapy/SKILL.md
