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.
pip install prefixcommonsVerified import paths — ran on the pinned version, not inferred.
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.
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`.
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.
Change your import statement from `from prefixcommons import expand_uri` (or similar) to `from prefixcommons.curie_util import expand_uri, contract_uri`.
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/'})`.