airbyte-cdk 0.0.0.dev0__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 (368) hide show
  1. airbyte_cdk/__init__.py +358 -0
  2. airbyte_cdk/cli/__init__.py +1 -0
  3. airbyte_cdk/cli/source_declarative_manifest/__init__.py +5 -0
  4. airbyte_cdk/cli/source_declarative_manifest/_run.py +236 -0
  5. airbyte_cdk/cli/source_declarative_manifest/spec.json +17 -0
  6. airbyte_cdk/config_observation.py +104 -0
  7. airbyte_cdk/connector.py +123 -0
  8. airbyte_cdk/connector_builder/README.md +53 -0
  9. airbyte_cdk/connector_builder/__init__.py +3 -0
  10. airbyte_cdk/connector_builder/connector_builder_handler.py +121 -0
  11. airbyte_cdk/connector_builder/main.py +107 -0
  12. airbyte_cdk/connector_builder/models.py +73 -0
  13. airbyte_cdk/connector_builder/test_reader/__init__.py +7 -0
  14. airbyte_cdk/connector_builder/test_reader/helpers.py +689 -0
  15. airbyte_cdk/connector_builder/test_reader/message_grouper.py +173 -0
  16. airbyte_cdk/connector_builder/test_reader/reader.py +441 -0
  17. airbyte_cdk/connector_builder/test_reader/types.py +83 -0
  18. airbyte_cdk/destinations/__init__.py +8 -0
  19. airbyte_cdk/destinations/destination.py +154 -0
  20. airbyte_cdk/destinations/vector_db_based/README.md +37 -0
  21. airbyte_cdk/destinations/vector_db_based/__init__.py +38 -0
  22. airbyte_cdk/destinations/vector_db_based/config.py +298 -0
  23. airbyte_cdk/destinations/vector_db_based/document_processor.py +223 -0
  24. airbyte_cdk/destinations/vector_db_based/embedder.py +303 -0
  25. airbyte_cdk/destinations/vector_db_based/indexer.py +78 -0
  26. airbyte_cdk/destinations/vector_db_based/test_utils.py +63 -0
  27. airbyte_cdk/destinations/vector_db_based/utils.py +35 -0
  28. airbyte_cdk/destinations/vector_db_based/writer.py +104 -0
  29. airbyte_cdk/entrypoint.py +414 -0
  30. airbyte_cdk/exception_handler.py +56 -0
  31. airbyte_cdk/logger.py +109 -0
  32. airbyte_cdk/models/__init__.py +72 -0
  33. airbyte_cdk/models/airbyte_protocol.py +88 -0
  34. airbyte_cdk/models/airbyte_protocol_serializers.py +44 -0
  35. airbyte_cdk/models/well_known_types.py +5 -0
  36. airbyte_cdk/py.typed +0 -0
  37. airbyte_cdk/sources/__init__.py +26 -0
  38. airbyte_cdk/sources/abstract_source.py +326 -0
  39. airbyte_cdk/sources/concurrent_source/__init__.py +8 -0
  40. airbyte_cdk/sources/concurrent_source/concurrent_read_processor.py +255 -0
  41. airbyte_cdk/sources/concurrent_source/concurrent_source.py +165 -0
  42. airbyte_cdk/sources/concurrent_source/concurrent_source_adapter.py +147 -0
  43. airbyte_cdk/sources/concurrent_source/partition_generation_completed_sentinel.py +24 -0
  44. airbyte_cdk/sources/concurrent_source/stream_thread_exception.py +25 -0
  45. airbyte_cdk/sources/concurrent_source/thread_pool_manager.py +115 -0
  46. airbyte_cdk/sources/config.py +27 -0
  47. airbyte_cdk/sources/connector_state_manager.py +161 -0
  48. airbyte_cdk/sources/declarative/__init__.py +3 -0
  49. airbyte_cdk/sources/declarative/async_job/__init__.py +0 -0
  50. airbyte_cdk/sources/declarative/async_job/job.py +52 -0
  51. airbyte_cdk/sources/declarative/async_job/job_orchestrator.py +525 -0
  52. airbyte_cdk/sources/declarative/async_job/job_tracker.py +79 -0
  53. airbyte_cdk/sources/declarative/async_job/repository.py +35 -0
  54. airbyte_cdk/sources/declarative/async_job/status.py +24 -0
  55. airbyte_cdk/sources/declarative/async_job/timer.py +39 -0
  56. airbyte_cdk/sources/declarative/auth/__init__.py +8 -0
  57. airbyte_cdk/sources/declarative/auth/declarative_authenticator.py +42 -0
  58. airbyte_cdk/sources/declarative/auth/jwt.py +197 -0
  59. airbyte_cdk/sources/declarative/auth/oauth.py +293 -0
  60. airbyte_cdk/sources/declarative/auth/selective_authenticator.py +45 -0
  61. airbyte_cdk/sources/declarative/auth/token.py +267 -0
  62. airbyte_cdk/sources/declarative/auth/token_provider.py +82 -0
  63. airbyte_cdk/sources/declarative/checks/__init__.py +24 -0
  64. airbyte_cdk/sources/declarative/checks/check_dynamic_stream.py +61 -0
  65. airbyte_cdk/sources/declarative/checks/check_stream.py +56 -0
  66. airbyte_cdk/sources/declarative/checks/connection_checker.py +35 -0
  67. airbyte_cdk/sources/declarative/concurrency_level/__init__.py +7 -0
  68. airbyte_cdk/sources/declarative/concurrency_level/concurrency_level.py +50 -0
  69. airbyte_cdk/sources/declarative/concurrent_declarative_source.py +526 -0
  70. airbyte_cdk/sources/declarative/datetime/__init__.py +3 -0
  71. airbyte_cdk/sources/declarative/datetime/datetime_parser.py +65 -0
  72. airbyte_cdk/sources/declarative/datetime/min_max_datetime.py +118 -0
  73. airbyte_cdk/sources/declarative/declarative_component_schema.yaml +3975 -0
  74. airbyte_cdk/sources/declarative/declarative_source.py +36 -0
  75. airbyte_cdk/sources/declarative/declarative_stream.py +241 -0
  76. airbyte_cdk/sources/declarative/decoders/__init__.py +33 -0
  77. airbyte_cdk/sources/declarative/decoders/composite_raw_decoder.py +218 -0
  78. airbyte_cdk/sources/declarative/decoders/decoder.py +32 -0
  79. airbyte_cdk/sources/declarative/decoders/decoder_parser.py +30 -0
  80. airbyte_cdk/sources/declarative/decoders/json_decoder.py +65 -0
  81. airbyte_cdk/sources/declarative/decoders/noop_decoder.py +21 -0
  82. airbyte_cdk/sources/declarative/decoders/pagination_decoder_decorator.py +39 -0
  83. airbyte_cdk/sources/declarative/decoders/xml_decoder.py +98 -0
  84. airbyte_cdk/sources/declarative/decoders/zipfile_decoder.py +56 -0
  85. airbyte_cdk/sources/declarative/exceptions.py +9 -0
  86. airbyte_cdk/sources/declarative/extractors/__init__.py +21 -0
  87. airbyte_cdk/sources/declarative/extractors/dpath_extractor.py +86 -0
  88. airbyte_cdk/sources/declarative/extractors/http_selector.py +37 -0
  89. airbyte_cdk/sources/declarative/extractors/record_extractor.py +27 -0
  90. airbyte_cdk/sources/declarative/extractors/record_filter.py +91 -0
  91. airbyte_cdk/sources/declarative/extractors/record_selector.py +170 -0
  92. airbyte_cdk/sources/declarative/extractors/response_to_file_extractor.py +176 -0
  93. airbyte_cdk/sources/declarative/extractors/type_transformer.py +55 -0
  94. airbyte_cdk/sources/declarative/incremental/__init__.py +37 -0
  95. airbyte_cdk/sources/declarative/incremental/concurrent_partition_cursor.py +497 -0
  96. airbyte_cdk/sources/declarative/incremental/datetime_based_cursor.py +459 -0
  97. airbyte_cdk/sources/declarative/incremental/declarative_cursor.py +13 -0
  98. airbyte_cdk/sources/declarative/incremental/global_substream_cursor.py +357 -0
  99. airbyte_cdk/sources/declarative/incremental/per_partition_cursor.py +380 -0
  100. airbyte_cdk/sources/declarative/incremental/per_partition_with_global.py +200 -0
  101. airbyte_cdk/sources/declarative/incremental/resumable_full_refresh_cursor.py +122 -0
  102. airbyte_cdk/sources/declarative/interpolation/__init__.py +9 -0
  103. airbyte_cdk/sources/declarative/interpolation/filters.py +139 -0
  104. airbyte_cdk/sources/declarative/interpolation/interpolated_boolean.py +66 -0
  105. airbyte_cdk/sources/declarative/interpolation/interpolated_mapping.py +56 -0
  106. airbyte_cdk/sources/declarative/interpolation/interpolated_nested_mapping.py +52 -0
  107. airbyte_cdk/sources/declarative/interpolation/interpolated_string.py +79 -0
  108. airbyte_cdk/sources/declarative/interpolation/interpolation.py +34 -0
  109. airbyte_cdk/sources/declarative/interpolation/jinja.py +161 -0
  110. airbyte_cdk/sources/declarative/interpolation/macros.py +191 -0
  111. airbyte_cdk/sources/declarative/manifest_declarative_source.py +421 -0
  112. airbyte_cdk/sources/declarative/migrations/__init__.py +0 -0
  113. airbyte_cdk/sources/declarative/migrations/legacy_to_per_partition_state_migration.py +98 -0
  114. airbyte_cdk/sources/declarative/migrations/state_migration.py +24 -0
  115. airbyte_cdk/sources/declarative/models/__init__.py +2 -0
  116. airbyte_cdk/sources/declarative/models/declarative_component_schema.py +2503 -0
  117. airbyte_cdk/sources/declarative/parsers/__init__.py +3 -0
  118. airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py +157 -0
  119. airbyte_cdk/sources/declarative/parsers/custom_exceptions.py +21 -0
  120. airbyte_cdk/sources/declarative/parsers/manifest_component_transformer.py +172 -0
  121. airbyte_cdk/sources/declarative/parsers/manifest_reference_resolver.py +213 -0
  122. airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py +3407 -0
  123. airbyte_cdk/sources/declarative/partition_routers/__init__.py +29 -0
  124. airbyte_cdk/sources/declarative/partition_routers/async_job_partition_router.py +65 -0
  125. airbyte_cdk/sources/declarative/partition_routers/cartesian_product_stream_slicer.py +176 -0
  126. airbyte_cdk/sources/declarative/partition_routers/list_partition_router.py +121 -0
  127. airbyte_cdk/sources/declarative/partition_routers/partition_router.py +62 -0
  128. airbyte_cdk/sources/declarative/partition_routers/single_partition_router.py +63 -0
  129. airbyte_cdk/sources/declarative/partition_routers/substream_partition_router.py +437 -0
  130. airbyte_cdk/sources/declarative/requesters/README.md +56 -0
  131. airbyte_cdk/sources/declarative/requesters/__init__.py +9 -0
  132. airbyte_cdk/sources/declarative/requesters/error_handlers/__init__.py +25 -0
  133. airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/__init__.py +23 -0
  134. airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/constant_backoff_strategy.py +45 -0
  135. airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/exponential_backoff_strategy.py +45 -0
  136. airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/header_helper.py +41 -0
  137. airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/wait_time_from_header_backoff_strategy.py +70 -0
  138. airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategies/wait_until_time_from_header_backoff_strategy.py +77 -0
  139. airbyte_cdk/sources/declarative/requesters/error_handlers/backoff_strategy.py +17 -0
  140. airbyte_cdk/sources/declarative/requesters/error_handlers/composite_error_handler.py +101 -0
  141. airbyte_cdk/sources/declarative/requesters/error_handlers/default_error_handler.py +147 -0
  142. airbyte_cdk/sources/declarative/requesters/error_handlers/default_http_response_filter.py +40 -0
  143. airbyte_cdk/sources/declarative/requesters/error_handlers/error_handler.py +17 -0
  144. airbyte_cdk/sources/declarative/requesters/error_handlers/http_response_filter.py +179 -0
  145. airbyte_cdk/sources/declarative/requesters/http_job_repository.py +350 -0
  146. airbyte_cdk/sources/declarative/requesters/http_requester.py +433 -0
  147. airbyte_cdk/sources/declarative/requesters/paginators/__init__.py +21 -0
  148. airbyte_cdk/sources/declarative/requesters/paginators/default_paginator.py +327 -0
  149. airbyte_cdk/sources/declarative/requesters/paginators/no_pagination.py +76 -0
  150. airbyte_cdk/sources/declarative/requesters/paginators/paginator.py +65 -0
  151. airbyte_cdk/sources/declarative/requesters/paginators/strategies/__init__.py +25 -0
  152. airbyte_cdk/sources/declarative/requesters/paginators/strategies/cursor_pagination_strategy.py +98 -0
  153. airbyte_cdk/sources/declarative/requesters/paginators/strategies/offset_increment.py +102 -0
  154. airbyte_cdk/sources/declarative/requesters/paginators/strategies/page_increment.py +71 -0
  155. airbyte_cdk/sources/declarative/requesters/paginators/strategies/pagination_strategy.py +48 -0
  156. airbyte_cdk/sources/declarative/requesters/paginators/strategies/stop_condition.py +66 -0
  157. airbyte_cdk/sources/declarative/requesters/request_option.py +117 -0
  158. airbyte_cdk/sources/declarative/requesters/request_options/__init__.py +23 -0
  159. airbyte_cdk/sources/declarative/requesters/request_options/datetime_based_request_options_provider.py +92 -0
  160. airbyte_cdk/sources/declarative/requesters/request_options/default_request_options_provider.py +60 -0
  161. airbyte_cdk/sources/declarative/requesters/request_options/interpolated_nested_request_input_provider.py +59 -0
  162. airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_input_provider.py +68 -0
  163. airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_options_provider.py +119 -0
  164. airbyte_cdk/sources/declarative/requesters/request_options/request_options_provider.py +79 -0
  165. airbyte_cdk/sources/declarative/requesters/request_path.py +15 -0
  166. airbyte_cdk/sources/declarative/requesters/requester.py +144 -0
  167. airbyte_cdk/sources/declarative/resolvers/__init__.py +41 -0
  168. airbyte_cdk/sources/declarative/resolvers/components_resolver.py +55 -0
  169. airbyte_cdk/sources/declarative/resolvers/config_components_resolver.py +136 -0
  170. airbyte_cdk/sources/declarative/resolvers/http_components_resolver.py +112 -0
  171. airbyte_cdk/sources/declarative/retrievers/__init__.py +19 -0
  172. airbyte_cdk/sources/declarative/retrievers/async_retriever.py +124 -0
  173. airbyte_cdk/sources/declarative/retrievers/file_uploader.py +89 -0
  174. airbyte_cdk/sources/declarative/retrievers/retriever.py +54 -0
  175. airbyte_cdk/sources/declarative/retrievers/simple_retriever.py +702 -0
  176. airbyte_cdk/sources/declarative/schema/__init__.py +25 -0
  177. airbyte_cdk/sources/declarative/schema/default_schema_loader.py +47 -0
  178. airbyte_cdk/sources/declarative/schema/dynamic_schema_loader.py +285 -0
  179. airbyte_cdk/sources/declarative/schema/inline_schema_loader.py +19 -0
  180. airbyte_cdk/sources/declarative/schema/json_file_schema_loader.py +92 -0
  181. airbyte_cdk/sources/declarative/schema/schema_loader.py +17 -0
  182. airbyte_cdk/sources/declarative/spec/__init__.py +7 -0
  183. airbyte_cdk/sources/declarative/spec/spec.py +48 -0
  184. airbyte_cdk/sources/declarative/stream_slicers/__init__.py +7 -0
  185. airbyte_cdk/sources/declarative/stream_slicers/declarative_partition_generator.py +93 -0
  186. airbyte_cdk/sources/declarative/stream_slicers/stream_slicer.py +25 -0
  187. airbyte_cdk/sources/declarative/transformations/__init__.py +17 -0
  188. airbyte_cdk/sources/declarative/transformations/add_fields.py +146 -0
  189. airbyte_cdk/sources/declarative/transformations/dpath_flatten_fields.py +61 -0
  190. airbyte_cdk/sources/declarative/transformations/flatten_fields.py +52 -0
  191. airbyte_cdk/sources/declarative/transformations/keys_replace_transformation.py +61 -0
  192. airbyte_cdk/sources/declarative/transformations/keys_to_lower_transformation.py +22 -0
  193. airbyte_cdk/sources/declarative/transformations/keys_to_snake_transformation.py +68 -0
  194. airbyte_cdk/sources/declarative/transformations/remove_fields.py +75 -0
  195. airbyte_cdk/sources/declarative/transformations/transformation.py +37 -0
  196. airbyte_cdk/sources/declarative/types.py +25 -0
  197. airbyte_cdk/sources/declarative/yaml_declarative_source.py +67 -0
  198. airbyte_cdk/sources/file_based/README.md +152 -0
  199. airbyte_cdk/sources/file_based/__init__.py +24 -0
  200. airbyte_cdk/sources/file_based/availability_strategy/__init__.py +11 -0
  201. airbyte_cdk/sources/file_based/availability_strategy/abstract_file_based_availability_strategy.py +73 -0
  202. airbyte_cdk/sources/file_based/availability_strategy/default_file_based_availability_strategy.py +149 -0
  203. airbyte_cdk/sources/file_based/config/__init__.py +0 -0
  204. airbyte_cdk/sources/file_based/config/abstract_file_based_spec.py +153 -0
  205. airbyte_cdk/sources/file_based/config/avro_format.py +25 -0
  206. airbyte_cdk/sources/file_based/config/csv_format.py +210 -0
  207. airbyte_cdk/sources/file_based/config/excel_format.py +18 -0
  208. airbyte_cdk/sources/file_based/config/file_based_stream_config.py +99 -0
  209. airbyte_cdk/sources/file_based/config/jsonl_format.py +18 -0
  210. airbyte_cdk/sources/file_based/config/parquet_format.py +25 -0
  211. airbyte_cdk/sources/file_based/config/unstructured_format.py +102 -0
  212. airbyte_cdk/sources/file_based/config/validate_config_transfer_modes.py +81 -0
  213. airbyte_cdk/sources/file_based/discovery_policy/__init__.py +8 -0
  214. airbyte_cdk/sources/file_based/discovery_policy/abstract_discovery_policy.py +21 -0
  215. airbyte_cdk/sources/file_based/discovery_policy/default_discovery_policy.py +33 -0
  216. airbyte_cdk/sources/file_based/exceptions.py +159 -0
  217. airbyte_cdk/sources/file_based/file_based_source.py +466 -0
  218. airbyte_cdk/sources/file_based/file_based_stream_permissions_reader.py +123 -0
  219. airbyte_cdk/sources/file_based/file_based_stream_reader.py +209 -0
  220. airbyte_cdk/sources/file_based/file_record_data.py +22 -0
  221. airbyte_cdk/sources/file_based/file_types/__init__.py +37 -0
  222. airbyte_cdk/sources/file_based/file_types/avro_parser.py +233 -0
  223. airbyte_cdk/sources/file_based/file_types/csv_parser.py +527 -0
  224. airbyte_cdk/sources/file_based/file_types/excel_parser.py +196 -0
  225. airbyte_cdk/sources/file_based/file_types/file_transfer.py +30 -0
  226. airbyte_cdk/sources/file_based/file_types/file_type_parser.py +86 -0
  227. airbyte_cdk/sources/file_based/file_types/jsonl_parser.py +145 -0
  228. airbyte_cdk/sources/file_based/file_types/parquet_parser.py +275 -0
  229. airbyte_cdk/sources/file_based/file_types/unstructured_parser.py +480 -0
  230. airbyte_cdk/sources/file_based/remote_file.py +18 -0
  231. airbyte_cdk/sources/file_based/schema_helpers.py +281 -0
  232. airbyte_cdk/sources/file_based/schema_validation_policies/__init__.py +17 -0
  233. airbyte_cdk/sources/file_based/schema_validation_policies/abstract_schema_validation_policy.py +20 -0
  234. airbyte_cdk/sources/file_based/schema_validation_policies/default_schema_validation_policies.py +52 -0
  235. airbyte_cdk/sources/file_based/stream/__init__.py +13 -0
  236. airbyte_cdk/sources/file_based/stream/abstract_file_based_stream.py +197 -0
  237. airbyte_cdk/sources/file_based/stream/concurrent/__init__.py +0 -0
  238. airbyte_cdk/sources/file_based/stream/concurrent/adapters.py +343 -0
  239. airbyte_cdk/sources/file_based/stream/concurrent/cursor/__init__.py +9 -0
  240. airbyte_cdk/sources/file_based/stream/concurrent/cursor/abstract_concurrent_file_based_cursor.py +59 -0
  241. airbyte_cdk/sources/file_based/stream/concurrent/cursor/file_based_concurrent_cursor.py +313 -0
  242. airbyte_cdk/sources/file_based/stream/concurrent/cursor/file_based_final_state_cursor.py +83 -0
  243. airbyte_cdk/sources/file_based/stream/cursor/__init__.py +4 -0
  244. airbyte_cdk/sources/file_based/stream/cursor/abstract_file_based_cursor.py +66 -0
  245. airbyte_cdk/sources/file_based/stream/cursor/default_file_based_cursor.py +149 -0
  246. airbyte_cdk/sources/file_based/stream/default_file_based_stream.py +396 -0
  247. airbyte_cdk/sources/file_based/stream/identities_stream.py +49 -0
  248. airbyte_cdk/sources/file_based/stream/permissions_file_based_stream.py +92 -0
  249. airbyte_cdk/sources/file_based/types.py +10 -0
  250. airbyte_cdk/sources/http_config.py +10 -0
  251. airbyte_cdk/sources/http_logger.py +55 -0
  252. airbyte_cdk/sources/message/__init__.py +19 -0
  253. airbyte_cdk/sources/message/repository.py +137 -0
  254. airbyte_cdk/sources/source.py +95 -0
  255. airbyte_cdk/sources/specs/transfer_modes.py +26 -0
  256. airbyte_cdk/sources/streams/__init__.py +8 -0
  257. airbyte_cdk/sources/streams/availability_strategy.py +84 -0
  258. airbyte_cdk/sources/streams/call_rate.py +704 -0
  259. airbyte_cdk/sources/streams/checkpoint/__init__.py +26 -0
  260. airbyte_cdk/sources/streams/checkpoint/checkpoint_reader.py +335 -0
  261. airbyte_cdk/sources/streams/checkpoint/cursor.py +77 -0
  262. airbyte_cdk/sources/streams/checkpoint/per_partition_key_serializer.py +22 -0
  263. airbyte_cdk/sources/streams/checkpoint/resumable_full_refresh_cursor.py +51 -0
  264. airbyte_cdk/sources/streams/checkpoint/substream_resumable_full_refresh_cursor.py +110 -0
  265. airbyte_cdk/sources/streams/concurrent/README.md +7 -0
  266. airbyte_cdk/sources/streams/concurrent/__init__.py +3 -0
  267. airbyte_cdk/sources/streams/concurrent/abstract_stream.py +96 -0
  268. airbyte_cdk/sources/streams/concurrent/abstract_stream_facade.py +37 -0
  269. airbyte_cdk/sources/streams/concurrent/adapters.py +397 -0
  270. airbyte_cdk/sources/streams/concurrent/availability_strategy.py +94 -0
  271. airbyte_cdk/sources/streams/concurrent/clamping.py +99 -0
  272. airbyte_cdk/sources/streams/concurrent/cursor.py +481 -0
  273. airbyte_cdk/sources/streams/concurrent/cursor_types.py +32 -0
  274. airbyte_cdk/sources/streams/concurrent/default_stream.py +102 -0
  275. airbyte_cdk/sources/streams/concurrent/exceptions.py +18 -0
  276. airbyte_cdk/sources/streams/concurrent/helpers.py +42 -0
  277. airbyte_cdk/sources/streams/concurrent/partition_enqueuer.py +64 -0
  278. airbyte_cdk/sources/streams/concurrent/partition_reader.py +45 -0
  279. airbyte_cdk/sources/streams/concurrent/partitions/__init__.py +3 -0
  280. airbyte_cdk/sources/streams/concurrent/partitions/partition.py +48 -0
  281. airbyte_cdk/sources/streams/concurrent/partitions/partition_generator.py +18 -0
  282. airbyte_cdk/sources/streams/concurrent/partitions/stream_slicer.py +21 -0
  283. airbyte_cdk/sources/streams/concurrent/partitions/types.py +38 -0
  284. airbyte_cdk/sources/streams/concurrent/state_converters/__init__.py +0 -0
  285. airbyte_cdk/sources/streams/concurrent/state_converters/abstract_stream_state_converter.py +182 -0
  286. airbyte_cdk/sources/streams/concurrent/state_converters/datetime_stream_state_converter.py +223 -0
  287. airbyte_cdk/sources/streams/concurrent/state_converters/incrementing_count_stream_state_converter.py +92 -0
  288. airbyte_cdk/sources/streams/core.py +703 -0
  289. airbyte_cdk/sources/streams/http/__init__.py +10 -0
  290. airbyte_cdk/sources/streams/http/availability_strategy.py +54 -0
  291. airbyte_cdk/sources/streams/http/error_handlers/__init__.py +22 -0
  292. airbyte_cdk/sources/streams/http/error_handlers/backoff_strategy.py +28 -0
  293. airbyte_cdk/sources/streams/http/error_handlers/default_backoff_strategy.py +17 -0
  294. airbyte_cdk/sources/streams/http/error_handlers/default_error_mapping.py +86 -0
  295. airbyte_cdk/sources/streams/http/error_handlers/error_handler.py +42 -0
  296. airbyte_cdk/sources/streams/http/error_handlers/error_message_parser.py +19 -0
  297. airbyte_cdk/sources/streams/http/error_handlers/http_status_error_handler.py +110 -0
  298. airbyte_cdk/sources/streams/http/error_handlers/json_error_message_parser.py +52 -0
  299. airbyte_cdk/sources/streams/http/error_handlers/response_models.py +65 -0
  300. airbyte_cdk/sources/streams/http/exceptions.py +61 -0
  301. airbyte_cdk/sources/streams/http/http.py +673 -0
  302. airbyte_cdk/sources/streams/http/http_client.py +531 -0
  303. airbyte_cdk/sources/streams/http/rate_limiting.py +158 -0
  304. airbyte_cdk/sources/streams/http/requests_native_auth/__init__.py +14 -0
  305. airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py +479 -0
  306. airbyte_cdk/sources/streams/http/requests_native_auth/abstract_token.py +34 -0
  307. airbyte_cdk/sources/streams/http/requests_native_auth/oauth.py +436 -0
  308. airbyte_cdk/sources/streams/http/requests_native_auth/token.py +83 -0
  309. airbyte_cdk/sources/streams/permissions/identities_stream.py +75 -0
  310. airbyte_cdk/sources/streams/utils/__init__.py +3 -0
  311. airbyte_cdk/sources/types.py +169 -0
  312. airbyte_cdk/sources/utils/__init__.py +7 -0
  313. airbyte_cdk/sources/utils/casing.py +12 -0
  314. airbyte_cdk/sources/utils/files_directory.py +15 -0
  315. airbyte_cdk/sources/utils/record_helper.py +53 -0
  316. airbyte_cdk/sources/utils/schema_helpers.py +230 -0
  317. airbyte_cdk/sources/utils/slice_logger.py +57 -0
  318. airbyte_cdk/sources/utils/transform.py +277 -0
  319. airbyte_cdk/sources/utils/types.py +7 -0
  320. airbyte_cdk/sql/__init__.py +0 -0
  321. airbyte_cdk/sql/_util/__init__.py +0 -0
  322. airbyte_cdk/sql/_util/hashing.py +34 -0
  323. airbyte_cdk/sql/_util/name_normalizers.py +92 -0
  324. airbyte_cdk/sql/constants.py +32 -0
  325. airbyte_cdk/sql/exceptions.py +235 -0
  326. airbyte_cdk/sql/secrets.py +123 -0
  327. airbyte_cdk/sql/shared/__init__.py +15 -0
  328. airbyte_cdk/sql/shared/catalog_providers.py +145 -0
  329. airbyte_cdk/sql/shared/sql_processor.py +786 -0
  330. airbyte_cdk/sql/types.py +160 -0
  331. airbyte_cdk/test/__init__.py +7 -0
  332. airbyte_cdk/test/catalog_builder.py +81 -0
  333. airbyte_cdk/test/entrypoint_wrapper.py +250 -0
  334. airbyte_cdk/test/mock_http/__init__.py +6 -0
  335. airbyte_cdk/test/mock_http/matcher.py +41 -0
  336. airbyte_cdk/test/mock_http/mocker.py +185 -0
  337. airbyte_cdk/test/mock_http/request.py +103 -0
  338. airbyte_cdk/test/mock_http/response.py +28 -0
  339. airbyte_cdk/test/mock_http/response_builder.py +237 -0
  340. airbyte_cdk/test/state_builder.py +33 -0
  341. airbyte_cdk/test/utils/__init__.py +1 -0
  342. airbyte_cdk/test/utils/data.py +24 -0
  343. airbyte_cdk/test/utils/http_mocking.py +16 -0
  344. airbyte_cdk/test/utils/manifest_only_fixtures.py +59 -0
  345. airbyte_cdk/test/utils/reading.py +26 -0
  346. airbyte_cdk/utils/__init__.py +10 -0
  347. airbyte_cdk/utils/airbyte_secrets_utils.py +80 -0
  348. airbyte_cdk/utils/analytics_message.py +25 -0
  349. airbyte_cdk/utils/constants.py +5 -0
  350. airbyte_cdk/utils/datetime_format_inferrer.py +94 -0
  351. airbyte_cdk/utils/datetime_helpers.py +499 -0
  352. airbyte_cdk/utils/event_timing.py +85 -0
  353. airbyte_cdk/utils/is_cloud_environment.py +18 -0
  354. airbyte_cdk/utils/mapping_helpers.py +162 -0
  355. airbyte_cdk/utils/message_utils.py +26 -0
  356. airbyte_cdk/utils/oneof_option_config.py +33 -0
  357. airbyte_cdk/utils/print_buffer.py +75 -0
  358. airbyte_cdk/utils/schema_inferrer.py +270 -0
  359. airbyte_cdk/utils/slice_hasher.py +37 -0
  360. airbyte_cdk/utils/spec_schema_transformations.py +26 -0
  361. airbyte_cdk/utils/stream_status_utils.py +43 -0
  362. airbyte_cdk/utils/traced_exception.py +145 -0
  363. airbyte_cdk-0.0.0.dev0.dist-info/LICENSE.txt +19 -0
  364. airbyte_cdk-0.0.0.dev0.dist-info/LICENSE_SHORT +1 -0
  365. airbyte_cdk-0.0.0.dev0.dist-info/METADATA +111 -0
  366. airbyte_cdk-0.0.0.dev0.dist-info/RECORD +368 -0
  367. airbyte_cdk-0.0.0.dev0.dist-info/WHEEL +4 -0
  368. airbyte_cdk-0.0.0.dev0.dist-info/entry_points.txt +3 -0
