PrefixCommons Python API

0.1.12 · active · verified Fri Apr 17

PrefixCommons is a Python API designed for working with ID prefixes, enabling the canonicalization, expansion, and contraction of CURIEs (Compact URIs). It is currently at version 0.1.12 and maintains an infrequent release cadence, often aligned with specific project requirements such as those from the Alliance of Genome Resources.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to expand and contract CURIEs using the default prefix map provided by the library, as well as how to supply a custom prefix map or load a pre-defined biomedical context map for more specific use cases.

from prefixcommons.curie_util import expand_uri, contract_uri, read_biocontext

# Using the default prefix map
expanded_go = expand_uri('GO:0008150')
print(f"Expanded GO: {expanded_go}")

contracted_go = contract_uri('http://purl.obolibrary.org/obo/GO_0008150')
print(f"Contracted GO: {contracted_go}\n")

# Using a custom prefix map
custom_map = {'EXAMPLE': 'http://example.org/myterms/'}
expanded_custom = expand_uri('EXAMPLE:001', prefix_map=custom_map)
print(f"Expanded custom: {expanded_custom}")

# Loading a biomedical context map
bio_context = read_biocontext()
expanded_ncbi = expand_uri('NCBIGENE:12345', prefix_map=bio_context)
print(f"Expanded NCBIGENE from bio_context: {expanded_ncbi}")

view raw JSON →