airbyte-cdk 6.38.0.dev0__py3-none-any.whl → 6.38.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. airbyte_cdk/entrypoint.py +6 -6
  2. airbyte_cdk/logger.py +1 -4
  3. airbyte_cdk/sources/declarative/datetime/__init__.py +0 -4
  4. airbyte_cdk/sources/declarative/datetime/datetime_parser.py +4 -0
  5. airbyte_cdk/sources/declarative/declarative_component_schema.yaml +10 -2
  6. airbyte_cdk/sources/declarative/decoders/composite_raw_decoder.py +104 -42
  7. airbyte_cdk/sources/declarative/decoders/decoder.py +3 -3
  8. airbyte_cdk/sources/declarative/decoders/decoder_parser.py +30 -0
  9. airbyte_cdk/sources/declarative/decoders/zipfile_decoder.py +6 -9
  10. airbyte_cdk/sources/declarative/extractors/response_to_file_extractor.py +0 -2
  11. airbyte_cdk/sources/declarative/interpolation/macros.py +3 -5
  12. airbyte_cdk/sources/declarative/models/declarative_component_schema.py +7 -5
  13. airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py +37 -9
  14. airbyte_cdk/sources/declarative/requesters/http_requester.py +77 -25
  15. airbyte_cdk/sources/declarative/requesters/paginators/default_paginator.py +25 -4
  16. airbyte_cdk/sources/declarative/requesters/paginators/no_pagination.py +6 -1
  17. airbyte_cdk/sources/declarative/requesters/paginators/paginator.py +7 -2
  18. airbyte_cdk/sources/declarative/requesters/requester.py +7 -1
  19. airbyte_cdk/sources/declarative/retrievers/simple_retriever.py +21 -4
  20. airbyte_cdk/sources/declarative/yaml_declarative_source.py +0 -1
  21. airbyte_cdk/sources/streams/http/error_handlers/default_error_mapping.py +3 -3
  22. airbyte_cdk/sources/types.py +1 -0
  23. airbyte_cdk/utils/mapping_helpers.py +18 -1
  24. {airbyte_cdk-6.38.0.dev0.dist-info → airbyte_cdk-6.38.2.dist-info}/METADATA +3 -3
  25. {airbyte_cdk-6.38.0.dev0.dist-info → airbyte_cdk-6.38.2.dist-info}/RECORD +29 -33
  26. airbyte_cdk/sources/embedded/__init__.py +0 -3
  27. airbyte_cdk/sources/embedded/base_integration.py +0 -61
  28. airbyte_cdk/sources/embedded/catalog.py +0 -57
  29. airbyte_cdk/sources/embedded/runner.py +0 -57
  30. airbyte_cdk/sources/embedded/tools.py +0 -27
  31. {airbyte_cdk-6.38.0.dev0.dist-info → airbyte_cdk-6.38.2.dist-info}/LICENSE.txt +0 -0
  32. {airbyte_cdk-6.38.0.dev0.dist-info → airbyte_cdk-6.38.2.dist-info}/LICENSE_SHORT +0 -0
  33. {airbyte_cdk-6.38.0.dev0.dist-info → airbyte_cdk-6.38.2.dist-info}/WHEEL +0 -0
  34. {airbyte_cdk-6.38.0.dev0.dist-info → airbyte_cdk-6.38.2.dist-info}/entry_points.txt +0 -0
