PrefixMap

class PrefixMap(root: RootModelRootType = PydanticUndefined)[source]

Bases: RootModel[dict[Prefix, str]]

A simple prefix map.

This can be used to validate dictionaries:

from curies import PrefixMap

prefix_map_model = PrefixMap.model_validate(
    {
        "CHEBI": "http://purl.obolibrary.org/obo/CHEBI_",
    }
)

# note that you have to unpack it
prefix_map_dict = prefix_map_model.root

Similarly, a prefix map can be used as part of another Pydantic model like in:

from pydantic import BaseModel
from curies import PrefixMap


class RDFContent(BaseModel):
    prefix_map: PrefixMap
    triples: list[tuple[str, str, str]]


rdf_content = RDFContent.model_validate(
    {
        "prefix_map": {
            "CHEBI": "http://purl.obolibrary.org/obo/CHEBI_",
        },
        "triples": [
            ("CHEBI:1234", "RO:0000001", "CHEBI:5678"),
        ],
    }
)

# note that you have to unpack the resulting prefix map
prefix_map = rdf_content.prefix_map.root

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Attributes Summary

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Attributes Documentation

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].