{"id":10059,"library":"prefixmaps","title":"Prefixmaps Library","description":"The `prefixmaps` library, currently at version 0.2.6, is a Python tool for managing and resolving semantic prefix maps, particularly for CURIEs (Compact URIs). It simplifies the expansion of short-form identifiers into full IRIs and vice versa, primarily by leveraging community-maintained prefix registries like those from OBO Foundry. Releases occur periodically to update prefix data and improve functionality.","status":"active","version":"0.2.6","language":"en","source_language":"en","source_url":"https://github.com/prefixcommons/prefixmaps","tags":["semantic web","curie","iri","namespaces","ontologies","identifiers","linked data"],"install":[{"cmd":"pip install prefixmaps","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for data validation and parsing of prefix map schemas.","package":"pydantic"}],"imports":[{"symbol":"PrefixMap","correct":"from prefixmaps import PrefixMap"},{"symbol":"load_jsonld_context","correct":"from prefixmaps.io import load_jsonld_context"}],"quickstart":{"code":"from prefixmaps import PrefixMap\n\n# Initialize with the default OBO Foundry prefix map (loaded from the web)\npm = PrefixMap()\n\n# Expand a CURIE (Compact URI) to a full IRI\ncurie = \"GO:0008150\"\niri = pm.expand(curie)\nprint(f\"Expanded {curie} to: {iri}\")\n\n# Compress a full IRI to a CURIE (if a matching prefix is found)\nfull_iri = \"http://purl.obolibrary.org/obo/BFO_0000001\"\ncompressed_curie = pm.compress(full_iri)\nprint(f\"Compressed {full_iri} to: {compressed_curie}\")\n\n# Check if a prefix exists in the map\nprint(f\"Has prefix 'GO': {pm.has_prefix('GO')}\")\nprint(f\"Has prefix 'UNKNOWN': {pm.has_prefix('UNKNOWN')}\")","lang":"python","description":"Demonstrates initializing a PrefixMap, expanding a CURIE, compressing an IRI, and checking for prefix existence."},"warnings":[{"fix":"Use `pm = PrefixMap()` for the default registry or `PrefixMap.load_default_registry()` for explicit loading.","message":"The method for loading the default registry has changed across minor versions. Directly calling `prefixmaps.io.get_and_parse_default_registry()` is now deprecated or removed.","severity":"breaking","affected_versions":"<0.2.0"},{"fix":"For offline or controlled environments, consider using `PrefixMap.load_from_json(filepath)` or `PrefixMap.load_from_shacl(filepath)` with a locally cached registry file. The library also allows specifying a custom URL for the registry.","message":"Initializing `PrefixMap()` without arguments attempts to load the default prefix registry from a remote web source (e.g., OBO Foundry). This operation will fail without an internet connection or if the remote source is temporarily unavailable.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Always check the return value of `pm.expand(curie)`: `iri = pm.expand(curie); if iri is None: print(f\"Unknown prefix for {curie}\")`.","message":"The `expand()` method returns `None` if a given CURIE's prefix is not found in the loaded `PrefixMap`, rather than raising an error. This requires explicit `None` checking in application code.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use `pm = PrefixMap()` to load the default registry or `PrefixMap.load_default_registry()` if you need to load it explicitly without creating a new `PrefixMap` instance immediately.","message":"Direct access to `prefixmaps.io.get_and_parse_default_registry()` is deprecated. This function was an internal detail that has been superseded by the `PrefixMap` constructor and class methods.","severity":"deprecated","affected_versions":">=0.2.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install prefixmaps` to install the library.","cause":"The `prefixmaps` library is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'prefixmaps'"},{"fix":"Ensure that your `PrefixMap` instance includes a mapping for the base IRI you are trying to compress, or handle the `ValueError` gracefully. You might need to add a custom prefix map entry using `pm.add_prefix(prefix, iri_prefix)`.","cause":"The `compress()` method was called with an IRI for which no matching prefix is defined in the current `PrefixMap` instance.","error":"ValueError: Missing prefix for IRI: http://example.org/myterm"},{"fix":"Rename the method call from `obj.compress_uri()` to `obj.compress()`.","cause":"An outdated or incorrect method name was used. The correct method for compressing an IRI is `compress()`.","error":"AttributeError: 'PrefixMap' object has no attribute 'compress_uri'"}]}