Reference

class Reference(*, prefix: str, 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_computed_fields

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config

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

model_fields

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

pair

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

Methods Summary

from_curie(curie[, sep])

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_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'frozen': True}

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

model_fields: ClassVar[dict[str, FieldInfo]] = {'identifier': FieldInfo(annotation=str, required=True, description='The local unique identifier used in a compact URI (CURIE).'), 'prefix': FieldInfo(annotation=str, required=True, description='The prefix used in a compact URI (CURIE).')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

pair

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

Methods Documentation

classmethod from_curie(curie: str, sep: str = ':') Reference[source]

Parse a CURIE string and populate a reference.

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

  • sep – The separator

Returns:

A reference object

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