5050
5151
5252class AbstractSource (Source , ABC ):
53- """
54- Abstract base class for an Airbyte Source. Consumers should implement any abstract methods
55- in this class to create an Airbyte Specification compliant Source.
56- """
53+ """Base class for Airbyte source connectors that orchestrates stream reading and state management."""
5754
5855 @abstractmethod
5956 def check_connection (
6057 self , logger : logging .Logger , config : Mapping [str , Any ]
6158 ) -> Tuple [bool , Optional [Any ]]:
62- """
63- :param logger: source logger
64- :param config: The user-provided configuration as specified by the source's spec.
65- This usually contains information required to check connection e.g. tokens, secrets and keys etc .
66- :return: A tuple of (boolean, error). If boolean is true, then the connection check is successful
67- and we can connect to the underlying data source using the provided configuration.
68- Otherwise, the input config cannot be used to connect to the underlying data source,
69- and the " error" object should describe what went wrong .
70- The error object will be cast to string to display the problem to the user.
59+ """Validates that the provided configuration can successfully connect to the data source.
60+
61+ Args:
62+ logger: Source logger for diagnostic output .
63+ config: User-provided configuration containing credentials and connection parameters.
64+
65+ Returns:
66+ Tuple of (success boolean, error object). If success is True, connection is valid .
67+ If False, error object describes what went wrong and will be displayed to the user.
7168 """
7269
7370 @abstractmethod
7471 def streams (self , config : Mapping [str , Any ]) -> List [Stream ]:
75- """
76- :param config: The user-provided configuration as specified by the source's spec.
77- Any stream construction related operation should happen here.
78- :return: A list of the streams in this source connector .
72+ """Returns the list of streams available in this source connector.
73+
74+ Args:
75+ config: User-provided configuration for initializing streams .
7976 """
8077
8178 # Stream name to instance map for applying output object transformation
8279 _stream_to_instance_map : Dict [str , Stream ] = {}
8380 _slice_logger : SliceLogger = DebugSliceLogger ()
8481
8582 def discover (self , logger : logging .Logger , config : Mapping [str , Any ]) -> AirbyteCatalog :
86- """Implements the Discover operation from the Airbyte Specification.
87- See https://docs.airbyte.com/understanding-airbyte/airbyte-protocol/#discover.
88- """
83+ """Discovers available streams and their schemas from the data source."""
8984 streams = [stream .as_airbyte_stream () for stream in self .streams (config = config )]
9085 return AirbyteCatalog (streams = streams )
9186
9287 def check (self , logger : logging .Logger , config : Mapping [str , Any ]) -> AirbyteConnectionStatus :
93- """Implements the Check Connection operation from the Airbyte Specification.
94- See https://docs.airbyte.com/understanding-airbyte/airbyte-protocol/#check.
95- """
88+ """Validates connection to the data source using the provided configuration."""
9689 check_succeeded , error = self .check_connection (logger , config )
9790 if not check_succeeded :
9891 return AirbyteConnectionStatus (status = Status .FAILED , message = repr (error ))
@@ -105,7 +98,7 @@ def read(
10598 catalog : ConfiguredAirbyteCatalog ,
10699 state : Optional [List [AirbyteStateMessage ]] = None ,
107100 ) -> Iterator [AirbyteMessage ]:
108- """Implements the Read operation from the Airbyte Specification. See https://docs.airbyte.com/understanding-airbyte/airbyte-protocol/ ."""
101+ """Reads records from configured streams and emits them as Airbyte messages ."""
109102 logger .info (f"Starting syncing { self .name } " )
110103 config , internal_config = split_config (config )
111104 # TODO assert all streams exist in the connector
@@ -214,6 +207,7 @@ def read(
214207 def _serialize_exception (
215208 stream_descriptor : StreamDescriptor , e : Exception , stream_instance : Optional [Stream ] = None
216209 ) -> AirbyteTracedException :
210+ """Converts an exception into an AirbyteTracedException with optional stream-specific error message."""
217211 display_message = stream_instance .get_error_display_message (e ) if stream_instance else None
218212 if display_message :
219213 return AirbyteTracedException .from_exception (
@@ -223,6 +217,7 @@ def _serialize_exception(
223217
224218 @property
225219 def raise_exception_on_missing_stream (self ) -> bool :
220+ """Controls whether to raise an exception when a configured stream is not found in the source."""
226221 return False
227222
228223 def _read_stream (
@@ -233,6 +228,7 @@ def _read_stream(
233228 state_manager : ConnectorStateManager ,
234229 internal_config : InternalConfig ,
235230 ) -> Iterator [AirbyteMessage ]:
231+ """Reads records from a single stream and emits them as Airbyte messages."""
236232 if internal_config .page_size and isinstance (stream_instance , HttpStream ):
237233 logger .info (
238234 f"Setting page size for { stream_instance .name } to { internal_config .page_size } "
@@ -289,16 +285,15 @@ def _read_stream(
289285 logger .info (f"Read { record_counter } records from { stream_name } stream" )
290286
291287 def _emit_queued_messages (self ) -> Iterable [AirbyteMessage ]:
288+ """Emits any messages that have been queued in the message repository."""
292289 if self .message_repository :
293290 yield from self .message_repository .consume_queue ()
294291 return
295292
296293 def _get_message (
297294 self , record_data_or_message : Union [StreamData , AirbyteMessage ], stream : Stream
298295 ) -> AirbyteMessage :
299- """
300- Converts the input to an AirbyteMessage if it is a StreamData. Returns the input as is if it is already an AirbyteMessage
301- """
296+ """Converts StreamData to AirbyteMessage or returns the input if already an AirbyteMessage."""
302297 match record_data_or_message :
303298 case AirbyteMessage ():
304299 return record_data_or_message
@@ -312,11 +307,13 @@ def _get_message(
312307
313308 @property
314309 def message_repository (self ) -> Union [None , MessageRepository ]:
310+ """Returns the message repository used for queuing messages during sync operations."""
315311 return _default_message_repository
316312
317313 @property
318314 def stop_sync_on_stream_failure (self ) -> bool :
319- """
315+ """Controls whether to stop the entire sync when a single stream fails.
316+
320317 WARNING: This function is in-development which means it is subject to change. Use at your own risk.
321318
322319 By default, when a source encounters an exception while syncing a stream, it will emit an error trace message and then
0 commit comments