Registry / serialization / bioc
library2.1pypypi✓ verified 85d ago

bioc is a Python library designed for processing and manipulating data in BioC XML/JSON, Brat standoff, and PubTator formats. It provides an API that facilitates reading, writing, and working with these common bioinformatics text mining annotation formats. Currently at version 2.1, the library undergoes releases with a focus on supporting the latest Python versions and format specifications.

pip install bioc
INSTALL
IMPORT
SIG · BIOC
B
bioc
serializationpythonv2.1
Install
3.4s avg
Import
54ms
Disk
31MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.056s · 33.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.4s · import 0.051s · 34MB
31MB installed
● package 31MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

biocxml
from bioc import biocxml
import bioc
In versions 2.x and later, BioC XML functionalities are moved under the `biocxml` submodule. Direct `import bioc` no longer exposes XML dump/load functions.
brat
from bioc import brat
pubtator
from bioc import pubtator
BioCCollection
from bioc.bioc import BioCCollection
from bioc import BioCCollection
Core BioC data structures like `BioCCollection`, `BioCDocument`, etc., are typically accessed via `bioc.bioc` submodule.

This quickstart demonstrates how to create a basic BioC collection programmatically, add a document with a passage and an annotation, and then serialize it to a BioC XML string using `biocxml.dumps`. It also shows how to deserialize an XML string back into a BioC collection using `biocxml.loads`.

from bioc import biocxml, bioc # Create a simple BioC Collection collection = bioc.BioCCollection() collection.date = '2023-01-01' collection.source = 'Example' document = bioc.BioCDocument() document.id = '123' passage = bioc.BioCPassage() passage.offset = 0 passage.text = 'This is a test sentence.' annotation = bioc.BioCAnnotation() annotation.id = 'T1' annotation.text = 'test sentence' annotation.add_location(bioc.BioCLocation(offset=10, length=13)) passage.add_annotation(annotation) document.add_passage(passage) collection.add_document(document) # Serialize to a BioC XML string xml_string = biocxml.dumps(collection, pretty_print=True) print('--- BioC XML ---') print(xml_string) # Deserialize from a BioC XML string loaded_collection = biocxml.loads(xml_string) print('\n--- Loaded Collection ID ---') for doc in loaded_collection.documents: print(doc.id)
Debug
Known issues
breakingDirect top-level import of BioC XML functions (e.g., `bioc.dump`, `bioc.load`, `bioc.dumps`, `bioc.loads`) was removed in version 2.0. These functions are now part of the `biocxml` submodule.
fix
Update imports from `import bioc` to `from bioc import biocxml` for XML operations, and then use `biocxml.dump()` or `biocxml.load()`.
affects: >=2.0
breakingPython 2.x is no longer supported. Version 1.2.1 removed support for Python 2, and subsequent versions are Python 3.6+ only.
fix
Ensure your project runs on Python 3.6 or newer. Upgrade your Python environment if necessary.
affects: >=1.2.1
gotchaThe PyPI project metadata still lists the 'Development Status' as '1 - Planning' (as of v2.1). This is misleading as the library has undergone multiple releases and is actively maintained for production use.
fix
Disregard the 'Development Status' classifier on PyPI; the library is stable and actively developed.
affects: All versions
Errors
Common errors & fixes
AttributeError: module 'bioc' has no attribute 'dump'
Attempting to use `bioc.dump` or `bioc.load` directly in `bioc` versions 2.x or later.
fix
For XML operations, use `from bioc import biocxml` and then call `biocxml.dump()` or `biocxml.load()`.
ModuleNotFoundError: No module named 'biocxml'
Trying to import `biocxml` directly as a top-level package or without `from bioc`.
fix
The `biocxml` module is part of the `bioc` package. Use `from bioc import biocxml`.
SyntaxError: invalid syntax (when running on Python 2.x)
Running `bioc` code (especially versions 1.2.1+) with a Python 2 interpreter.
fix
Upgrade your Python environment to Python 3.6 or higher. `bioc` no longer supports Python 2.
Upgrade
Version history
2.1latest on PyPI · released Aug 15, 2023
Audit
Dependencies
pythonrequiredRequires Python 3.6 or higher for compatibility and features.
Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources
bioc — pip install bioc · libregistry