Idiomatic conversion between URIs and compact URIs (CURIEs)

0.13.3 · active · verified Thu Apr 16

The `curies` Python package provides efficient, faultless, and idiomatic utilities for converting between Uniform Resource Identifiers (URIs) and Compact URIs (CURIEs). It is a crucial low-level tool for linked data applications, enabling data scientists, curators, and software developers to handle prefix maps, expand CURIEs to URIs, and compress URIs to CURIEs. The library is actively developed, currently at version 0.13.3, with ongoing enhancements for robustness and usability.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load a predefined CURIE converter and then use it to expand CURIEs to URIs and compress URIs back to CURIEs. Alternatively, you can define and load your own prefix map.

import curies

# Option 1: Load a predefined converter (e.g., OBO Foundry)
converter = curies.get_obo_converter()

# Option 2: Load a custom prefix map
# prefix_map = {"CHEBI": "http://purl.obolibrary.org/obo/CHEBI_"}
# converter = curies.load_prefix_map(prefix_map)

# Expand a CURIE to a URI
curie_example = "CHEBI:1"
expanded_uri = converter.expand(curie_example)
print(f"Expanded '{curie_example}' to '{expanded_uri}'")
# Expected: Expanded 'CHEBI:1' to 'http://purl.obolibrary.org/obo/CHEBI_1'

# Compress a URI to a CURIE
uri_example = "http://purl.obolibrary.org/obo/CHEBI_2"
compressed_curie = converter.compress(uri_example)
print(f"Compressed '{uri_example}' to '{compressed_curie}'")
# Expected: Compressed 'http://purl.obolibrary.org/obo/CHEBI_2' to 'CHEBI:2'

view raw JSON →