{"id":10058,"library":"prefixcommons","title":"PrefixCommons Python API","description":"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.","status":"active","version":"0.1.12","language":"en","source_language":"en","source_url":"https://github.com/prefixcommons/prefixcommons-py","tags":["CURIEs","identifiers","bioinformatics","data-interoperability","linked-data"],"install":[{"cmd":"pip install prefixcommons","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for fetching external resources and context maps, although core functionality doesn't strictly depend on it for local maps.","package":"requests","optional":false}],"imports":[{"note":"Core utility functions like expand_uri and contract_uri reside in the `curie_util` submodule, not directly under the top-level package.","wrong":"from prefixcommons import expand_uri","symbol":"expand_uri","correct":"from prefixcommons.curie_util import expand_uri"},{"note":"Core utility functions like expand_uri and contract_uri reside in the `curie_util` submodule, not directly under the top-level package.","wrong":"from prefixcommons import contract_uri","symbol":"contract_uri","correct":"from prefixcommons.curie_util import contract_uri"},{"note":"Helper function to load a common set of biomedical prefixes.","symbol":"read_biocontext","correct":"from prefixcommons.curie_util import read_biocontext"}],"quickstart":{"code":"from prefixcommons.curie_util import expand_uri, contract_uri, read_biocontext\n\n# Using the default prefix map\nexpanded_go = expand_uri('GO:0008150')\nprint(f\"Expanded GO: {expanded_go}\")\n\ncontracted_go = contract_uri('http://purl.obolibrary.org/obo/GO_0008150')\nprint(f\"Contracted GO: {contracted_go}\\n\")\n\n# Using a custom prefix map\ncustom_map = {'EXAMPLE': 'http://example.org/myterms/'}\nexpanded_custom = expand_uri('EXAMPLE:001', prefix_map=custom_map)\nprint(f\"Expanded custom: {expanded_custom}\")\n\n# Loading a biomedical context map\nbio_context = read_biocontext()\nexpanded_ncbi = expand_uri('NCBIGENE:12345', prefix_map=bio_context)\nprint(f\"Expanded NCBIGENE from bio_context: {expanded_ncbi}\")","lang":"python","description":"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."},"warnings":[{"fix":"Consider explicitly loading domain-specific context maps using functions like `prefixcommons.curie_util.read_biocontext()` or provide your own custom `prefix_map` dictionary to functions like `expand_uri` and `contract_uri`.","message":"The default prefix map, loaded internally from `resources/prefixcommons.jsonld`, may not be exhaustive for all domains or may become stale over time. For robust applications, relying solely on this default map for critical or very specific prefixes is not recommended.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For applications requiring the absolute latest or highly specialized prefix definitions, it is advisable to rely on custom-maintained prefix maps or external services rather than solely on the library's built-in defaults. Monitor the GitHub repository for updates.","message":"PrefixCommons has an infrequent release cadence, often tied to specific project needs. While stable, this means that updates to its default prefix maps for very new or niche identifiers might not be as frequent as external data sources.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Change your import statement from `from prefixcommons import expand_uri` (or similar) to `from prefixcommons.curie_util import expand_uri, contract_uri`.","cause":"Attempting to import core utility functions directly from the top-level `prefixcommons` package instead of their specific submodule `curie_util`.","error":"ModuleNotFoundError: No module named 'prefixcommons.curie_util'"},{"fix":"Ensure that the `prefix_map` supplied to `expand_uri` or `contract_uri` (or the default map being used) contains the required prefix. You can load specific contexts using `prefixcommons.curie_util.read_biocontext()` or pass a custom dictionary: `expand_uri('MYAPP:123', prefix_map={'MYAPP': 'http://example.com/myapp/'})`.","cause":"The CURIE prefix (e.g., 'MYAPP' in 'MYAPP:123') is not found in the currently active prefix map when attempting to expand or contract a URI.","error":"KeyError: 'UNKNOWN_PREFIX'"}]}