airbyte_cdk.sources.declarative.retrievers.retriever

 1#
 2# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
 3#
 4
 5from abc import abstractmethod
 6from typing import Any, Iterable, Mapping, Optional
 7
 8from typing_extensions import deprecated
 9
10from airbyte_cdk.sources.streams.core import StreamData
11from airbyte_cdk.sources.types import StreamSlice, StreamState
12
13
14class Retriever:
15    """
16    Responsible for fetching a stream's records from an HTTP API source.
17    """
18
19    @abstractmethod
20    def read_records(
21        self,
22        records_schema: Mapping[str, Any],
23        stream_slice: Optional[StreamSlice] = None,
24    ) -> Iterable[StreamData]:
25        """
26        Fetch a stream's records from an HTTP API source
27
28        :param records_schema: json schema to describe record
29        :param stream_slice: The stream slice to read data for
30        :return: The records read from the API source
31        """
32
33    @deprecated("Stream slicing is being moved to the stream level.")
34    def stream_slices(self) -> Iterable[Optional[StreamSlice]]:
35        """Does nothing as this method is deprecated, so underlying Retriever implementations
36        do not need to implement this.
37        """
38        yield from []
39
40    @property
41    @deprecated("State management is being moved to the stream level.")
42    def state(self) -> StreamState:
43        """
44        Does nothing as this method is deprecated, so underlying Retriever implementations
45        do not need to implement this.
46        """
47        return {}
48
49    @state.setter
50    @deprecated("State management is being moved to the stream level.")
51    def state(self, value: StreamState) -> None:
52        """
53        Does nothing as this method is deprecated, so underlying Retriever implementations
54        do not need to implement this.
55        """
56        pass
class Retriever:
15class Retriever:
16    """
17    Responsible for fetching a stream's records from an HTTP API source.
18    """
19
20    @abstractmethod
21    def read_records(
22        self,
23        records_schema: Mapping[str, Any],
24        stream_slice: Optional[StreamSlice] = None,
25    ) -> Iterable[StreamData]:
26        """
27        Fetch a stream's records from an HTTP API source
28
29        :param records_schema: json schema to describe record
30        :param stream_slice: The stream slice to read data for
31        :return: The records read from the API source
32        """
33
34    @deprecated("Stream slicing is being moved to the stream level.")
35    def stream_slices(self) -> Iterable[Optional[StreamSlice]]:
36        """Does nothing as this method is deprecated, so underlying Retriever implementations
37        do not need to implement this.
38        """
39        yield from []
40
41    @property
42    @deprecated("State management is being moved to the stream level.")
43    def state(self) -> StreamState:
44        """
45        Does nothing as this method is deprecated, so underlying Retriever implementations
46        do not need to implement this.
47        """
48        return {}
49
50    @state.setter
51    @deprecated("State management is being moved to the stream level.")
52    def state(self, value: StreamState) -> None:
53        """
54        Does nothing as this method is deprecated, so underlying Retriever implementations
55        do not need to implement this.
56        """
57        pass

Responsible for fetching a stream's records from an HTTP API source.

@abstractmethod
def read_records( self, records_schema: Mapping[str, Any], stream_slice: Optional[airbyte_cdk.StreamSlice] = None) -> Iterable[Union[Mapping[str, Any], airbyte_cdk.AirbyteMessage]]:
20    @abstractmethod
21    def read_records(
22        self,
23        records_schema: Mapping[str, Any],
24        stream_slice: Optional[StreamSlice] = None,
25    ) -> Iterable[StreamData]:
26        """
27        Fetch a stream's records from an HTTP API source
28
29        :param records_schema: json schema to describe record
30        :param stream_slice: The stream slice to read data for
31        :return: The records read from the API source
32        """

Fetch a stream's records from an HTTP API source

Parameters
  • records_schema: json schema to describe record
  • stream_slice: The stream slice to read data for
Returns

The records read from the API source

@deprecated('Stream slicing is being moved to the stream level.')
def stream_slices(self) -> Iterable[Optional[airbyte_cdk.StreamSlice]]:
34    @deprecated("Stream slicing is being moved to the stream level.")
35    def stream_slices(self) -> Iterable[Optional[StreamSlice]]:
36        """Does nothing as this method is deprecated, so underlying Retriever implementations
37        do not need to implement this.
38        """
39        yield from []

Does nothing as this method is deprecated, so underlying Retriever implementations do not need to implement this.

state: Mapping[str, Any]
41    @property
42    @deprecated("State management is being moved to the stream level.")
43    def state(self) -> StreamState:
44        """
45        Does nothing as this method is deprecated, so underlying Retriever implementations
46        do not need to implement this.
47        """
48        return {}

Does nothing as this method is deprecated, so underlying Retriever implementations do not need to implement this.