fastobo

raw JSON →
0.14.1 verified Fri May 01 auth: no python

Faultless AST for Open Biomedical Ontologies (OBO) in Python. Version 0.14.1 provides robust parsing, manipulation, and serialization of OBO files, with optional OWL export. Released regularly, with pre-built wheels for many platforms.

pip install fastobo
error AttributeError: module 'fastobo' has no attribute 'load'
cause Trying to use fastobo.load without importing it explicitly, or using an older version where load was not top-level.
fix
Use from fastobo import load
error TypeError: load() argument 1 must be str, not _io.TextIOWrapper
cause Passing a file handle instead of a file path string.
fix
Call load with a file path string: doc = load('file.obo'); do not use open().
error ModuleNotFoundError: No module named 'fastobo'
cause fastobo is not installed.
fix
pip install fastobo
error AttributeError: 'OboDoc' object has no attribute 'frames'
cause OboDoc is iterable but does not have a 'frames' attribute; frames are accessed via iteration.
fix
Use for frame in doc: ...
gotcha Some frame attributes (e.g., 'name') may be None if not defined in the OBO file. Always check for None before use.
fix frame.name or ''
deprecated Support for Python 3.6 removed in v0.12.0; requires Python >=3.7.
fix Upgrade Python to >=3.7
gotcha The OWL export functionality (dump_owl) is only available if the fastobo-owl dependency is installed (not included by default).
fix pip install fastobo[owl] or pip install fastobo-owl
gotcha When loading from a file, the file must be a Path-like object or a string; streams are not supported directly. Use load(open(...)) may fail because load expects a filename or path string, not a file handle.
fix doc = load('/path/to/file.obo') # Do not pass file handle
breaking In v0.12.0, the GIL is no longer released when loading from a file on Windows; this may affect performance but fixes compilation.
fix No action needed unless relying on concurrency; upgrade to latest

Load and iterate over an OBO ontology file.

from fastobo import load

# Load an OBO file (use a test file or URL)
doc = load('go.obo')

# Iterate over all frames
for frame in doc:
    # Frames have an 'id' and 'name' attribute
    print(frame.id, frame.name)

# Convert to OWL (requires fastobo-owl, install separately)
# from fastobo import dump_owl
# dump_owl(doc, 'go.owl')