@@ -1,61 +0,0 @@
1
- #
2
- # Copyright (c) 2023 Airbyte, Inc., all rights reserved.
3
- #
4
-
5
- from abc import ABC, abstractmethod
6
- from typing import Generic, Iterable, Optional, TypeVar
7
-
8
- from airbyte_cdk.connector import TConfig
9
- from airbyte_cdk.models import AirbyteRecordMessage, AirbyteStateMessage, SyncMode, Type
10
- from airbyte_cdk.sources.embedded.catalog import (
11
- create_configured_catalog,
12
- get_stream,
13
- get_stream_names,
14
- )
15
- from airbyte_cdk.sources.embedded.runner import SourceRunner
16
- from airbyte_cdk.sources.embedded.tools import get_defined_id
17
- from airbyte_cdk.sources.utils.schema_helpers import check_config_against_spec_or_exit
18
-
19
- TOutput = TypeVar("TOutput")
20
-
21
-
22
- class BaseEmbeddedIntegration(ABC, Generic[TConfig, TOutput]):
23
- def __init__(self, runner: SourceRunner[TConfig], config: TConfig):
24
- check_config_against_spec_or_exit(config, runner.spec())
25
-
26
- self.source = runner
27
- self.config = config
28
-
29
- self.last_state: Optional[AirbyteStateMessage] = None
30
-
31
- @abstractmethod
32
- def _handle_record(self, record: AirbyteRecordMessage, id: Optional[str]) -> Optional[TOutput]:
33
- """
34
- Turn an Airbyte record into the appropriate output type for the integration.
35
- """
36
- pass
37
-
38
- def _load_data(
39
- self, stream_name: str, state: Optional[AirbyteStateMessage] = None
40
- ) -> Iterable[TOutput]:
41
- catalog = self.source.discover(self.config)
42
- stream = get_stream(catalog, stream_name)
43
- if not stream:
44
- raise ValueError(
45
- f"Stream {stream_name} not found, the following streams are available: {', '.join(get_stream_names(catalog))}"
46
- )
47
- if SyncMode.incremental not in stream.supported_sync_modes:
48
- configured_catalog = create_configured_catalog(stream, sync_mode=SyncMode.full_refresh)
49
- else:
50
- configured_catalog = create_configured_catalog(stream, sync_mode=SyncMode.incremental)
51
-
52
- for message in self.source.read(self.config, configured_catalog, state):
53
- if message.type == Type.RECORD:
54
- output = self._handle_record(
55
- message.record,
56
- get_defined_id(stream, message.record.data), # type: ignore[union-attr, arg-type]
57
- )
58
- if output:
59
- yield output
60
- elif message.type is Type.STATE and message.state:
61
- self.last_state = message.state
@@ -1,57 +0,0 @@
1
- #
2
- # Copyright (c) 2023 Airbyte, Inc., all rights reserved.
3
- #
4
-
5
- from typing import List, Optional
6
-
7
- from airbyte_cdk.models import (
8
- AirbyteCatalog,
9
- AirbyteStream,
10
- ConfiguredAirbyteCatalog,
11
- ConfiguredAirbyteStream,
12
- DestinationSyncMode,
13
- SyncMode,
14
- )
15
- from airbyte_cdk.sources.embedded.tools import get_first
16
-
17
-
18
- def get_stream(catalog: AirbyteCatalog, stream_name: str) -> Optional[AirbyteStream]:
19
- return get_first(catalog.streams, lambda s: s.name == stream_name)
20
-
21
-
22
- def get_stream_names(catalog: AirbyteCatalog) -> List[str]:
23
- return [stream.name for stream in catalog.streams]
24
-
25
-
26
- def to_configured_stream(
27
- stream: AirbyteStream,
28
- sync_mode: SyncMode = SyncMode.full_refresh,
29
- destination_sync_mode: DestinationSyncMode = DestinationSyncMode.append,
30
- cursor_field: Optional[List[str]] = None,
31
- primary_key: Optional[List[List[str]]] = None,
32
- ) -> ConfiguredAirbyteStream:
33
- return ConfiguredAirbyteStream(
34
- stream=stream,
35
- sync_mode=sync_mode,
36
- destination_sync_mode=destination_sync_mode,
37
- cursor_field=cursor_field,
38
- primary_key=primary_key,
39
- )
40
-
41
-
42
- def to_configured_catalog(
43
- configured_streams: List[ConfiguredAirbyteStream],
44
- ) -> ConfiguredAirbyteCatalog:
45
- return ConfiguredAirbyteCatalog(streams=configured_streams)
46
-
47
-
48
- def create_configured_catalog(
49
- stream: AirbyteStream, sync_mode: SyncMode = SyncMode.full_refresh
50
- ) -> ConfiguredAirbyteCatalog:
51
- configured_streams = [
52
- to_configured_stream(
53
- stream, sync_mode=sync_mode, primary_key=stream.source_defined_primary_key
54
- )
55
- ]
56
-
57
- return to_configured_catalog(configured_streams)
@@ -1,57 +0,0 @@
1
- #
2
- # Copyright (c) 2023 Airbyte, Inc., all rights reserved.
3
- #
4
-
5
-
6
- import logging
7
- from abc import ABC, abstractmethod
8
- from typing import Generic, Iterable, Optional
9
-
10
- from airbyte_cdk.connector import TConfig
11
- from airbyte_cdk.models import (
12
- AirbyteCatalog,
13
- AirbyteMessage,
14
- AirbyteStateMessage,
15
- ConfiguredAirbyteCatalog,
16
- ConnectorSpecification,
17
- )
18
- from airbyte_cdk.sources.source import Source
19
-
20
-
21
- class SourceRunner(ABC, Generic[TConfig]):
22
- @abstractmethod
23
- def spec(self) -> ConnectorSpecification:
24
- pass
25
-
26
- @abstractmethod
27
- def discover(self, config: TConfig) -> AirbyteCatalog:
28
- pass
29
-
30
- @abstractmethod
31
- def read(
32
- self,
33
- config: TConfig,
34
- catalog: ConfiguredAirbyteCatalog,
35
- state: Optional[AirbyteStateMessage],
36
- ) -> Iterable[AirbyteMessage]:
37
- pass
38
-
39
-
40
- class CDKRunner(SourceRunner[TConfig]):
41
- def __init__(self, source: Source, name: str):
42
- self._source = source
43
- self._logger = logging.getLogger(name)
44
-
45
- def spec(self) -> ConnectorSpecification:
46
- return self._source.spec(self._logger)
47
-
48
- def discover(self, config: TConfig) -> AirbyteCatalog:
49
- return self._source.discover(self._logger, config)
50
-
51
- def read(
52
- self,
53
- config: TConfig,
54
- catalog: ConfiguredAirbyteCatalog,
55
- state: Optional[AirbyteStateMessage],
56
- ) -> Iterable[AirbyteMessage]:
57
- return self._source.read(self._logger, config, catalog, state=[state] if state else [])
@@ -1,27 +0,0 @@
1
- #
2
- # Copyright (c) 2023 Airbyte, Inc., all rights reserved.
3
- #
4
-
5
- from typing import Any, Callable, Dict, Iterable, Optional
6
-
7
- import dpath
8
-
9
- from airbyte_cdk.models import AirbyteStream
10
-
11
-
12
- def get_first(
13
- iterable: Iterable[Any], predicate: Callable[[Any], bool] = lambda m: True
14
- ) -> Optional[Any]:
15
- return next(filter(predicate, iterable), None)
16
-
17
-
18
- def get_defined_id(stream: AirbyteStream, data: Dict[str, Any]) -> Optional[str]:
19
- if not stream.source_defined_primary_key:
20
- return None
21
- primary_key = []
22
- for key in stream.source_defined_primary_key:
23
- try:
24
- primary_key.append(str(dpath.get(data, key)))
25
- except KeyError:
26
- primary_key.append("__not_found__")
27
- return "_".join(primary_key)