airbyte-cdk 6.33.2.dev0__py3-none-any.whl → 6.33.3__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.
- airbyte_cdk/sources/declarative/auth/oauth.py +6 -1
- airbyte_cdk/sources/declarative/concurrent_declarative_source.py +15 -1
- airbyte_cdk/sources/declarative/declarative_component_schema.yaml +23 -288
- airbyte_cdk/sources/declarative/decoders/__init__.py +0 -4
- airbyte_cdk/sources/declarative/decoders/composite_raw_decoder.py +7 -2
- airbyte_cdk/sources/declarative/decoders/json_decoder.py +12 -58
- airbyte_cdk/sources/declarative/incremental/concurrent_partition_cursor.py +6 -11
- airbyte_cdk/sources/declarative/manifest_declarative_source.py +0 -4
- airbyte_cdk/sources/declarative/models/declarative_component_schema.py +14 -202
- airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py +53 -196
- airbyte_cdk/sources/declarative/requesters/http_requester.py +0 -3
- airbyte_cdk/sources/streams/call_rate.py +40 -116
- airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py +3 -0
- {airbyte_cdk-6.33.2.dev0.dist-info → airbyte_cdk-6.33.3.dist-info}/METADATA +1 -1
- {airbyte_cdk-6.33.2.dev0.dist-info → airbyte_cdk-6.33.3.dist-info}/RECORD +19 -19
- {airbyte_cdk-6.33.2.dev0.dist-info → airbyte_cdk-6.33.3.dist-info}/LICENSE.txt +0 -0
- {airbyte_cdk-6.33.2.dev0.dist-info → airbyte_cdk-6.33.3.dist-info}/LICENSE_SHORT +0 -0
- {airbyte_cdk-6.33.2.dev0.dist-info → airbyte_cdk-6.33.3.dist-info}/WHEEL +0 -0
- {airbyte_cdk-6.33.2.dev0.dist-info → airbyte_cdk-6.33.3.dist-info}/entry_points.txt +0 -0
@@ -60,10 +60,8 @@ from airbyte_cdk.sources.declarative.datetime import MinMaxDatetime
|
|
60
60
|
from airbyte_cdk.sources.declarative.declarative_stream import DeclarativeStream
|
61
61
|
from airbyte_cdk.sources.declarative.decoders import (
|
62
62
|
Decoder,
|
63
|
-
GzipJsonDecoder,
|
64
63
|
IterableDecoder,
|
65
64
|
JsonDecoder,
|
66
|
-
JsonlDecoder,
|
67
65
|
PaginationDecoderDecorator,
|
68
66
|
XmlDecoder,
|
69
67
|
ZipfileDecoder,
|
@@ -103,8 +101,8 @@ from airbyte_cdk.sources.declarative.migrations.legacy_to_per_partition_state_mi
|
|
103
101
|
LegacyToPerPartitionStateMigration,
|
104
102
|
)
|
105
103
|
from airbyte_cdk.sources.declarative.models import (
|
106
|
-
Clamping,
|
107
104
|
CustomStateMigration,
|
105
|
+
GzipDecoder,
|
108
106
|
)
|
109
107
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
110
108
|
AddedFieldDefinition as AddedFieldDefinitionModel,
|
@@ -112,9 +110,6 @@ from airbyte_cdk.sources.declarative.models.declarative_component_schema import
|
|
112
110
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
113
111
|
AddFields as AddFieldsModel,
|
114
112
|
)
|
115
|
-
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
116
|
-
APIBudget as APIBudgetModel,
|
117
|
-
)
|
118
113
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
119
114
|
ApiKeyAuthenticator as ApiKeyAuthenticatorModel,
|
120
115
|
)
|
@@ -145,9 +140,6 @@ from airbyte_cdk.sources.declarative.models.declarative_component_schema import
|
|
145
140
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
146
141
|
CompositeErrorHandler as CompositeErrorHandlerModel,
|
147
142
|
)
|
148
|
-
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
149
|
-
CompositeRawDecoder as CompositeRawDecoderModel,
|
150
|
-
)
|
151
143
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
152
144
|
ConcurrencyLevel as ConcurrencyLevelModel,
|
153
145
|
)
|
@@ -158,7 +150,7 @@ from airbyte_cdk.sources.declarative.models.declarative_component_schema import
|
|
158
150
|
ConstantBackoffStrategy as ConstantBackoffStrategyModel,
|
159
151
|
)
|
160
152
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
161
|
-
|
153
|
+
CsvDecoder as CsvDecoderModel,
|
162
154
|
)
|
163
155
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
164
156
|
CursorPagination as CursorPaginationModel,
|
@@ -229,20 +221,11 @@ from airbyte_cdk.sources.declarative.models.declarative_component_schema import
|
|
229
221
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
230
222
|
ExponentialBackoffStrategy as ExponentialBackoffStrategyModel,
|
231
223
|
)
|
232
|
-
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
233
|
-
FixedWindowCallRatePolicy as FixedWindowCallRatePolicyModel,
|
234
|
-
)
|
235
224
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
236
225
|
FlattenFields as FlattenFieldsModel,
|
237
226
|
)
|
238
227
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
239
|
-
|
240
|
-
)
|
241
|
-
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
242
|
-
GzipParser as GzipParserModel,
|
243
|
-
)
|
244
|
-
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
245
|
-
HTTPAPIBudget as HTTPAPIBudgetModel,
|
228
|
+
GzipDecoder as GzipDecoderModel,
|
246
229
|
)
|
247
230
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
248
231
|
HttpComponentsResolver as HttpComponentsResolverModel,
|
@@ -250,9 +233,6 @@ from airbyte_cdk.sources.declarative.models.declarative_component_schema import
|
|
250
233
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
251
234
|
HttpRequester as HttpRequesterModel,
|
252
235
|
)
|
253
|
-
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
254
|
-
HttpRequestRegexMatcher as HttpRequestRegexMatcherModel,
|
255
|
-
)
|
256
236
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
257
237
|
HttpResponseFilter as HttpResponseFilterModel,
|
258
238
|
)
|
@@ -271,12 +251,6 @@ from airbyte_cdk.sources.declarative.models.declarative_component_schema import
|
|
271
251
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
272
252
|
JsonlDecoder as JsonlDecoderModel,
|
273
253
|
)
|
274
|
-
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
275
|
-
JsonLineParser as JsonLineParserModel,
|
276
|
-
)
|
277
|
-
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
278
|
-
JsonParser as JsonParserModel,
|
279
|
-
)
|
280
254
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
281
255
|
JwtAuthenticator as JwtAuthenticatorModel,
|
282
256
|
)
|
@@ -307,9 +281,6 @@ from airbyte_cdk.sources.declarative.models.declarative_component_schema import
|
|
307
281
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
308
282
|
MinMaxDatetime as MinMaxDatetimeModel,
|
309
283
|
)
|
310
|
-
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
311
|
-
MovingWindowCallRatePolicy as MovingWindowCallRatePolicyModel,
|
312
|
-
)
|
313
284
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
314
285
|
NoAuth as NoAuthModel,
|
315
286
|
)
|
@@ -328,9 +299,6 @@ from airbyte_cdk.sources.declarative.models.declarative_component_schema import
|
|
328
299
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
329
300
|
ParentStreamConfig as ParentStreamConfigModel,
|
330
301
|
)
|
331
|
-
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
332
|
-
Rate as RateModel,
|
333
|
-
)
|
334
302
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
335
303
|
RecordFilter as RecordFilterModel,
|
336
304
|
)
|
@@ -374,9 +342,6 @@ from airbyte_cdk.sources.declarative.models.declarative_component_schema import
|
|
374
342
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
375
343
|
TypesMap as TypesMapModel,
|
376
344
|
)
|
377
|
-
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
378
|
-
UnlimitedCallRatePolicy as UnlimitedCallRatePolicyModel,
|
379
|
-
)
|
380
345
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import ValueType
|
381
346
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
382
347
|
WaitTimeFromHeader as WaitTimeFromHeaderModel,
|
@@ -490,15 +455,6 @@ from airbyte_cdk.sources.message import (
|
|
490
455
|
MessageRepository,
|
491
456
|
NoopMessageRepository,
|
492
457
|
)
|
493
|
-
from airbyte_cdk.sources.streams.call_rate import (
|
494
|
-
APIBudget,
|
495
|
-
FixedWindowCallRatePolicy,
|
496
|
-
HttpAPIBudget,
|
497
|
-
HttpRequestRegexMatcher,
|
498
|
-
MovingWindowCallRatePolicy,
|
499
|
-
Rate,
|
500
|
-
UnlimitedCallRatePolicy,
|
501
|
-
)
|
502
458
|
from airbyte_cdk.sources.streams.concurrent.clamping import (
|
503
459
|
ClampingEndProvider,
|
504
460
|
ClampingStrategy,
|
@@ -550,7 +506,6 @@ class ModelToComponentFactory:
|
|
550
506
|
self._evaluate_log_level(emit_connector_builder_messages)
|
551
507
|
)
|
552
508
|
self._connector_state_manager = connector_state_manager or ConnectorStateManager()
|
553
|
-
self._api_budget: Optional[Union[APIBudget, HttpAPIBudget]] = None
|
554
509
|
|
555
510
|
def _init_mappings(self) -> None:
|
556
511
|
self.PYDANTIC_MODEL_TO_CONSTRUCTOR: Mapping[Type[BaseModel], Callable[..., Any]] = {
|
@@ -562,9 +517,9 @@ class ModelToComponentFactory:
|
|
562
517
|
CheckStreamModel: self.create_check_stream,
|
563
518
|
CheckDynamicStreamModel: self.create_check_dynamic_stream,
|
564
519
|
CompositeErrorHandlerModel: self.create_composite_error_handler,
|
565
|
-
CompositeRawDecoderModel: self.create_composite_raw_decoder,
|
566
520
|
ConcurrencyLevelModel: self.create_concurrency_level,
|
567
521
|
ConstantBackoffStrategyModel: self.create_constant_backoff_strategy,
|
522
|
+
CsvDecoderModel: self.create_csv_decoder,
|
568
523
|
CursorPaginationModel: self.create_cursor_pagination,
|
569
524
|
CustomAuthenticatorModel: self.create_custom_component,
|
570
525
|
CustomBackoffStrategyModel: self.create_custom_component,
|
@@ -594,10 +549,7 @@ class ModelToComponentFactory:
|
|
594
549
|
InlineSchemaLoaderModel: self.create_inline_schema_loader,
|
595
550
|
JsonDecoderModel: self.create_json_decoder,
|
596
551
|
JsonlDecoderModel: self.create_jsonl_decoder,
|
597
|
-
|
598
|
-
JsonParserModel: self.create_json_parser,
|
599
|
-
GzipJsonDecoderModel: self.create_gzipjson_decoder,
|
600
|
-
GzipParserModel: self.create_gzip_parser,
|
552
|
+
GzipDecoderModel: self.create_gzip_decoder,
|
601
553
|
KeysToLowerModel: self.create_keys_to_lower_transformation,
|
602
554
|
KeysToSnakeCaseModel: self.create_keys_to_snake_transformation,
|
603
555
|
KeysReplaceModel: self.create_keys_replace_transformation,
|
@@ -638,13 +590,6 @@ class ModelToComponentFactory:
|
|
638
590
|
StreamConfigModel: self.create_stream_config,
|
639
591
|
ComponentMappingDefinitionModel: self.create_components_mapping_definition,
|
640
592
|
ZipfileDecoderModel: self.create_zipfile_decoder,
|
641
|
-
APIBudgetModel: self.create_api_budget,
|
642
|
-
HTTPAPIBudgetModel: self.create_http_api_budget,
|
643
|
-
FixedWindowCallRatePolicyModel: self.create_fixed_window_call_rate_policy,
|
644
|
-
MovingWindowCallRatePolicyModel: self.create_moving_window_call_rate_policy,
|
645
|
-
UnlimitedCallRatePolicyModel: self.create_unlimited_call_rate_policy,
|
646
|
-
RateModel: self.create_rate,
|
647
|
-
HttpRequestRegexMatcherModel: self.create_http_request_matcher,
|
648
593
|
}
|
649
594
|
|
650
595
|
# Needed for the case where we need to perform a second parse on the fields of a custom component
|
@@ -972,6 +917,17 @@ class ModelToComponentFactory:
|
|
972
917
|
parameters={},
|
973
918
|
)
|
974
919
|
|
920
|
+
@staticmethod
|
921
|
+
def apply_stream_state_migrations(
|
922
|
+
stream_state_migrations: List[Any] | None, stream_state: MutableMapping[str, Any]
|
923
|
+
) -> MutableMapping[str, Any]:
|
924
|
+
if stream_state_migrations:
|
925
|
+
for state_migration in stream_state_migrations:
|
926
|
+
if state_migration.should_migrate(stream_state):
|
927
|
+
# The state variable is expected to be mutable but the migrate method returns an immutable mapping.
|
928
|
+
stream_state = dict(state_migration.migrate(stream_state))
|
929
|
+
return stream_state
|
930
|
+
|
975
931
|
def create_concurrent_cursor_from_datetime_based_cursor(
|
976
932
|
self,
|
977
933
|
model_type: Type[BaseModel],
|
@@ -981,6 +937,7 @@ class ModelToComponentFactory:
|
|
981
937
|
config: Config,
|
982
938
|
message_repository: Optional[MessageRepository] = None,
|
983
939
|
runtime_lookback_window: Optional[datetime.timedelta] = None,
|
940
|
+
stream_state_migrations: Optional[List[Any]] = None,
|
984
941
|
**kwargs: Any,
|
985
942
|
) -> ConcurrentCursor:
|
986
943
|
# Per-partition incremental streams can dynamically create child cursors which will pass their current
|
@@ -991,6 +948,7 @@ class ModelToComponentFactory:
|
|
991
948
|
if "stream_state" not in kwargs
|
992
949
|
else kwargs["stream_state"]
|
993
950
|
)
|
951
|
+
stream_state = self.apply_stream_state_migrations(stream_state_migrations, stream_state)
|
994
952
|
|
995
953
|
component_type = component_definition.get("type")
|
996
954
|
if component_definition.get("type") != model_type.__name__:
|
@@ -1226,6 +1184,7 @@ class ModelToComponentFactory:
|
|
1226
1184
|
config: Config,
|
1227
1185
|
stream_state: MutableMapping[str, Any],
|
1228
1186
|
partition_router: PartitionRouter,
|
1187
|
+
stream_state_migrations: Optional[List[Any]] = None,
|
1229
1188
|
**kwargs: Any,
|
1230
1189
|
) -> ConcurrentPerPartitionCursor:
|
1231
1190
|
component_type = component_definition.get("type")
|
@@ -1274,8 +1233,10 @@ class ModelToComponentFactory:
|
|
1274
1233
|
stream_namespace=stream_namespace,
|
1275
1234
|
config=config,
|
1276
1235
|
message_repository=NoopMessageRepository(),
|
1236
|
+
stream_state_migrations=stream_state_migrations,
|
1277
1237
|
)
|
1278
1238
|
)
|
1239
|
+
stream_state = self.apply_stream_state_migrations(stream_state_migrations, stream_state)
|
1279
1240
|
|
1280
1241
|
# Return the concurrent cursor and state converter
|
1281
1242
|
return ConcurrentPerPartitionCursor(
|
@@ -1784,6 +1745,7 @@ class ModelToComponentFactory:
|
|
1784
1745
|
stream_name=model.name or "",
|
1785
1746
|
stream_namespace=None,
|
1786
1747
|
config=config or {},
|
1748
|
+
stream_state_migrations=model.state_migrations,
|
1787
1749
|
)
|
1788
1750
|
return (
|
1789
1751
|
self._create_component_from_model(model=model.incremental_sync, config=config)
|
@@ -1940,8 +1902,6 @@ class ModelToComponentFactory:
|
|
1940
1902
|
)
|
1941
1903
|
)
|
1942
1904
|
|
1943
|
-
api_budget = self._api_budget
|
1944
|
-
|
1945
1905
|
request_options_provider = InterpolatedRequestOptionsProvider(
|
1946
1906
|
request_body_data=model.request_body_data,
|
1947
1907
|
request_body_json=model.request_body_json,
|
@@ -1962,7 +1922,6 @@ class ModelToComponentFactory:
|
|
1962
1922
|
path=model.path,
|
1963
1923
|
authenticator=authenticator,
|
1964
1924
|
error_handler=error_handler,
|
1965
|
-
api_budget=api_budget,
|
1966
1925
|
http_method=HttpMethod[model.http_method.value],
|
1967
1926
|
request_options_provider=request_options_provider,
|
1968
1927
|
config=config,
|
@@ -2092,25 +2051,26 @@ class ModelToComponentFactory:
|
|
2092
2051
|
)
|
2093
2052
|
|
2094
2053
|
@staticmethod
|
2095
|
-
def create_json_decoder(model: JsonDecoderModel, config: Config, **kwargs: Any) ->
|
2054
|
+
def create_json_decoder(model: JsonDecoderModel, config: Config, **kwargs: Any) -> Decoder:
|
2096
2055
|
return JsonDecoder(parameters={})
|
2097
2056
|
|
2098
2057
|
@staticmethod
|
2099
|
-
def
|
2100
|
-
|
2101
|
-
|
2058
|
+
def create_csv_decoder(model: CsvDecoderModel, config: Config, **kwargs: Any) -> Decoder:
|
2059
|
+
return CompositeRawDecoder(
|
2060
|
+
parser=ModelToComponentFactory._get_parser(model, config), stream_response=True
|
2061
|
+
)
|
2102
2062
|
|
2103
2063
|
@staticmethod
|
2104
|
-
def create_jsonl_decoder(
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2064
|
+
def create_jsonl_decoder(model: JsonlDecoderModel, config: Config, **kwargs: Any) -> Decoder:
|
2065
|
+
return CompositeRawDecoder(
|
2066
|
+
parser=ModelToComponentFactory._get_parser(model, config), stream_response=True
|
2067
|
+
)
|
2108
2068
|
|
2109
2069
|
@staticmethod
|
2110
|
-
def
|
2111
|
-
|
2112
|
-
|
2113
|
-
|
2070
|
+
def create_gzip_decoder(model: GzipDecoderModel, config: Config, **kwargs: Any) -> Decoder:
|
2071
|
+
return CompositeRawDecoder(
|
2072
|
+
parser=ModelToComponentFactory._get_parser(model, config), stream_response=True
|
2073
|
+
)
|
2114
2074
|
|
2115
2075
|
@staticmethod
|
2116
2076
|
def create_iterable_decoder(
|
@@ -2122,33 +2082,30 @@ class ModelToComponentFactory:
|
|
2122
2082
|
def create_xml_decoder(model: XmlDecoderModel, config: Config, **kwargs: Any) -> XmlDecoder:
|
2123
2083
|
return XmlDecoder(parameters={})
|
2124
2084
|
|
2125
|
-
@staticmethod
|
2126
|
-
def create_gzipjson_decoder(
|
2127
|
-
model: GzipJsonDecoderModel, config: Config, **kwargs: Any
|
2128
|
-
) -> GzipJsonDecoder:
|
2129
|
-
return GzipJsonDecoder(parameters={}, encoding=model.encoding)
|
2130
|
-
|
2131
2085
|
def create_zipfile_decoder(
|
2132
2086
|
self, model: ZipfileDecoderModel, config: Config, **kwargs: Any
|
2133
2087
|
) -> ZipfileDecoder:
|
2134
|
-
parser
|
2135
|
-
return ZipfileDecoder(parser=parser)
|
2136
|
-
|
2137
|
-
def create_gzip_parser(
|
2138
|
-
self, model: GzipParserModel, config: Config, **kwargs: Any
|
2139
|
-
) -> GzipParser:
|
2140
|
-
inner_parser = self._create_component_from_model(model=model.inner_parser, config=config)
|
2141
|
-
return GzipParser(inner_parser=inner_parser)
|
2088
|
+
return ZipfileDecoder(parser=ModelToComponentFactory._get_parser(model.decoder, config))
|
2142
2089
|
|
2143
2090
|
@staticmethod
|
2144
|
-
def
|
2145
|
-
|
2091
|
+
def _get_parser(model: BaseModel, config: Config) -> Parser:
|
2092
|
+
if isinstance(model, JsonDecoderModel):
|
2093
|
+
# Note that the logic is a bit different from the JsonDecoder as there is some legacy that is maintained to return {} on error cases
|
2094
|
+
return JsonParser()
|
2095
|
+
elif isinstance(model, JsonlDecoderModel):
|
2096
|
+
return JsonLineParser()
|
2097
|
+
elif isinstance(model, CsvDecoderModel):
|
2098
|
+
return CsvParser(encoding=model.encoding, delimiter=model.delimiter)
|
2099
|
+
elif isinstance(model, GzipDecoderModel):
|
2100
|
+
return GzipParser(
|
2101
|
+
inner_parser=ModelToComponentFactory._get_parser(model.decoder, config)
|
2102
|
+
)
|
2103
|
+
elif isinstance(
|
2104
|
+
model, (CustomDecoderModel, IterableDecoderModel, XmlDecoderModel, ZipfileDecoderModel)
|
2105
|
+
):
|
2106
|
+
raise ValueError(f"Decoder type {model} does not have parser associated to it")
|
2146
2107
|
|
2147
|
-
|
2148
|
-
self, model: CompositeRawDecoderModel, config: Config, **kwargs: Any
|
2149
|
-
) -> CompositeRawDecoder:
|
2150
|
-
parser = self._create_component_from_model(model=model.parser, config=config)
|
2151
|
-
return CompositeRawDecoder(parser=parser)
|
2108
|
+
raise ValueError(f"Unknown decoder type {model}")
|
2152
2109
|
|
2153
2110
|
@staticmethod
|
2154
2111
|
def create_json_file_schema_loader(
|
@@ -2964,103 +2921,3 @@ class ModelToComponentFactory:
|
|
2964
2921
|
return isinstance(parser.inner_parser, JsonParser)
|
2965
2922
|
else:
|
2966
2923
|
return False
|
2967
|
-
|
2968
|
-
def create_api_budget(self, model: APIBudgetModel, config: Config, **kwargs: Any) -> APIBudget:
|
2969
|
-
policies = [
|
2970
|
-
self._create_component_from_model(model=policy, config=config)
|
2971
|
-
for policy in model.policies
|
2972
|
-
]
|
2973
|
-
|
2974
|
-
return APIBudget(
|
2975
|
-
policies=policies,
|
2976
|
-
maximum_attempts_to_acquire=model.maximum_attempts_to_acquire or 100000,
|
2977
|
-
)
|
2978
|
-
|
2979
|
-
def create_http_api_budget(
|
2980
|
-
self, model: HTTPAPIBudgetModel, config: Config, **kwargs: Any
|
2981
|
-
) -> HttpAPIBudget:
|
2982
|
-
policies = [
|
2983
|
-
self._create_component_from_model(model=policy, config=config)
|
2984
|
-
for policy in model.policies
|
2985
|
-
]
|
2986
|
-
|
2987
|
-
return HttpAPIBudget(
|
2988
|
-
policies=policies,
|
2989
|
-
maximum_attempts_to_acquire=model.maximum_attempts_to_acquire or 100000,
|
2990
|
-
ratelimit_reset_header=model.ratelimit_reset_header or "ratelimit-reset",
|
2991
|
-
ratelimit_remaining_header=model.ratelimit_remaining_header or "ratelimit-remaining",
|
2992
|
-
status_codes_for_ratelimit_hit=model.status_codes_for_ratelimit_hit or (429,),
|
2993
|
-
)
|
2994
|
-
|
2995
|
-
def create_fixed_window_call_rate_policy(
|
2996
|
-
self, model: FixedWindowCallRatePolicyModel, config: Config, **kwargs: Any
|
2997
|
-
) -> FixedWindowCallRatePolicy:
|
2998
|
-
matchers = [
|
2999
|
-
self._create_component_from_model(model=matcher, config=config)
|
3000
|
-
for matcher in model.matchers
|
3001
|
-
]
|
3002
|
-
return FixedWindowCallRatePolicy(
|
3003
|
-
next_reset_ts=model.next_reset_ts,
|
3004
|
-
period=model.period,
|
3005
|
-
call_limit=model.call_limit,
|
3006
|
-
matchers=matchers,
|
3007
|
-
)
|
3008
|
-
|
3009
|
-
def create_moving_window_call_rate_policy(
|
3010
|
-
self, model: MovingWindowCallRatePolicyModel, config: Config, **kwargs: Any
|
3011
|
-
) -> MovingWindowCallRatePolicy:
|
3012
|
-
rates = [
|
3013
|
-
self._create_component_from_model(model=rate, config=config) for rate in model.rates
|
3014
|
-
]
|
3015
|
-
matchers = [
|
3016
|
-
self._create_component_from_model(model=matcher, config=config)
|
3017
|
-
for matcher in model.matchers
|
3018
|
-
]
|
3019
|
-
return MovingWindowCallRatePolicy(
|
3020
|
-
rates=rates,
|
3021
|
-
matchers=matchers,
|
3022
|
-
)
|
3023
|
-
|
3024
|
-
def create_unlimited_call_rate_policy(
|
3025
|
-
self, model: UnlimitedCallRatePolicyModel, config: Config, **kwargs: Any
|
3026
|
-
) -> UnlimitedCallRatePolicy:
|
3027
|
-
matchers = [
|
3028
|
-
self._create_component_from_model(model=matcher, config=config)
|
3029
|
-
for matcher in model.matchers
|
3030
|
-
]
|
3031
|
-
|
3032
|
-
return UnlimitedCallRatePolicy(
|
3033
|
-
matchers=matchers,
|
3034
|
-
)
|
3035
|
-
|
3036
|
-
def create_rate(self, model: RateModel, config: Config, **kwargs: Any) -> Rate:
|
3037
|
-
return Rate(
|
3038
|
-
limit=model.limit,
|
3039
|
-
interval=model.interval,
|
3040
|
-
)
|
3041
|
-
|
3042
|
-
def create_http_request_matcher(
|
3043
|
-
self, model: HttpRequestRegexMatcherModel, config: Config, **kwargs: Any
|
3044
|
-
) -> HttpRequestRegexMatcher:
|
3045
|
-
return HttpRequestRegexMatcher(
|
3046
|
-
method=model.method,
|
3047
|
-
url_base=model.url_base,
|
3048
|
-
url_path_pattern=model.url_path_pattern,
|
3049
|
-
params=model.params,
|
3050
|
-
headers=model.headers,
|
3051
|
-
)
|
3052
|
-
|
3053
|
-
def set_api_budget(self, component_definition: ComponentDefinition, config: Config) -> None:
|
3054
|
-
model_str = component_definition.get("type")
|
3055
|
-
if model_str == "APIBudget":
|
3056
|
-
# Annotate model_type as a type that is a subclass of BaseModel
|
3057
|
-
model_type: Union[Type[APIBudgetModel], Type[HTTPAPIBudgetModel]] = APIBudgetModel
|
3058
|
-
elif model_str == "HTTPAPIBudget":
|
3059
|
-
model_type = HTTPAPIBudgetModel
|
3060
|
-
else:
|
3061
|
-
raise ValueError(f"Unknown API Budget type: {model_str}")
|
3062
|
-
|
3063
|
-
# create_component expects a type[BaseModel] and returns an instance of that model.
|
3064
|
-
self._api_budget = self.create_component(
|
3065
|
-
model_type=model_type, component_definition=component_definition, config=config
|
3066
|
-
)
|
@@ -22,7 +22,6 @@ from airbyte_cdk.sources.declarative.requesters.request_options.interpolated_req
|
|
22
22
|
)
|
23
23
|
from airbyte_cdk.sources.declarative.requesters.requester import HttpMethod, Requester
|
24
24
|
from airbyte_cdk.sources.message import MessageRepository, NoopMessageRepository
|
25
|
-
from airbyte_cdk.sources.streams.call_rate import APIBudget
|
26
25
|
from airbyte_cdk.sources.streams.http import HttpClient
|
27
26
|
from airbyte_cdk.sources.streams.http.error_handlers import ErrorHandler
|
28
27
|
from airbyte_cdk.sources.types import Config, StreamSlice, StreamState
|
@@ -56,7 +55,6 @@ class HttpRequester(Requester):
|
|
56
55
|
http_method: Union[str, HttpMethod] = HttpMethod.GET
|
57
56
|
request_options_provider: Optional[InterpolatedRequestOptionsProvider] = None
|
58
57
|
error_handler: Optional[ErrorHandler] = None
|
59
|
-
api_budget: Optional[APIBudget] = None
|
60
58
|
disable_retries: bool = False
|
61
59
|
message_repository: MessageRepository = NoopMessageRepository()
|
62
60
|
use_cache: bool = False
|
@@ -93,7 +91,6 @@ class HttpRequester(Requester):
|
|
93
91
|
name=self.name,
|
94
92
|
logger=self.logger,
|
95
93
|
error_handler=self.error_handler,
|
96
|
-
api_budget=self.api_budget,
|
97
94
|
authenticator=self._authenticator,
|
98
95
|
use_cache=self.use_cache,
|
99
96
|
backoff_strategy=backoff_strategies,
|