airbyte-cdk 6.6.3__py3-none-any.whl → 6.6.4__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.
@@ -0,0 +1 @@
1
+ # Copyright (c) 2024 Airbyte, Inc., all rights reserved.
@@ -0,0 +1,6 @@
1
+ from airbyte_cdk.cli.source_declarative_manifest._run import run
2
+
3
+
4
+ __all__ = [
5
+ "run",
6
+ ]
@@ -0,0 +1,223 @@
1
+ # Copyright (c) 2024 Airbyte, Inc., all rights reserved.
2
+ """Defines the `source-declarative-manifest` connector, which installs alongside CDK.
3
+
4
+ This file was originally imported from the dedicated connector directory, under the
5
+ `airbyte` monorepo.
6
+
7
+ Usage:
8
+
9
+ ```
10
+ pipx install airbyte-cdk
11
+ source-declarative-manifest --help
12
+ source-declarative-manifest spec
13
+ ...
14
+ ```
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import json
20
+ import pkgutil
21
+ import sys
22
+ import traceback
23
+ from collections.abc import Mapping
24
+ from datetime import datetime
25
+ from pathlib import Path
26
+ from typing import Any, cast
27
+
28
+ from airbyte_cdk.entrypoint import AirbyteEntrypoint, launch
29
+ from airbyte_cdk.models import (
30
+ AirbyteErrorTraceMessage,
31
+ AirbyteMessage,
32
+ AirbyteMessageSerializer,
33
+ AirbyteStateMessage,
34
+ AirbyteTraceMessage,
35
+ ConfiguredAirbyteCatalog,
36
+ ConnectorSpecificationSerializer,
37
+ TraceType,
38
+ Type,
39
+ )
40
+ from airbyte_cdk.sources.declarative.concurrent_declarative_source import (
41
+ ConcurrentDeclarativeSource,
42
+ )
43
+ from airbyte_cdk.sources.declarative.yaml_declarative_source import YamlDeclarativeSource
44
+ from airbyte_cdk.sources.source import TState
45
+ from orjson import orjson
46
+
47
+
48
+ class SourceLocalYaml(YamlDeclarativeSource):
49
+ """
50
+ Declarative source defined by a yaml file in the local filesystem
51
+ """
52
+
53
+ def __init__(
54
+ self,
55
+ catalog: ConfiguredAirbyteCatalog | None,
56
+ config: Mapping[str, Any] | None,
57
+ state: TState,
58
+ **kwargs: Any,
59
+ ) -> None:
60
+ """
61
+ HACK!
62
+ Problem: YamlDeclarativeSource relies on the calling module name/path to find the yaml file.
63
+ Implication: If you call YamlDeclarativeSource directly it will look for the yaml file in the wrong place. (e.g. the airbyte-cdk package)
64
+ Solution: Subclass YamlDeclarativeSource from the same location as the manifest to load.
65
+
66
+ When can we remove this?
67
+ When the airbyte-cdk is updated to not rely on the calling module name/path to find the yaml file.
68
+ When all manifest connectors are updated to use the new airbyte-cdk.
69
+ When all manifest connectors are updated to use the source-declarative-manifest as the base image.
70
+ """
71
+ super().__init__(
72
+ catalog=catalog,
73
+ config=config,
74
+ state=state,
75
+ path_to_yaml="manifest.yaml",
76
+ )
77
+
78
+
79
+ def _is_local_manifest_command(args: list[str]) -> bool:
80
+ # Check for a local manifest.yaml file
81
+ return Path("/airbyte/integration_code/source_declarative_manifest/manifest.yaml").exists()
82
+
83
+
84
+ def handle_command(args: list[str]) -> None:
85
+ if _is_local_manifest_command(args):
86
+ handle_local_manifest_command(args)
87
+ else:
88
+ handle_remote_manifest_command(args)
89
+
90
+
91
+ def _get_local_yaml_source(args: list[str]) -> SourceLocalYaml:
92
+ try:
93
+ config, catalog, state = _parse_inputs_into_config_catalog_state(args)
94
+ return SourceLocalYaml(config=config, catalog=catalog, state=state)
95
+ except Exception as error:
96
+ print(
97
+ orjson.dumps(
98
+ AirbyteMessageSerializer.dump(
99
+ AirbyteMessage(
100
+ type=Type.TRACE,
101
+ trace=AirbyteTraceMessage(
102
+ type=TraceType.ERROR,
103
+ emitted_at=int(datetime.now().timestamp() * 1000),
104
+ error=AirbyteErrorTraceMessage(
105
+ message=f"Error starting the sync. This could be due to an invalid configuration or catalog. Please contact Support for assistance. Error: {error}",
106
+ stack_trace=traceback.format_exc(),
107
+ ),
108
+ ),
109
+ )
110
+ )
111
+ ).decode()
112
+ )
113
+ raise error
114
+
115
+
116
+ def handle_local_manifest_command(args: list[str]) -> None:
117
+ source = _get_local_yaml_source(args)
118
+ launch(
119
+ source=source,
120
+ args=args,
121
+ )
122
+
123
+
124
+ def handle_remote_manifest_command(args: list[str]) -> None:
125
+ """Overrides the spec command to return the generalized spec for the declarative manifest source.
126
+
127
+ This is different from a typical low-code, but built and published separately source built as a ManifestDeclarativeSource,
128
+ because that will have a spec method that returns the spec for that specific source. Other than spec,
129
+ the generalized connector behaves the same as any other, since the manifest is provided in the config.
130
+ """
131
+ if args[0] == "spec":
132
+ json_spec = pkgutil.get_data(
133
+ "airbyte_cdk.cli.source_declarative_manifest",
134
+ "spec.json",
135
+ )
136
+ if json_spec is None:
137
+ raise FileNotFoundError(
138
+ "Could not find `spec.json` file for source-declarative-manifest"
139
+ )
140
+
141
+ spec_obj = json.loads(json_spec)
142
+ spec = ConnectorSpecificationSerializer.load(spec_obj)
143
+
144
+ message = AirbyteMessage(type=Type.SPEC, spec=spec)
145
+ print(AirbyteEntrypoint.airbyte_message_to_string(message))
146
+ else:
147
+ source = create_declarative_source(args)
148
+ launch(
149
+ source=source,
150
+ args=args,
151
+ )
152
+
153
+
154
+ def create_declarative_source(args: list[str]) -> ConcurrentDeclarativeSource:
155
+ """Creates the source with the injected config.
156
+
157
+ This essentially does what other low-code sources do at build time, but at runtime,
158
+ with a user-provided manifest in the config. This better reflects what happens in the
159
+ connector builder.
160
+ """
161
+ try:
162
+ config, catalog, state = _parse_inputs_into_config_catalog_state(args)
163
+ if "__injected_declarative_manifest" not in config:
164
+ raise ValueError(
165
+ f"Invalid config: `__injected_declarative_manifest` should be provided at the root of the config but config only has keys {list(config.keys())}"
166
+ )
167
+ return ConcurrentDeclarativeSource(
168
+ config=config,
169
+ catalog=catalog,
170
+ state=state,
171
+ source_config=cast(dict[str, Any], config["__injected_declarative_manifest"]),
172
+ )
173
+ except Exception as error:
174
+ print(
175
+ orjson.dumps(
176
+ AirbyteMessageSerializer.dump(
177
+ AirbyteMessage(
178
+ type=Type.TRACE,
179
+ trace=AirbyteTraceMessage(
180
+ type=TraceType.ERROR,
181
+ emitted_at=int(datetime.now().timestamp() * 1000),
182
+ error=AirbyteErrorTraceMessage(
183
+ message=f"Error starting the sync. This could be due to an invalid configuration or catalog. Please contact Support for assistance. Error: {error}",
184
+ stack_trace=traceback.format_exc(),
185
+ ),
186
+ ),
187
+ )
188
+ )
189
+ ).decode()
190
+ )
191
+ raise error
192
+
193
+
194
+ def _parse_inputs_into_config_catalog_state(
195
+ args: list[str],
196
+ ) -> tuple[
197
+ Mapping[str, Any] | None,
198
+ ConfiguredAirbyteCatalog | None,
199
+ list[AirbyteStateMessage],
200
+ ]:
201
+ parsed_args = AirbyteEntrypoint.parse_args(args)
202
+ config = (
203
+ ConcurrentDeclarativeSource.read_config(parsed_args.config)
204
+ if hasattr(parsed_args, "config")
205
+ else None
206
+ )
207
+ catalog = (
208
+ ConcurrentDeclarativeSource.read_catalog(parsed_args.catalog)
209
+ if hasattr(parsed_args, "catalog")
210
+ else None
211
+ )
212
+ state = (
213
+ ConcurrentDeclarativeSource.read_state(parsed_args.state)
214
+ if hasattr(parsed_args, "state")
215
+ else []
216
+ )
217
+
218
+ return config, catalog, state
219
+
220
+
221
+ def run() -> None:
222
+ args: list[str] = sys.argv[1:]
223
+ handle_command(args)
@@ -0,0 +1,17 @@
1
+ {
2
+ "documentationUrl": "https://docs.airbyte.com/integrations/sources/low-code",
3
+ "connectionSpecification": {
4
+ "$schema": "http://json-schema.org/draft-07/schema#",
5
+ "title": "Low-code source spec",
6
+ "type": "object",
7
+ "required": ["__injected_declarative_manifest"],
8
+ "additionalProperties": true,
9
+ "properties": {
10
+ "__injected_declarative_manifest": {
11
+ "title": "Low-code manifest",
12
+ "type": "object",
13
+ "description": "The low-code manifest that defines the components of the source."
14
+ }
15
+ }
16
+ }
17
+ }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: airbyte-cdk
3
- Version: 6.6.3
3
+ Version: 6.6.4
4
4
  Summary: A framework for writing Airbyte Connectors.
5
5
  Home-page: https://airbyte.com
6
6
  License: MIT
@@ -37,7 +37,7 @@ Requires-Dist: fastavro (>=1.8.0,<1.9.0) ; extra == "file-based"
37
37
  Requires-Dist: genson (==1.3.0)
38
38
  Requires-Dist: isodate (>=0.6.1,<0.7.0)
39
39
  Requires-Dist: jsonref (>=0.2,<0.3)
40
- Requires-Dist: jsonschema (>=3.2.0,<3.3.0)
40
+ Requires-Dist: jsonschema (>=4.17.3,<4.18.0)
41
41
  Requires-Dist: langchain (==0.1.16) ; extra == "vector-db-based"
42
42
  Requires-Dist: langchain_core (==0.1.42)
43
43
  Requires-Dist: markdown ; extra == "file-based"
@@ -60,6 +60,7 @@ Requires-Dist: python-dateutil
60
60
  Requires-Dist: python-snappy (==0.7.3) ; extra == "file-based"
61
61
  Requires-Dist: python-ulid (>=3.0.0,<4.0.0)
62
62
  Requires-Dist: pytz (==2024.1)
63
+ Requires-Dist: rapidfuzz (>=3.10.1,<4.0.0)
63
64
  Requires-Dist: requests
64
65
  Requires-Dist: requests_cache
65
66
  Requires-Dist: serpyco-rs (>=1.10.2,<2.0.0)
@@ -1,4 +1,8 @@
1
1
  airbyte_cdk/__init__.py,sha256=3BlW1O37s_grUaioVZvGj3hRsofR0tY4sMceu5ygylk,11550
2
+ airbyte_cdk/cli/__init__.py,sha256=Hu-1XT2KDoYjDF7-_ziDwv5bY3PueGjANOCbzeOegDg,57
3
+ airbyte_cdk/cli/source_declarative_manifest/__init__.py,sha256=_zFyFFl4leAvtnkHmBFbtLYT6Bh44qxmLbU0wnK2TZQ,92
4
+ airbyte_cdk/cli/source_declarative_manifest/_run.py,sha256=3rIz-W65J6c2g3eMvvh2jk00cBBTiSgxx-MqA9WPUkw,7769
5
+ airbyte_cdk/cli/source_declarative_manifest/spec.json,sha256=Earc1L6ngcdIr514oFQlUoOxdF4RHqtUyStSIAquXdY,554
2
6
  airbyte_cdk/config_observation.py,sha256=A2P475pS9JndFzBggtkkAmcN1aMeq_thRbXRzmWjI3E,3997
3
7
  airbyte_cdk/connector.py,sha256=srfjRNgkt1nsPw-Mm0d1qXoVmM90zHPYHIfxu8p6JXI,4223
4
8
  airbyte_cdk/connector_builder/README.md,sha256=Hw3wvVewuHG9-QgsAq1jDiKuLlStDxKBz52ftyNRnBw,1665
@@ -327,7 +331,8 @@ airbyte_cdk/utils/slice_hasher.py,sha256=EemcgcQlI8-LPYOPlYv4Qkdjyho79XVLWaUHF5X
327
331
  airbyte_cdk/utils/spec_schema_transformations.py,sha256=LVc9KbtMeV_z99jWo0Ou8u4l6eBJ0BWNhxj4zrrGKRs,763
328
332
  airbyte_cdk/utils/stream_status_utils.py,sha256=ZmBoiy5HVbUEHAMrUONxZvxnvfV9CesmQJLDTAIWnWw,1171
329
333
  airbyte_cdk/utils/traced_exception.py,sha256=89TQdFuYZ1NJgmFpqLzY_T_T_64TpJYmVqs119Bp43g,6164
330
- airbyte_cdk-6.6.3.dist-info/LICENSE.txt,sha256=Wfe61S4BaGPj404v8lrAbvhjYR68SHlkzeYrg3_bbuM,1051
331
- airbyte_cdk-6.6.3.dist-info/METADATA,sha256=boO70XZVhxUW5jHT2ZpWGNIgLZ9qMaYo9o3oP5ShsrE,13297
332
- airbyte_cdk-6.6.3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
333
- airbyte_cdk-6.6.3.dist-info/RECORD,,
334
+ airbyte_cdk-6.6.4.dist-info/LICENSE.txt,sha256=Wfe61S4BaGPj404v8lrAbvhjYR68SHlkzeYrg3_bbuM,1051
335
+ airbyte_cdk-6.6.4.dist-info/METADATA,sha256=Sk-R3-F0P7mWRBhJdKVMazuklAft9hBEkzI_AznMiAw,13342
336
+ airbyte_cdk-6.6.4.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
337
+ airbyte_cdk-6.6.4.dist-info/entry_points.txt,sha256=fj-e3PAQvsxsQzyyq8UkG1k8spunWnD4BAH2AwlR6NM,95
338
+ airbyte_cdk-6.6.4.dist-info/RECORD,,
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ source-declarative-manifest=airbyte_cdk.cli.source_declarative_manifest:run
3
+