> ## Content Index
> Fetch the complete content index at: https://mfitzp.ghost.io/llms.txt
> Use this file to discover other available public pages before exploring further.

# BioCyc (API)
- URL: https://mfitzp.ghost.io/biocyc/
- Published: 2014-05-24T00:00:00.000Z
- Updated: 2024-04-02T21:12:28.000Z
- Description: Python interface to the BioCyc Web API
- Author: Martin Fitzpatrick
- Tags: Releases, Python, #Import 2026-08-24 14:26

[BioCyc](https://pypi.python.org/pypi/biocy/0.0.1?ref=mfitzp.ghost.io) is a Python interface to the [BioCyc](http://biocyc.org%20web%20api/). Acting as a wrapper it queries the database and then presents the XML returned in a pythonic object-based interface. Support for IPython views is included offering nice summary tables of object attributes.

## Interface

The BioCyc interface provides access to most attributes, with inter-object links presented as lazy-loading lists. These links are followed and auto-queried on access, allowing navigation through the entire database tree by simply accessing object attributes and slices.

The interface is throttled to one request per second (by request of BioCyc). However, the module comes with a built-in cache (stored by default under `~/.biocyc`) that stores retrieved objects for future use. As such subsequent requests are much quicker. Multiple and configurable caches may be used, and it's possible to share caches across multiple machines.

To install, get on the command line and type:

```
pip install BioCyc

```

or download from [PyPi](https://pypi.python.org/pypi/BioCyc/0.0.1?ref=mfitzp.ghost.io) or [Github](https://github.com/mfitzp/BioCyc?ref=mfitzp.ghost.io).

A demo IPython notebook (available [here](http://nbviewer.ipython.org/github/mfitzp/ipython-notebooks/blob/master/public/BioCyc%20Interface%20Demo.ipynb?ref=mfitzp.ghost.io)) is walked through below.

## Basic initialisation

Import the `biocyc` object from the `biocyc` module. This object provides the base access to the database for the initial get. You can set the organism using `set_organism` and one of the standard BioCyc database identifiers. Note that this only affects the organism-database used for direct requests on the biocyc object. Sub-requests on existing objects will use the same database as that object (otherwise things would be very confusing indeed).

```Python
import os
from biocyc import biocyc
os.environ['http_proxy'] = '' # Set your proxy if neccessary
biocyc.set_organism('meta')

```

## Making a request

To get an database object (of any type) simply using the unique BioCyc identifiers for it. Here we request `L-Lactate`. Note that if you do this from within an IP\[y\] Notebook you get a nice table output of all associated attributes for an object. This includes direct links to the BioCyc database and other database annotations.

```Python
o=biocyc.get('L-LACTATE')
o

```

| Name             | (*S*)-lactate                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| BioCyc ID        | [L-LACTATE](http://www.biocyc.org/META/NEW-IMAGE?object=L-LACTATE&ref=mfitzp.ghost.io)                                                                                                                                                                                                                                                                                                                                                                                            |
| Org ID           | META                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| Synonyms         | L-lactate, L(+)-lactate                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| INCHI            | InChI=1S/C3H6O3/c1-2(4)3(5)6/h2,4H,1H3,(H,5,6)/p-1/t2-/m0/s1                                                                                                                                                                                                                                                                                                                                                                                                                      |
| Molecular weight | 89.071                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| Gibbs 0          | \-72.55646                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| Parents          | L-2-hydroxyacids, Lactate                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| Reactions        | TRANS-RXN-104, RXN-12165, RXN-12096, LACTALDDEHYDROG-RXN, RXN0-5269, D-LACTATE-2-SULFATASE-RXN, TRANS-RXN-104, L-LACTDEHYDROGFMN-RXN, LACTATE-MALATE-TRANSHYDROGENASE-RXN, LACTATE-2-MONOOXYGENASE-RXN, L-LACTATE-DEHYDROGENASE-CYTOCHROME-RXN, L-LACTATE-DEHYDROGENASE-RXN, RXN-9067, RXN-8076, PROPIONLACT-RXN, LACTATE-RACEMASE-RXN, LACTATE-ALDOLASE-RXN                                                                                                                      |
| Database links   | CAS: [79-33-4](http://www.commonchemistry.org/ChemicalDetail.aspx?ref=79-33-4), PUBCHEM: [5460161](http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=5460161&ref=mfitzp.ghost.io), LIGAND-CPD: [C00186](http://www.genome.ad.jp/dbget-bin/www%5Fbget?C00186&ref=mfitzp.ghost.io), CHEMSPIDER: [4573803](http://www.chemspider.com/4573803?ref=mfitzp.ghost.io), CHEBI: [16651](http://www.ebi.ac.uk/chebi/searchId.do?chebiId=CHEBI:16651&ref=mfitzp.ghost.io), BIGG: 34179 |

## Exploring further

Now we have an object we can perform sub-queries by accessing fields. If you access the `o.reactions`field you will trigger a dynamic request for all entities in that list. Connections to the BioCyc server are throttled at 1/second, so this may take a little while on long lists. However, retrieved data is cached under `~/.biocyc`so subsequent requests will be much quicker. By default the cache is set to expire objects after \~6 months, and the cache folder can be shared between multiple machines.

*Note: If you just want access to the identifiers, you can use the `` `o._reactions ``field to access these without triggering a request*

```Python
r = o.reactions
r[0]

```

| BioCyc ID | [TRANS-RXN-104](http://www.biocyc.org/META/NEW-IMAGE?object=TRANS-RXN-104&ref=mfitzp.ghost.io) |
| --------- | ---------------------------------------------------------------------------------------------- |
| Org ID    | META                                                                                           |
| Parents   | Small-Molecule-Reactions, TR-12                                                                |

```Python
r[1]

```

| Name      | NADP+ L-lactaldehyde dehydrogenase                                                     |
| --------- | -------------------------------------------------------------------------------------- |
| BioCyc ID | [RXN-12165](http://www.biocyc.org/META/NEW-IMAGE?object=RXN-12165&ref=mfitzp.ghost.io) |
| Org ID    | META                                                                                   |
| Parents   | Chemical-Reactions, Small-Molecule-Reactions                                           |
| Pathways  | PWY-6713                                                                               |

You can access sub-entities and manipulate objects using standard Python list processing.

```Python
ps = [r.pathways for r in o.reactions]
p = [p for sl in ps for p in sl]
p

[L-rhamnose degradation II,
L-rhamnose degradation III,
L-rhamnose degradation II,
methylglyoxal degradation V,
lactate biosynthesis (archaea),
L-lactaldehyde degradation (aerobic),
L-lactaldehyde degradation (aerobic),
methylglyoxal degradation V,
pyruvate fermentation to lactate,
glucose and xylose degradation,
Bifidobacterium shunt,
heterolactic fermentation,
factor 420 biosynthesis]

```

```Python
p[0]

```

| Name            | L-rhamnose degradation II                                                            |
| --------------- | ------------------------------------------------------------------------------------ |
| BioCyc ID       | [PWY-6713](http://www.biocyc.org/META/NEW-IMAGE?object=PWY-6713&ref=mfitzp.ghost.io) |
| Org ID          | META                                                                                 |
| Synonyms        | aldolase pathway                                                                     |
| Parents         | L-rhamnose-Degradation                                                               |
| Species         | TAX-5580, ORG-6176, TAX-95486, TAX-284592, TAX-322104                                |
| Taxonomic range | TAX-2, TAX-4751                                                                      |

## Finally

That's all for now! Hopefully this shows how Python (and IPython notebook) access to the BioCyc Web API may be useful. Support for additional attributes, API calls etc. is planned for the future.