Reference

class Reference(*, prefix: Prefix, identifier: str)[source]

Bases: BaseModel

A reference to an entity in a given identifier space.

This class uses Pydantic to make it easier to build other more complex data types with Pydantic that also uses a first- class notion of parsed reference (instead of merely stringified CURIEs). Instances of this class can also be hashed because of the “frozen” configuration from Pydantic (see https://docs.pydantic.dev/latest/usage/model_config/ for more details).

A reference can be constructed several ways:

>>> Reference(prefix="chebi", identifier="1234")
Reference(prefix='chebi', identifier='1234')
>>> Reference.from_curie("chebi:1234")
Reference(prefix='chebi', identifier='1234')

A reference can also be constructued using Pydantic’s parsing utilities, but keep in mind if you’re using Pydantic v1 or Pydantic v2.

A reference can be formatted as a CURIE string with the curie attribute

>>> Reference.from_curie("chebi:1234").curie
'chebi:1234'

References can’t be sliced like reference tuples, but they can still be accessed through attributes

>>> t = Reference.from_curie("chebi:1234")
>>> t.prefix
'chebi'
>>> t.identifier
'1234'

If you need a performance gain, you can get a ReferenceTuple using the pair attribute:

>>> reference = Reference.from_curie("chebi:1234")
>>> reference.pair
ReferenceTuple(prefix='chebi', identifier='1234')

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

curie

Get the reference as a CURIE string.

model_config

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

pair

Get the reference as a 2-tuple of prefix and identifier.

Methods Summary

from_curie(curie, *[, sep, converter])

Parse a CURIE string and populate a reference.

Attributes Documentation

curie

Get the reference as a CURIE string.

Returns:

A string representation of a compact URI (CURIE).

>>> Reference(prefix="chebi", identifier="1234").curie
'chebi:1234'
model_config: ClassVar[ConfigDict] = {'frozen': True}

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

pair

Get the reference as a 2-tuple of prefix and identifier.

Methods Documentation

classmethod from_curie(curie: str, *, sep: str = ':', converter: Converter | None = None) Reference[source]

Parse a CURIE string and populate a reference.

Parameters:
  • curie – A string representation of a compact URI (CURIE)

  • sep – The separator

  • converter – The converter to use as context when parsing

Returns:

A reference object

>>> Reference.from_curie("chebi:1234")
Reference(prefix='chebi', identifier='1234')