Skip to content

Latest commit

 

History

History
69 lines (54 loc) · 1.89 KB

File metadata and controls

69 lines (54 loc) · 1.89 KB
title Annotated Results
sidebar_position 4
description This guide provides instructions for returning extra response metadata from Provider extension models. Use this class to include important citations, credits, or other dictionary-like items that should not be included in table or chart data.
keywords
ODP
credits
source
citation
accreditation
OpenBB Platform
metadata
provider
results metadata
AnnotatedResult
annotations
develop
results

import HeadTitle from '@site/src/components/General/HeadTitle.tsx';

AnnotatedResult Class

Use this class to return function metadata, or other data, that is not intended to be included with the main results.

For example, source citations can be included by using this object as a wrapper for the real results.

from openbb_core.provider.abstract.annotated_result import AnnotatedResult

Initialize the class with two objects.

  • result: Any
    • Serializable results - i.e, list[dict]
  • metadata: dict
    • JSON-encodable dictionary

How To Use

:::important The class is used in conjunction with the ProviderInterface. :::

In the provider's Fetcher.transform_data method, wrap and annotate the output like below.

    @staticmethod
    def transform_data(
        query: FredSeriesQueryParams,
        data: dict,
        **kwargs: Any,
    ) -> AnnotatedResult[list[FredSeriesData]]:
        """Transform data."""
        records = data.get("results", [])
        metadata = data.get("metadata", {})

        return AnnotatedResult(
            result=[FredSeriesData.model_validate(r) for r in records],
            metadata=metadata,
        )

Output

When the pattern above is used, the metadata dictionary is returned to, output.extra["results_metadata"].