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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.056s · 33.3MB
glibcpy 3.10–3.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)
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.
fixFor 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`.
fixThe `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.
fixUpgrade 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.