@@ -0,0 +1,358 @@
1
+ # Copyright (c) 2021 Airbyte, Inc., all rights reserved.
2
+ """
3
+ # Welcome to the Airbyte Python CDK!
4
+
5
+ The Airbyte Python CDK is a Python library that provides a set of tools to help you build
6
+ connectors for the Airbyte platform.
7
+
8
+ ## Building Source Connectors
9
+
10
+ To build a source connector, you will want to refer to
11
+ the following classes and modules:
12
+
13
+ - `airbyte_cdk.sources`
14
+ - `airbyte_cdk.sources.concurrent_source`
15
+ - `airbyte_cdk.sources.config`
16
+ - `airbyte_cdk.sources.file_based`
17
+ - `airbyte_cdk.sources.streams`
18
+
19
+ ## Building Destination Connectors
20
+
21
+ To build a destination connector, you will want to refer to
22
+ the following classes and modules:
23
+
24
+ - `airbyte_cdk.destinations`
25
+ - `airbyte_cdk.destinations.Destination`
26
+ - `airbyte_cdk.destinations.vector_db_based`
27
+
28
+ ## Working with Airbyte Protocol Models
29
+
30
+ The Airbyte CDK provides a set of classes that help you work with the Airbyte protocol models:
31
+
32
+ - `airbyte_cdk.models.airbyte_protocol`
33
+ - `airbyte_cdk.models.airbyte_protocol_serializers`
34
+
35
+ ---
36
+
37
+ API Reference
38
+
39
+ ---
40
+
41
+ """
42
+
43
+ # Warning: The below imports are not stable and will cause circular
44
+ # dependencies if auto-sorted with isort. Please keep them in the same order.
45
+ # TODO: Submodules should import from lower-level modules, rather than importing from here.
46
+ # Imports should also be placed in `if TYPE_CHECKING` blocks if they are only used as type
47
+ # hints - again, to avoid circular dependencies.
48
+ # Once those issues are resolved, the below can be sorted with isort.
49
+ import dunamai as _dunamai
50
+
51
+ from .config_observation import (
52
+ create_connector_config_control_message,
53
+ emit_configuration_as_airbyte_control_message,
54
+ )
55
+ from .connector import BaseConnector, Connector
56
+ from .destinations import Destination
57
+ from .entrypoint import AirbyteEntrypoint, launch
58
+ from .logger import AirbyteLogFormatter, init_logger
59
+ from .models import (
60
+ AdvancedAuth,
61
+ AirbyteConnectionStatus,
62
+ AirbyteLogMessage,
63
+ AirbyteMessage,
64
+ AirbyteRecordMessage,
65
+ AirbyteStream,
66
+ ConfiguredAirbyteCatalog,
67
+ ConfiguredAirbyteStream,
68
+ ConnectorSpecification,
69
+ DestinationSyncMode,
70
+ FailureType,
71
+ Level,
72
+ OAuthConfigSpecification,
73
+ OrchestratorType,
74
+ Status,
75
+ SyncMode,
76
+ Type,
77
+ )
78
+ from .sources import AbstractSource, Source
79
+ from .sources.concurrent_source.concurrent_source import ConcurrentSource
80
+ from .sources.concurrent_source.concurrent_source_adapter import ConcurrentSourceAdapter
81
+ from .sources.config import BaseConfig
82
+ from .sources.connector_state_manager import ConnectorStateManager
83
+ from .sources.declarative.auth import DeclarativeOauth2Authenticator
84
+ from .sources.declarative.auth.declarative_authenticator import DeclarativeAuthenticator, NoAuth
85
+ from .sources.declarative.auth.oauth import DeclarativeSingleUseRefreshTokenOauth2Authenticator
86
+ from .sources.declarative.auth.token import (
87
+ ApiKeyAuthenticator,
88
+ BasicHttpAuthenticator,
89
+ BearerAuthenticator,
90
+ )
91
+ from .sources.declarative.datetime.min_max_datetime import MinMaxDatetime
92
+ from .sources.declarative.declarative_stream import DeclarativeStream
93
+ from .sources.declarative.decoders import Decoder, JsonDecoder
94
+ from .sources.declarative.exceptions import ReadException
95
+ from .sources.declarative.extractors import DpathExtractor, RecordSelector
96
+ from .sources.declarative.extractors.record_extractor import RecordExtractor
97
+ from .sources.declarative.extractors.record_filter import RecordFilter
98
+ from .sources.declarative.incremental import DatetimeBasedCursor
99
+ from .sources.declarative.interpolation import InterpolatedBoolean, InterpolatedString
100
+ from .sources.declarative.manifest_declarative_source import ManifestDeclarativeSource
101
+ from .sources.declarative.migrations.legacy_to_per_partition_state_migration import (
102
+ LegacyToPerPartitionStateMigration,
103
+ )
104
+ from .sources.declarative.partition_routers import (
105
+ CartesianProductStreamSlicer,
106
+ SinglePartitionRouter,
107
+ SubstreamPartitionRouter,
108
+ )
109
+ from .sources.declarative.partition_routers.substream_partition_router import ParentStreamConfig
110
+ from .sources.declarative.requesters import HttpRequester, Requester
111
+ from .sources.declarative.requesters.error_handlers import BackoffStrategy
112
+ from .sources.declarative.requesters.paginators import DefaultPaginator, PaginationStrategy
113
+ from .sources.declarative.requesters.paginators.strategies import (
114
+ CursorPaginationStrategy,
115
+ OffsetIncrement,
116
+ PageIncrement,
117
+ StopConditionPaginationStrategyDecorator,
118
+ )
119
+ from .sources.declarative.requesters.request_option import RequestOption, RequestOptionType
120
+ from .sources.declarative.requesters.request_options.default_request_options_provider import (
121
+ DefaultRequestOptionsProvider,
122
+ )
123
+ from .sources.declarative.requesters.request_options.interpolated_request_input_provider import (
124
+ InterpolatedRequestInputProvider,
125
+ )
126
+ from .sources.declarative.requesters.requester import HttpMethod
127
+ from .sources.declarative.retrievers import SimpleRetriever
128
+ from .sources.declarative.schema import JsonFileSchemaLoader
129
+ from .sources.declarative.transformations.add_fields import AddedFieldDefinition, AddFields
130
+ from .sources.declarative.transformations.transformation import RecordTransformation
131
+ from .sources.declarative.types import FieldPointer
132
+ from .sources.declarative.yaml_declarative_source import YamlDeclarativeSource
133
+ from .sources.message import InMemoryMessageRepository, MessageRepository
134
+ from .sources.source import TState
135
+ from .sources.streams.availability_strategy import AvailabilityStrategy
136
+ from .sources.streams.call_rate import (
137
+ AbstractAPIBudget,
138
+ CachedLimiterSession,
139
+ HttpAPIBudget,
140
+ HttpRequestMatcher,
141
+ LimiterSession,
142
+ MovingWindowCallRatePolicy,
143
+ Rate,
144
+ )
145
+ from .sources.streams.checkpoint import Cursor as LegacyCursor
146
+ from .sources.streams.checkpoint import ResumableFullRefreshCursor
147
+ from .sources.streams.concurrent.adapters import StreamFacade
148
+ from .sources.streams.concurrent.cursor import (
149
+ ConcurrentCursor,
150
+ Cursor,
151
+ CursorField,
152
+ FinalStateCursor,
153
+ )
154
+ from .sources.streams.concurrent.state_converters.datetime_stream_state_converter import (
155
+ EpochValueConcurrentStreamStateConverter,
156
+ IsoMillisConcurrentStreamStateConverter,
157
+ )
158
+ from .sources.streams.core import IncrementalMixin, Stream, package_name_from_class
159
+ from .sources.streams.http import HttpStream, HttpSubStream
160
+ from .sources.streams.http.availability_strategy import HttpAvailabilityStrategy
161
+ from .sources.streams.http.exceptions import (
162
+ BaseBackoffException,
163
+ DefaultBackoffException,
164
+ UserDefinedBackoffException,
165
+ )
166
+ from .sources.streams.http.rate_limiting import default_backoff_handler
167
+ from .sources.streams.http.requests_native_auth import (
168
+ Oauth2Authenticator,
169
+ SingleUseRefreshTokenOauth2Authenticator,
170
+ TokenAuthenticator,
171
+ )
172
+ from .sources.streams.http.requests_native_auth.abstract_token import AbstractHeaderAuthenticator
173
+ from .sources.types import Config, Record, StreamSlice
174
+ from .sources.utils import casing
175
+ from .sources.utils.schema_helpers import (
176
+ InternalConfig,
177
+ ResourceSchemaLoader,
178
+ check_config_against_spec_or_exit,
179
+ expand_refs,
180
+ split_config,
181
+ )
182
+ from .sources.utils.transform import TransformConfig, TypeTransformer
183
+ from .utils import AirbyteTracedException, is_cloud_environment
184
+ from .utils.constants import ENV_REQUEST_CACHE_PATH
185
+ from .utils.event_timing import create_timer
186
+ from .utils.oneof_option_config import OneOfOptionConfig
187
+ from .utils.spec_schema_transformations import resolve_refs
188
+ from .utils.stream_status_utils import as_airbyte_message
189
+
190
+ __all__ = [
191
+ # Availability strategy
192
+ "AvailabilityStrategy",
193
+ "HttpAvailabilityStrategy",
194
+ # Checkpoint
195
+ "LegacyCursor",
196
+ "ResumableFullRefreshCursor",
197
+ # Concurrent
198
+ "ConcurrentCursor",
199
+ "ConcurrentSource",
200
+ "ConcurrentSourceAdapter",
201
+ "Cursor",
202
+ "CursorField",
203
+ "DEFAULT_CONCURRENCY",
204
+ "EpochValueConcurrentStreamStateConverter",
205
+ "FinalStateCursor",
206
+ "IsoMillisConcurrentStreamStateConverter",
207
+ "StreamFacade",
208
+ # Config observation
209
+ "create_connector_config_control_message",
210
+ "emit_configuration_as_airbyte_control_message",
211
+ # Connector
212
+ "AbstractSource",
213
+ "BaseConfig",
214
+ "BaseConnector",
215
+ "Connector",
216
+ "Destination",
217
+ "Source",
218
+ "TState",
219
+ # Declarative
220
+ "AddFields",
221
+ "AddedFieldDefinition",
222
+ "ApiKeyAuthenticator",
223
+ "BackoffStrategy",
224
+ "BasicHttpAuthenticator",
225
+ "BearerAuthenticator",
226
+ "CartesianProductStreamSlicer",
227
+ "CursorPaginationStrategy",
228
+ "DatetimeBasedCursor",
229
+ "DeclarativeAuthenticator",
230
+ "DeclarativeOauth2Authenticator",
231
+ "DeclarativeSingleUseRefreshTokenOauth2Authenticator",
232
+ "DeclarativeStream",
233
+ "Decoder",
234
+ "DefaultPaginator",
235
+ "DefaultRequestOptionsProvider",
236
+ "DpathExtractor",
237
+ "FieldPointer",
238
+ "HttpMethod",
239
+ "HttpRequester",
240
+ "InterpolatedBoolean",
241
+ "InterpolatedRequestInputProvider",
242
+ "InterpolatedString",
243
+ "JsonDecoder",
244
+ "JsonFileSchemaLoader",
245
+ "LegacyToPerPartitionStateMigration",
246
+ "ManifestDeclarativeSource",
247
+ "MinMaxDatetime",
248
+ "NoAuth",
249
+ "OffsetIncrement",
250
+ "PageIncrement",
251
+ "PaginationStrategy",
252
+ "ParentStreamConfig",
253
+ "ReadException",
254
+ "RecordExtractor",
255
+ "RecordFilter",
256
+ "RecordSelector",
257
+ "RecordTransformation",
258
+ "RequestOption",
259
+ "RequestOptionType",
260
+ "Requester",
261
+ "ResponseStatus",
262
+ "SimpleRetriever",
263
+ "SinglePartitionRouter",
264
+ "StopConditionPaginationStrategyDecorator",
265
+ "StreamSlice",
266
+ "SubstreamPartitionRouter",
267
+ "YamlDeclarativeSource",
268
+ # Entrypoint
269
+ "launch",
270
+ "AirbyteEntrypoint",
271
+ # HTTP
272
+ "AbstractAPIBudget",
273
+ "AbstractHeaderAuthenticator",
274
+ "BaseBackoffException",
275
+ "CachedLimiterSession",
276
+ "DefaultBackoffException",
277
+ "default_backoff_handler",
278
+ "HttpAPIBudget",
279
+ "HttpAuthenticator",
280
+ "HttpRequestMatcher",
281
+ "HttpStream",
282
+ "HttpSubStream",
283
+ "LimiterSession",
284
+ "MovingWindowCallRatePolicy",
285
+ "MultipleTokenAuthenticator",
286
+ "Oauth2Authenticator",
287
+ "Rate",
288
+ "SingleUseRefreshTokenOauth2Authenticator",
289
+ "TokenAuthenticator",
290
+ "UserDefinedBackoffException",
291
+ # Logger
292
+ "AirbyteLogFormatter",
293
+ "init_logger",
294
+ # Protocol classes
295
+ "AirbyteStream",
296
+ "AirbyteConnectionStatus",
297
+ "AirbyteMessage",
298
+ "ConfiguredAirbyteCatalog",
299
+ "Status",
300
+ "Type",
301
+ "OrchestratorType",
302
+ "ConfiguredAirbyteStream",
303
+ "DestinationSyncMode",
304
+ "SyncMode",
305
+ "FailureType",
306
+ "AdvancedAuth",
307
+ "AirbyteLogMessage",
308
+ "OAuthConfigSpecification",
309
+ "ConnectorSpecification",
310
+ "Level",
311
+ "AirbyteRecordMessage",
312
+ # Repository
313
+ "InMemoryMessageRepository",
314
+ "MessageRepository",
315
+ # State management
316
+ "ConnectorStateManager",
317
+ # Stream
318
+ "IncrementalMixin",
319
+ "Stream",
320
+ "StreamData",
321
+ "package_name_from_class",
322
+ # Utils
323
+ "AirbyteTracedException",
324
+ "is_cloud_environment",
325
+ "casing",
326
+ "InternalConfig",
327
+ "ResourceSchemaLoader",
328
+ "check_config_against_spec_or_exit",
329
+ "split_config",
330
+ "TransformConfig",
331
+ "TypeTransformer",
332
+ "ENV_REQUEST_CACHE_PATH",
333
+ "create_timer",
334
+ "OneOfOptionConfig",
335
+ "resolve_refs",
336
+ "as_airbyte_message",
337
+ # Types
338
+ "Config",
339
+ "Record",
340
+ "Source",
341
+ "StreamSlice",
342
+ ]
343
+
344
+ __version__: str
345
+ """Version generated by poetry dynamic versioning during publish.
346
+
347
+ When running in development, dunamai will calculate a new prerelease version
348
+ from existing git release tag info.
349
+ """
350
+
351
+ try:
352
+ __version__ = _dunamai.get_version(
353
+ "airbyte-cdk",
354
+ third_choice=_dunamai.Version.from_any_vcs,
355
+ fallback=_dunamai.Version("0.0.0+dev"),
356
+ ).serialize()
357
+ except:
358
+ __version__ = "0.0.0+dev"
@@ -0,0 +1 @@
1
+ # Copyright (c) 2024 Airbyte, Inc., all rights reserved.
@@ -0,0 +1,5 @@
1
+ from airbyte_cdk.cli.source_declarative_manifest._run import run
2
+
3
+ __all__ = [
4
+ "run",
5
+ ]
@@ -0,0 +1,236 @@
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 pathlib import Path
25
+ from typing import Any, cast
26
+
27
+ import orjson
28
+
29
+ from airbyte_cdk.entrypoint import AirbyteEntrypoint, launch
30
+ from airbyte_cdk.models import (
31
+ AirbyteErrorTraceMessage,
32
+ AirbyteMessage,
33
+ AirbyteMessageSerializer,
34
+ AirbyteStateMessage,
35
+ AirbyteTraceMessage,
36
+ ConfiguredAirbyteCatalog,
37
+ ConnectorSpecificationSerializer,
38
+ TraceType,
39
+ Type,
40
+ )
41
+ from airbyte_cdk.sources.declarative.concurrent_declarative_source import (
42
+ ConcurrentDeclarativeSource,
43
+ )
44
+ from airbyte_cdk.sources.declarative.yaml_declarative_source import YamlDeclarativeSource
45
+ from airbyte_cdk.sources.source import TState
46
+ from airbyte_cdk.utils.datetime_helpers import ab_datetime_now
47
+
48
+
49
+ class SourceLocalYaml(YamlDeclarativeSource):
50
+ """
51
+ Declarative source defined by a yaml file in the local filesystem
52
+ """
53
+
54
+ def __init__(
55
+ self,
56
+ catalog: ConfiguredAirbyteCatalog | None,
57
+ config: Mapping[str, Any] | None,
58
+ state: TState,
59
+ **kwargs: Any,
60
+ ) -> None:
61
+ """
62
+ HACK!
63
+ Problem: YamlDeclarativeSource relies on the calling module name/path to find the yaml file.
64
+ Implication: If you call YamlDeclarativeSource directly it will look for the yaml file in the wrong place. (e.g. the airbyte-cdk package)
65
+ Solution: Subclass YamlDeclarativeSource from the same location as the manifest to load.
66
+
67
+ When can we remove this?
68
+ When the airbyte-cdk is updated to not rely on the calling module name/path to find the yaml file.
69
+ When all manifest connectors are updated to use the new airbyte-cdk.
70
+ When all manifest connectors are updated to use the source-declarative-manifest as the base image.
71
+ """
72
+ super().__init__(
73
+ catalog=catalog,
74
+ config=config,
75
+ state=state, # type: ignore [arg-type]
76
+ path_to_yaml="manifest.yaml",
77
+ )
78
+
79
+
80
+ def _is_local_manifest_command(args: list[str]) -> bool:
81
+ # Check for a local manifest.yaml file
82
+ return Path("/airbyte/integration_code/source_declarative_manifest/manifest.yaml").exists()
83
+
84
+
85
+ def handle_command(args: list[str]) -> None:
86
+ if _is_local_manifest_command(args):
87
+ handle_local_manifest_command(args)
88
+ else:
89
+ handle_remote_manifest_command(args)
90
+
91
+
92
+ def _get_local_yaml_source(args: list[str]) -> SourceLocalYaml:
93
+ try:
94
+ config, catalog, state = _parse_inputs_into_config_catalog_state(args)
95
+ return SourceLocalYaml(config=config, catalog=catalog, state=state)
96
+ except Exception as error:
97
+ print(
98
+ orjson.dumps(
99
+ AirbyteMessageSerializer.dump(
100
+ AirbyteMessage(
101
+ type=Type.TRACE,
102
+ trace=AirbyteTraceMessage(
103
+ type=TraceType.ERROR,
104
+ emitted_at=ab_datetime_now().to_epoch_millis(),
105
+ error=AirbyteErrorTraceMessage(
106
+ message=f"Error starting the sync. This could be due to an invalid configuration or catalog. Please contact Support for assistance. Error: {error}",
107
+ stack_trace=traceback.format_exc(),
108
+ ),
109
+ ),
110
+ )
111
+ )
112
+ ).decode()
113
+ )
114
+ raise error
115
+
116
+
117
+ def handle_local_manifest_command(args: list[str]) -> None:
118
+ source = _get_local_yaml_source(args)
119
+ launch(
120
+ source=source,
121
+ args=args,
122
+ )
123
+
124
+
125
+ def handle_remote_manifest_command(args: list[str]) -> None:
126
+ """Overrides the spec command to return the generalized spec for the declarative manifest source.
127
+
128
+ This is different from a typical low-code, but built and published separately source built as a ManifestDeclarativeSource,
129
+ because that will have a spec method that returns the spec for that specific source. Other than spec,
130
+ the generalized connector behaves the same as any other, since the manifest is provided in the config.
131
+ """
132
+ if args[0] == "spec":
133
+ json_spec = pkgutil.get_data(
134
+ "airbyte_cdk.cli.source_declarative_manifest",
135
+ "spec.json",
136
+ )
137
+ if json_spec is None:
138
+ raise FileNotFoundError(
139
+ "Could not find `spec.json` file for source-declarative-manifest"
140
+ )
141
+
142
+ spec_obj = json.loads(json_spec)
143
+ spec = ConnectorSpecificationSerializer.load(spec_obj)
144
+
145
+ message = AirbyteMessage(type=Type.SPEC, spec=spec)
146
+ print(AirbyteEntrypoint.airbyte_message_to_string(message))
147
+ else:
148
+ source = create_declarative_source(args)
149
+ launch(
150
+ source=source,
151
+ args=args,
152
+ )
153
+
154
+
155
+ def create_declarative_source(
156
+ args: list[str],
157
+ ) -> ConcurrentDeclarativeSource: # type: ignore [type-arg]
158
+ """Creates the source with the injected config.
159
+
160
+ This essentially does what other low-code sources do at build time, but at runtime,
161
+ with a user-provided manifest in the config. This better reflects what happens in the
162
+ connector builder.
163
+ """
164
+ try:
165
+ config: Mapping[str, Any] | None
166
+ catalog: ConfiguredAirbyteCatalog | None
167
+ state: list[AirbyteStateMessage]
168
+ config, catalog, state = _parse_inputs_into_config_catalog_state(args)
169
+ if config is None or "__injected_declarative_manifest" not in config:
170
+ raise ValueError(
171
+ "Invalid config: `__injected_declarative_manifest` should be provided at the root "
172
+ f"of the config but config only has keys: {list(config.keys() if config else [])}"
173
+ )
174
+ if not isinstance(config["__injected_declarative_manifest"], dict):
175
+ raise ValueError(
176
+ "Invalid config: `__injected_declarative_manifest` should be a dictionary, "
177
+ f"but got type: {type(config['__injected_declarative_manifest'])}"
178
+ )
179
+
180
+ return ConcurrentDeclarativeSource(
181
+ config=config,
182
+ catalog=catalog,
183
+ state=state,
184
+ source_config=cast(dict[str, Any], config["__injected_declarative_manifest"]),
185
+ )
186
+ except Exception as error:
187
+ print(
188
+ orjson.dumps(
189
+ AirbyteMessageSerializer.dump(
190
+ AirbyteMessage(
191
+ type=Type.TRACE,
192
+ trace=AirbyteTraceMessage(
193
+ type=TraceType.ERROR,
194
+ emitted_at=ab_datetime_now().to_epoch_millis(),
195
+ error=AirbyteErrorTraceMessage(
196
+ message=f"Error starting the sync. This could be due to an invalid configuration or catalog. Please contact Support for assistance. Error: {error}",
197
+ stack_trace=traceback.format_exc(),
198
+ ),
199
+ ),
200
+ )
201
+ )
202
+ ).decode()
203
+ )
204
+ raise error
205
+
206
+
207
+ def _parse_inputs_into_config_catalog_state(
208
+ args: list[str],
209
+ ) -> tuple[
210
+ Mapping[str, Any] | None,
211
+ ConfiguredAirbyteCatalog | None,
212
+ list[AirbyteStateMessage],
213
+ ]:
214
+ parsed_args = AirbyteEntrypoint.parse_args(args)
215
+ config = (
216
+ ConcurrentDeclarativeSource.read_config(parsed_args.config)
217
+ if hasattr(parsed_args, "config")
218
+ else None
219
+ )
220
+ catalog = (
221
+ ConcurrentDeclarativeSource.read_catalog(parsed_args.catalog)
222
+ if hasattr(parsed_args, "catalog")
223
+ else None
224
+ )
225
+ state = (
226
+ ConcurrentDeclarativeSource.read_state(parsed_args.state)
227
+ if hasattr(parsed_args, "state")
228
+ else []
229
+ )
230
+
231
+ return config, catalog, state
232
+
233
+
234
+ def run() -> None:
235
+ args: list[str] = sys.argv[1:]
236
+ 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
+ }