airbyte-cdk 6.32.0__py3-none-any.whl → 6.33.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.
- airbyte_cdk/sources/declarative/declarative_component_schema.yaml +208 -1
- airbyte_cdk/sources/declarative/manifest_declarative_source.py +4 -0
- airbyte_cdk/sources/declarative/models/declarative_component_schema.py +165 -0
- airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py +141 -0
- airbyte_cdk/sources/declarative/requesters/http_requester.py +3 -0
- airbyte_cdk/sources/streams/call_rate.py +84 -71
- {airbyte_cdk-6.32.0.dist-info → airbyte_cdk-6.33.0.dev0.dist-info}/METADATA +1 -1
- {airbyte_cdk-6.32.0.dist-info → airbyte_cdk-6.33.0.dev0.dist-info}/RECORD +12 -12
- {airbyte_cdk-6.32.0.dist-info → airbyte_cdk-6.33.0.dev0.dist-info}/LICENSE.txt +0 -0
- {airbyte_cdk-6.32.0.dist-info → airbyte_cdk-6.33.0.dev0.dist-info}/LICENSE_SHORT +0 -0
- {airbyte_cdk-6.32.0.dist-info → airbyte_cdk-6.33.0.dev0.dist-info}/WHEEL +0 -0
- {airbyte_cdk-6.32.0.dist-info → airbyte_cdk-6.33.0.dev0.dist-info}/entry_points.txt +0 -0
@@ -40,6 +40,12 @@ properties:
|
|
40
40
|
"$ref": "#/definitions/Spec"
|
41
41
|
concurrency_level:
|
42
42
|
"$ref": "#/definitions/ConcurrencyLevel"
|
43
|
+
api_budget:
|
44
|
+
title: API Budget
|
45
|
+
description: Defines how many requests can be made to the API in a given time frame. This field accepts either a generic APIBudget or an HTTP-specific configuration (HTTPAPIBudget) to be applied across all streams.
|
46
|
+
anyOf:
|
47
|
+
- "$ref": "#/definitions/APIBudget"
|
48
|
+
- "$ref": "#/definitions/HTTPAPIBudget"
|
43
49
|
metadata:
|
44
50
|
type: object
|
45
51
|
description: For internal Airbyte use only - DO NOT modify manually. Used by consumers of declarative manifests for storing related metadata.
|
@@ -794,7 +800,7 @@ definitions:
|
|
794
800
|
description: This option is used to adjust the upper and lower boundaries of each datetime window to beginning and end of the provided target period (day, week, month)
|
795
801
|
type: object
|
796
802
|
required:
|
797
|
-
|
803
|
+
- target
|
798
804
|
properties:
|
799
805
|
target:
|
800
806
|
title: Target
|
@@ -1365,6 +1371,207 @@ definitions:
|
|
1365
1371
|
$parameters:
|
1366
1372
|
type: object
|
1367
1373
|
additional_properties: true
|
1374
|
+
APIBudget:
|
1375
|
+
title: API Budget
|
1376
|
+
description: >
|
1377
|
+
A generic API budget configuration that defines the policies (rate limiting rules)
|
1378
|
+
and the maximum number of attempts to acquire a call credit. This budget does not automatically
|
1379
|
+
update itself based on HTTP response headers.
|
1380
|
+
type: object
|
1381
|
+
required:
|
1382
|
+
- type
|
1383
|
+
- policies
|
1384
|
+
properties:
|
1385
|
+
type:
|
1386
|
+
type: string
|
1387
|
+
enum: [APIBudget]
|
1388
|
+
policies:
|
1389
|
+
title: Policies
|
1390
|
+
description: List of call rate policies that define how many calls are allowed.
|
1391
|
+
type: array
|
1392
|
+
items:
|
1393
|
+
anyOf:
|
1394
|
+
- "$ref": "#/definitions/FixedWindowCallRatePolicy"
|
1395
|
+
- "$ref": "#/definitions/MovingWindowCallRatePolicy"
|
1396
|
+
- "$ref": "#/definitions/UnlimitedCallRatePolicy"
|
1397
|
+
maximum_attempts_to_acquire:
|
1398
|
+
title: Maximum Attempts to Acquire
|
1399
|
+
description: The maximum number of attempts to acquire a call before giving up.
|
1400
|
+
type: integer
|
1401
|
+
default: 100000
|
1402
|
+
additionalProperties: true
|
1403
|
+
HTTPAPIBudget:
|
1404
|
+
title: HTTP API Budget
|
1405
|
+
description: >
|
1406
|
+
An HTTP-specific API budget that extends APIBudget by updating rate limiting information based
|
1407
|
+
on HTTP response headers. It extracts available calls and the next reset timestamp from the HTTP responses.
|
1408
|
+
type: object
|
1409
|
+
required:
|
1410
|
+
- type
|
1411
|
+
- policies
|
1412
|
+
properties:
|
1413
|
+
type:
|
1414
|
+
type: string
|
1415
|
+
enum: [HTTPAPIBudget]
|
1416
|
+
policies:
|
1417
|
+
title: Policies
|
1418
|
+
description: List of call rate policies that define how many calls are allowed.
|
1419
|
+
type: array
|
1420
|
+
items:
|
1421
|
+
anyOf:
|
1422
|
+
- "$ref": "#/definitions/FixedWindowCallRatePolicy"
|
1423
|
+
- "$ref": "#/definitions/MovingWindowCallRatePolicy"
|
1424
|
+
- "$ref": "#/definitions/UnlimitedCallRatePolicy"
|
1425
|
+
ratelimit_reset_header:
|
1426
|
+
title: Rate Limit Reset Header
|
1427
|
+
description: The HTTP response header name that indicates when the rate limit resets.
|
1428
|
+
type: string
|
1429
|
+
default: "ratelimit-reset"
|
1430
|
+
ratelimit_remaining_header:
|
1431
|
+
title: Rate Limit Remaining Header
|
1432
|
+
description: The HTTP response header name that indicates the number of remaining allowed calls.
|
1433
|
+
type: string
|
1434
|
+
default: "ratelimit-remaining"
|
1435
|
+
status_codes_for_ratelimit_hit:
|
1436
|
+
title: Status Codes for Rate Limit Hit
|
1437
|
+
description: List of HTTP status codes that indicate a rate limit has been hit.
|
1438
|
+
type: array
|
1439
|
+
items:
|
1440
|
+
type: integer
|
1441
|
+
default: [429]
|
1442
|
+
maximum_attempts_to_acquire:
|
1443
|
+
title: Maximum Attempts to Acquire
|
1444
|
+
description: The maximum number of attempts to acquire a call before giving up.
|
1445
|
+
type: integer
|
1446
|
+
default: 100000
|
1447
|
+
additionalProperties: true
|
1448
|
+
FixedWindowCallRatePolicy:
|
1449
|
+
title: Fixed Window Call Rate Policy
|
1450
|
+
description: A policy that allows a fixed number of calls within a specific time window.
|
1451
|
+
type: object
|
1452
|
+
required:
|
1453
|
+
- type
|
1454
|
+
- next_reset_ts
|
1455
|
+
- period
|
1456
|
+
- call_limit
|
1457
|
+
- matchers
|
1458
|
+
properties:
|
1459
|
+
type:
|
1460
|
+
type: string
|
1461
|
+
enum: [FixedWindowCallRatePolicy]
|
1462
|
+
next_reset_ts:
|
1463
|
+
title: Next Reset Timestamp
|
1464
|
+
description: The timestamp when the rate limit will reset.
|
1465
|
+
type: string
|
1466
|
+
format: date-time
|
1467
|
+
period:
|
1468
|
+
title: Period
|
1469
|
+
description: The time interval for the rate limit window.
|
1470
|
+
type: string
|
1471
|
+
format: duration
|
1472
|
+
call_limit:
|
1473
|
+
title: Call Limit
|
1474
|
+
description: The maximum number of calls allowed within the period.
|
1475
|
+
type: integer
|
1476
|
+
matchers:
|
1477
|
+
title: Matchers
|
1478
|
+
description: List of matchers that define which requests this policy applies to.
|
1479
|
+
type: array
|
1480
|
+
items:
|
1481
|
+
"$ref": "#/definitions/HttpRequestMatcher"
|
1482
|
+
additionalProperties: true
|
1483
|
+
MovingWindowCallRatePolicy:
|
1484
|
+
title: Moving Window Call Rate Policy
|
1485
|
+
description: A policy that allows a fixed number of calls within a moving time window.
|
1486
|
+
type: object
|
1487
|
+
required:
|
1488
|
+
- type
|
1489
|
+
- rates
|
1490
|
+
- matchers
|
1491
|
+
properties:
|
1492
|
+
type:
|
1493
|
+
type: string
|
1494
|
+
enum: [MovingWindowCallRatePolicy]
|
1495
|
+
rates:
|
1496
|
+
title: Rates
|
1497
|
+
description: List of rates that define the call limits for different time intervals.
|
1498
|
+
type: array
|
1499
|
+
items:
|
1500
|
+
"$ref": "#/definitions/Rate"
|
1501
|
+
matchers:
|
1502
|
+
title: Matchers
|
1503
|
+
description: List of matchers that define which requests this policy applies to.
|
1504
|
+
type: array
|
1505
|
+
items:
|
1506
|
+
"$ref": "#/definitions/HttpRequestMatcher"
|
1507
|
+
additionalProperties: true
|
1508
|
+
UnlimitedCallRatePolicy:
|
1509
|
+
title: Unlimited Call Rate Policy
|
1510
|
+
description: A policy that allows unlimited calls for specific requests.
|
1511
|
+
type: object
|
1512
|
+
required:
|
1513
|
+
- type
|
1514
|
+
- matchers
|
1515
|
+
properties:
|
1516
|
+
type:
|
1517
|
+
type: string
|
1518
|
+
enum: [UnlimitedCallRatePolicy]
|
1519
|
+
matchers:
|
1520
|
+
title: Matchers
|
1521
|
+
description: List of matchers that define which requests this policy applies to.
|
1522
|
+
type: array
|
1523
|
+
items:
|
1524
|
+
"$ref": "#/definitions/HttpRequestMatcher"
|
1525
|
+
additionalProperties: true
|
1526
|
+
Rate:
|
1527
|
+
title: Rate
|
1528
|
+
description: Defines a rate limit with a specific number of calls allowed within a time interval.
|
1529
|
+
type: object
|
1530
|
+
required:
|
1531
|
+
- limit
|
1532
|
+
- interval
|
1533
|
+
properties:
|
1534
|
+
limit:
|
1535
|
+
title: Limit
|
1536
|
+
description: The maximum number of calls allowed within the interval.
|
1537
|
+
type: integer
|
1538
|
+
interval:
|
1539
|
+
title: Interval
|
1540
|
+
description: The time interval for the rate limit.
|
1541
|
+
type: string
|
1542
|
+
format: duration
|
1543
|
+
additionalProperties: true
|
1544
|
+
HttpRequestMatcher:
|
1545
|
+
title: HTTP Request Matcher
|
1546
|
+
description: >
|
1547
|
+
Matches HTTP requests based on method, base URL, URL path pattern, query parameters, and headers.
|
1548
|
+
Use `url_base` to specify the scheme and host (without trailing slash) and
|
1549
|
+
`url_path_pattern` to apply a regex to the request path.
|
1550
|
+
type: object
|
1551
|
+
properties:
|
1552
|
+
method:
|
1553
|
+
title: Method
|
1554
|
+
description: The HTTP method to match (e.g., GET, POST).
|
1555
|
+
type: string
|
1556
|
+
url_base:
|
1557
|
+
title: URL Base
|
1558
|
+
description: The base URL (scheme and host, e.g. "https://api.example.com") to match.
|
1559
|
+
type: string
|
1560
|
+
url_path_pattern:
|
1561
|
+
title: URL Path Pattern
|
1562
|
+
description: A regular expression pattern to match the URL path.
|
1563
|
+
type: string
|
1564
|
+
params:
|
1565
|
+
title: Parameters
|
1566
|
+
description: The query parameters to match.
|
1567
|
+
type: object
|
1568
|
+
additionalProperties: true
|
1569
|
+
headers:
|
1570
|
+
title: Headers
|
1571
|
+
description: The headers to match.
|
1572
|
+
type: object
|
1573
|
+
additionalProperties: true
|
1574
|
+
additionalProperties: true
|
1368
1575
|
DefaultErrorHandler:
|
1369
1576
|
title: Default Error Handler
|
1370
1577
|
description: Component defining how to handle errors. Default behavior includes only retrying server errors (HTTP 5XX) and too many requests (HTTP 429) with an exponential backoff.
|
@@ -137,6 +137,10 @@ class ManifestDeclarativeSource(DeclarativeSource):
|
|
137
137
|
self._source_config, config
|
138
138
|
)
|
139
139
|
|
140
|
+
api_budget_model = self._source_config.get("api_budget")
|
141
|
+
if api_budget_model:
|
142
|
+
self._constructor.set_api_budget(api_budget_model, config)
|
143
|
+
|
140
144
|
source_streams = [
|
141
145
|
self._constructor.create_component(
|
142
146
|
DeclarativeStreamModel,
|
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
from __future__ import annotations
|
5
5
|
|
6
|
+
from datetime import datetime, timedelta
|
6
7
|
from enum import Enum
|
7
8
|
from typing import Any, Dict, List, Literal, Optional, Union
|
8
9
|
|
@@ -642,6 +643,45 @@ class OAuthAuthenticator(BaseModel):
|
|
642
643
|
parameters: Optional[Dict[str, Any]] = Field(None, alias="$parameters")
|
643
644
|
|
644
645
|
|
646
|
+
class Rate(BaseModel):
|
647
|
+
class Config:
|
648
|
+
extra = Extra.allow
|
649
|
+
|
650
|
+
limit: int = Field(
|
651
|
+
...,
|
652
|
+
description="The maximum number of calls allowed within the interval.",
|
653
|
+
title="Limit",
|
654
|
+
)
|
655
|
+
interval: timedelta = Field(
|
656
|
+
..., description="The time interval for the rate limit.", title="Interval"
|
657
|
+
)
|
658
|
+
|
659
|
+
|
660
|
+
class HttpRequestMatcher(BaseModel):
|
661
|
+
class Config:
|
662
|
+
extra = Extra.allow
|
663
|
+
|
664
|
+
method: Optional[str] = Field(
|
665
|
+
None, description="The HTTP method to match (e.g., GET, POST).", title="Method"
|
666
|
+
)
|
667
|
+
url_base: Optional[str] = Field(
|
668
|
+
None,
|
669
|
+
description='The base URL (scheme and host, e.g. "https://api.example.com") to match.',
|
670
|
+
title="URL Base",
|
671
|
+
)
|
672
|
+
url_path_pattern: Optional[str] = Field(
|
673
|
+
None,
|
674
|
+
description="A regular expression pattern to match the URL path.",
|
675
|
+
title="URL Path Pattern",
|
676
|
+
)
|
677
|
+
params: Optional[Dict[str, Any]] = Field(
|
678
|
+
None, description="The query parameters to match.", title="Parameters"
|
679
|
+
)
|
680
|
+
headers: Optional[Dict[str, Any]] = Field(
|
681
|
+
None, description="The headers to match.", title="Headers"
|
682
|
+
)
|
683
|
+
|
684
|
+
|
645
685
|
class DpathExtractor(BaseModel):
|
646
686
|
type: Literal["DpathExtractor"]
|
647
687
|
field_path: List[str] = Field(
|
@@ -1578,6 +1618,60 @@ class DatetimeBasedCursor(BaseModel):
|
|
1578
1618
|
parameters: Optional[Dict[str, Any]] = Field(None, alias="$parameters")
|
1579
1619
|
|
1580
1620
|
|
1621
|
+
class FixedWindowCallRatePolicy(BaseModel):
|
1622
|
+
class Config:
|
1623
|
+
extra = Extra.allow
|
1624
|
+
|
1625
|
+
type: Literal["FixedWindowCallRatePolicy"]
|
1626
|
+
next_reset_ts: datetime = Field(
|
1627
|
+
...,
|
1628
|
+
description="The timestamp when the rate limit will reset.",
|
1629
|
+
title="Next Reset Timestamp",
|
1630
|
+
)
|
1631
|
+
period: timedelta = Field(
|
1632
|
+
..., description="The time interval for the rate limit window.", title="Period"
|
1633
|
+
)
|
1634
|
+
call_limit: int = Field(
|
1635
|
+
...,
|
1636
|
+
description="The maximum number of calls allowed within the period.",
|
1637
|
+
title="Call Limit",
|
1638
|
+
)
|
1639
|
+
matchers: List[HttpRequestMatcher] = Field(
|
1640
|
+
...,
|
1641
|
+
description="List of matchers that define which requests this policy applies to.",
|
1642
|
+
title="Matchers",
|
1643
|
+
)
|
1644
|
+
|
1645
|
+
|
1646
|
+
class MovingWindowCallRatePolicy(BaseModel):
|
1647
|
+
class Config:
|
1648
|
+
extra = Extra.allow
|
1649
|
+
|
1650
|
+
type: Literal["MovingWindowCallRatePolicy"]
|
1651
|
+
rates: List[Rate] = Field(
|
1652
|
+
...,
|
1653
|
+
description="List of rates that define the call limits for different time intervals.",
|
1654
|
+
title="Rates",
|
1655
|
+
)
|
1656
|
+
matchers: List[HttpRequestMatcher] = Field(
|
1657
|
+
...,
|
1658
|
+
description="List of matchers that define which requests this policy applies to.",
|
1659
|
+
title="Matchers",
|
1660
|
+
)
|
1661
|
+
|
1662
|
+
|
1663
|
+
class UnlimitedCallRatePolicy(BaseModel):
|
1664
|
+
class Config:
|
1665
|
+
extra = Extra.allow
|
1666
|
+
|
1667
|
+
type: Literal["UnlimitedCallRatePolicy"]
|
1668
|
+
matchers: List[HttpRequestMatcher] = Field(
|
1669
|
+
...,
|
1670
|
+
description="List of matchers that define which requests this policy applies to.",
|
1671
|
+
title="Matchers",
|
1672
|
+
)
|
1673
|
+
|
1674
|
+
|
1581
1675
|
class DefaultErrorHandler(BaseModel):
|
1582
1676
|
type: Literal["DefaultErrorHandler"]
|
1583
1677
|
backoff_strategies: Optional[
|
@@ -1709,6 +1803,67 @@ class CompositeErrorHandler(BaseModel):
|
|
1709
1803
|
parameters: Optional[Dict[str, Any]] = Field(None, alias="$parameters")
|
1710
1804
|
|
1711
1805
|
|
1806
|
+
class APIBudget(BaseModel):
|
1807
|
+
class Config:
|
1808
|
+
extra = Extra.allow
|
1809
|
+
|
1810
|
+
type: Literal["APIBudget"]
|
1811
|
+
policies: List[
|
1812
|
+
Union[
|
1813
|
+
FixedWindowCallRatePolicy,
|
1814
|
+
MovingWindowCallRatePolicy,
|
1815
|
+
UnlimitedCallRatePolicy,
|
1816
|
+
]
|
1817
|
+
] = Field(
|
1818
|
+
...,
|
1819
|
+
description="List of call rate policies that define how many calls are allowed.",
|
1820
|
+
title="Policies",
|
1821
|
+
)
|
1822
|
+
maximum_attempts_to_acquire: Optional[int] = Field(
|
1823
|
+
100000,
|
1824
|
+
description="The maximum number of attempts to acquire a call before giving up.",
|
1825
|
+
title="Maximum Attempts to Acquire",
|
1826
|
+
)
|
1827
|
+
|
1828
|
+
|
1829
|
+
class HTTPAPIBudget(BaseModel):
|
1830
|
+
class Config:
|
1831
|
+
extra = Extra.allow
|
1832
|
+
|
1833
|
+
type: Literal["HTTPAPIBudget"]
|
1834
|
+
policies: List[
|
1835
|
+
Union[
|
1836
|
+
FixedWindowCallRatePolicy,
|
1837
|
+
MovingWindowCallRatePolicy,
|
1838
|
+
UnlimitedCallRatePolicy,
|
1839
|
+
]
|
1840
|
+
] = Field(
|
1841
|
+
...,
|
1842
|
+
description="List of call rate policies that define how many calls are allowed.",
|
1843
|
+
title="Policies",
|
1844
|
+
)
|
1845
|
+
ratelimit_reset_header: Optional[str] = Field(
|
1846
|
+
"ratelimit-reset",
|
1847
|
+
description="The HTTP response header name that indicates when the rate limit resets.",
|
1848
|
+
title="Rate Limit Reset Header",
|
1849
|
+
)
|
1850
|
+
ratelimit_remaining_header: Optional[str] = Field(
|
1851
|
+
"ratelimit-remaining",
|
1852
|
+
description="The HTTP response header name that indicates the number of remaining allowed calls.",
|
1853
|
+
title="Rate Limit Remaining Header",
|
1854
|
+
)
|
1855
|
+
status_codes_for_ratelimit_hit: Optional[List[int]] = Field(
|
1856
|
+
[429],
|
1857
|
+
description="List of HTTP status codes that indicate a rate limit has been hit.",
|
1858
|
+
title="Status Codes for Rate Limit Hit",
|
1859
|
+
)
|
1860
|
+
maximum_attempts_to_acquire: Optional[int] = Field(
|
1861
|
+
100000,
|
1862
|
+
description="The maximum number of attempts to acquire a call before giving up.",
|
1863
|
+
title="Maximum Attempts to Acquire",
|
1864
|
+
)
|
1865
|
+
|
1866
|
+
|
1712
1867
|
class ZipfileDecoder(BaseModel):
|
1713
1868
|
class Config:
|
1714
1869
|
extra = Extra.allow
|
@@ -1742,6 +1897,11 @@ class DeclarativeSource1(BaseModel):
|
|
1742
1897
|
definitions: Optional[Dict[str, Any]] = None
|
1743
1898
|
spec: Optional[Spec] = None
|
1744
1899
|
concurrency_level: Optional[ConcurrencyLevel] = None
|
1900
|
+
api_budget: Optional[Union[APIBudget, HTTPAPIBudget]] = Field(
|
1901
|
+
None,
|
1902
|
+
description="Defines how many requests can be made to the API in a given time frame. This field accepts either a generic APIBudget or an HTTP-specific configuration (HTTPAPIBudget) to be applied across all streams.",
|
1903
|
+
title="API Budget",
|
1904
|
+
)
|
1745
1905
|
metadata: Optional[Dict[str, Any]] = Field(
|
1746
1906
|
None,
|
1747
1907
|
description="For internal Airbyte use only - DO NOT modify manually. Used by consumers of declarative manifests for storing related metadata.",
|
@@ -1768,6 +1928,11 @@ class DeclarativeSource2(BaseModel):
|
|
1768
1928
|
definitions: Optional[Dict[str, Any]] = None
|
1769
1929
|
spec: Optional[Spec] = None
|
1770
1930
|
concurrency_level: Optional[ConcurrencyLevel] = None
|
1931
|
+
api_budget: Optional[Union[APIBudget, HTTPAPIBudget]] = Field(
|
1932
|
+
None,
|
1933
|
+
description="Defines how many requests can be made to the API in a given time frame. This field accepts either a generic APIBudget or an HTTP-specific configuration (HTTPAPIBudget) to be applied across all streams.",
|
1934
|
+
title="API Budget",
|
1935
|
+
)
|
1771
1936
|
metadata: Optional[Dict[str, Any]] = Field(
|
1772
1937
|
None,
|
1773
1938
|
description="For internal Airbyte use only - DO NOT modify manually. Used by consumers of declarative manifests for storing related metadata.",
|
@@ -112,6 +112,9 @@ from airbyte_cdk.sources.declarative.models.declarative_component_schema import
|
|
112
112
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
113
113
|
AddFields as AddFieldsModel,
|
114
114
|
)
|
115
|
+
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
116
|
+
APIBudget as APIBudgetModel,
|
117
|
+
)
|
115
118
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
116
119
|
ApiKeyAuthenticator as ApiKeyAuthenticatorModel,
|
117
120
|
)
|
@@ -226,6 +229,9 @@ from airbyte_cdk.sources.declarative.models.declarative_component_schema import
|
|
226
229
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
227
230
|
ExponentialBackoffStrategy as ExponentialBackoffStrategyModel,
|
228
231
|
)
|
232
|
+
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
233
|
+
FixedWindowCallRatePolicy as FixedWindowCallRatePolicyModel,
|
234
|
+
)
|
229
235
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
230
236
|
FlattenFields as FlattenFieldsModel,
|
231
237
|
)
|
@@ -235,12 +241,18 @@ from airbyte_cdk.sources.declarative.models.declarative_component_schema import
|
|
235
241
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
236
242
|
GzipParser as GzipParserModel,
|
237
243
|
)
|
244
|
+
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
245
|
+
HTTPAPIBudget as HTTPAPIBudgetModel,
|
246
|
+
)
|
238
247
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
239
248
|
HttpComponentsResolver as HttpComponentsResolverModel,
|
240
249
|
)
|
241
250
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
242
251
|
HttpRequester as HttpRequesterModel,
|
243
252
|
)
|
253
|
+
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
254
|
+
HttpRequestMatcher as HttpRequestMatcherModel,
|
255
|
+
)
|
244
256
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
245
257
|
HttpResponseFilter as HttpResponseFilterModel,
|
246
258
|
)
|
@@ -295,6 +307,9 @@ from airbyte_cdk.sources.declarative.models.declarative_component_schema import
|
|
295
307
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
296
308
|
MinMaxDatetime as MinMaxDatetimeModel,
|
297
309
|
)
|
310
|
+
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
311
|
+
MovingWindowCallRatePolicy as MovingWindowCallRatePolicyModel,
|
312
|
+
)
|
298
313
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
299
314
|
NoAuth as NoAuthModel,
|
300
315
|
)
|
@@ -313,6 +328,9 @@ from airbyte_cdk.sources.declarative.models.declarative_component_schema import
|
|
313
328
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
314
329
|
ParentStreamConfig as ParentStreamConfigModel,
|
315
330
|
)
|
331
|
+
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
332
|
+
Rate as RateModel,
|
333
|
+
)
|
316
334
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
317
335
|
RecordFilter as RecordFilterModel,
|
318
336
|
)
|
@@ -356,6 +374,9 @@ from airbyte_cdk.sources.declarative.models.declarative_component_schema import
|
|
356
374
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
357
375
|
TypesMap as TypesMapModel,
|
358
376
|
)
|
377
|
+
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
378
|
+
UnlimitedCallRatePolicy as UnlimitedCallRatePolicyModel,
|
379
|
+
)
|
359
380
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import ValueType
|
360
381
|
from airbyte_cdk.sources.declarative.models.declarative_component_schema import (
|
361
382
|
WaitTimeFromHeader as WaitTimeFromHeaderModel,
|
@@ -469,6 +490,15 @@ from airbyte_cdk.sources.message import (
|
|
469
490
|
MessageRepository,
|
470
491
|
NoopMessageRepository,
|
471
492
|
)
|
493
|
+
from airbyte_cdk.sources.streams.call_rate import (
|
494
|
+
APIBudget,
|
495
|
+
FixedWindowCallRatePolicy,
|
496
|
+
HttpAPIBudget,
|
497
|
+
HttpRequestMatcher,
|
498
|
+
MovingWindowCallRatePolicy,
|
499
|
+
Rate,
|
500
|
+
UnlimitedCallRatePolicy,
|
501
|
+
)
|
472
502
|
from airbyte_cdk.sources.streams.concurrent.clamping import (
|
473
503
|
ClampingEndProvider,
|
474
504
|
ClampingStrategy,
|
@@ -520,6 +550,7 @@ class ModelToComponentFactory:
|
|
520
550
|
self._evaluate_log_level(emit_connector_builder_messages)
|
521
551
|
)
|
522
552
|
self._connector_state_manager = connector_state_manager or ConnectorStateManager()
|
553
|
+
self._api_budget: Optional[Union[APIBudget, HttpAPIBudget]] = None
|
523
554
|
|
524
555
|
def _init_mappings(self) -> None:
|
525
556
|
self.PYDANTIC_MODEL_TO_CONSTRUCTOR: Mapping[Type[BaseModel], Callable[..., Any]] = {
|
@@ -607,6 +638,13 @@ class ModelToComponentFactory:
|
|
607
638
|
StreamConfigModel: self.create_stream_config,
|
608
639
|
ComponentMappingDefinitionModel: self.create_components_mapping_definition,
|
609
640
|
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
|
+
HttpRequestMatcherModel: self.create_http_request_matcher,
|
610
648
|
}
|
611
649
|
|
612
650
|
# Needed for the case where we need to perform a second parse on the fields of a custom component
|
@@ -1911,6 +1949,8 @@ class ModelToComponentFactory:
|
|
1911
1949
|
)
|
1912
1950
|
)
|
1913
1951
|
|
1952
|
+
api_budget = self._api_budget
|
1953
|
+
|
1914
1954
|
request_options_provider = InterpolatedRequestOptionsProvider(
|
1915
1955
|
request_body_data=model.request_body_data,
|
1916
1956
|
request_body_json=model.request_body_json,
|
@@ -1931,6 +1971,7 @@ class ModelToComponentFactory:
|
|
1931
1971
|
path=model.path,
|
1932
1972
|
authenticator=authenticator,
|
1933
1973
|
error_handler=error_handler,
|
1974
|
+
api_budget=api_budget,
|
1934
1975
|
http_method=HttpMethod[model.http_method.value],
|
1935
1976
|
request_options_provider=request_options_provider,
|
1936
1977
|
config=config,
|
@@ -2919,3 +2960,103 @@ class ModelToComponentFactory:
|
|
2919
2960
|
return isinstance(parser.inner_parser, JsonParser)
|
2920
2961
|
else:
|
2921
2962
|
return False
|
2963
|
+
|
2964
|
+
def create_api_budget(self, model: APIBudgetModel, config: Config, **kwargs: Any) -> APIBudget:
|
2965
|
+
policies = [
|
2966
|
+
self._create_component_from_model(model=policy, config=config)
|
2967
|
+
for policy in model.policies
|
2968
|
+
]
|
2969
|
+
|
2970
|
+
return APIBudget(
|
2971
|
+
policies=policies,
|
2972
|
+
maximum_attempts_to_acquire=model.maximum_attempts_to_acquire or 100000,
|
2973
|
+
)
|
2974
|
+
|
2975
|
+
def create_http_api_budget(
|
2976
|
+
self, model: HTTPAPIBudgetModel, config: Config, **kwargs: Any
|
2977
|
+
) -> HttpAPIBudget:
|
2978
|
+
policies = [
|
2979
|
+
self._create_component_from_model(model=policy, config=config)
|
2980
|
+
for policy in model.policies
|
2981
|
+
]
|
2982
|
+
|
2983
|
+
return HttpAPIBudget(
|
2984
|
+
policies=policies,
|
2985
|
+
maximum_attempts_to_acquire=model.maximum_attempts_to_acquire or 100000,
|
2986
|
+
ratelimit_reset_header=model.ratelimit_reset_header or "ratelimit-reset",
|
2987
|
+
ratelimit_remaining_header=model.ratelimit_remaining_header or "ratelimit-remaining",
|
2988
|
+
status_codes_for_ratelimit_hit=model.status_codes_for_ratelimit_hit or (429,),
|
2989
|
+
)
|
2990
|
+
|
2991
|
+
def create_fixed_window_call_rate_policy(
|
2992
|
+
self, model: FixedWindowCallRatePolicyModel, config: Config, **kwargs: Any
|
2993
|
+
) -> FixedWindowCallRatePolicy:
|
2994
|
+
matchers = [
|
2995
|
+
self._create_component_from_model(model=matcher, config=config)
|
2996
|
+
for matcher in model.matchers
|
2997
|
+
]
|
2998
|
+
return FixedWindowCallRatePolicy(
|
2999
|
+
next_reset_ts=model.next_reset_ts,
|
3000
|
+
period=parse_duration(model.period),
|
3001
|
+
call_limit=model.call_limit,
|
3002
|
+
matchers=matchers,
|
3003
|
+
)
|
3004
|
+
|
3005
|
+
def create_moving_window_call_rate_policy(
|
3006
|
+
self, model: MovingWindowCallRatePolicyModel, config: Config, **kwargs: Any
|
3007
|
+
) -> MovingWindowCallRatePolicy:
|
3008
|
+
rates = [
|
3009
|
+
self._create_component_from_model(model=rate, config=config) for rate in model.rates
|
3010
|
+
]
|
3011
|
+
matchers = [
|
3012
|
+
self._create_component_from_model(model=matcher, config=config)
|
3013
|
+
for matcher in model.matchers
|
3014
|
+
]
|
3015
|
+
return MovingWindowCallRatePolicy(
|
3016
|
+
rates=rates,
|
3017
|
+
matchers=matchers,
|
3018
|
+
)
|
3019
|
+
|
3020
|
+
def create_unlimited_call_rate_policy(
|
3021
|
+
self, model: UnlimitedCallRatePolicyModel, config: Config, **kwargs: Any
|
3022
|
+
) -> UnlimitedCallRatePolicy:
|
3023
|
+
matchers = [
|
3024
|
+
self._create_component_from_model(model=matcher, config=config)
|
3025
|
+
for matcher in model.matchers
|
3026
|
+
]
|
3027
|
+
|
3028
|
+
return UnlimitedCallRatePolicy(
|
3029
|
+
matchers=matchers,
|
3030
|
+
)
|
3031
|
+
|
3032
|
+
def create_rate(self, model: RateModel, config: Config, **kwargs: Any) -> Rate:
|
3033
|
+
return Rate(
|
3034
|
+
limit=model.limit,
|
3035
|
+
interval=model.interval,
|
3036
|
+
)
|
3037
|
+
|
3038
|
+
def create_http_request_matcher(
|
3039
|
+
self, model: HttpRequestMatcherModel, config: Config, **kwargs: Any
|
3040
|
+
) -> HttpRequestMatcher:
|
3041
|
+
return HttpRequestMatcher(
|
3042
|
+
method=model.method,
|
3043
|
+
url_base=model.url_base,
|
3044
|
+
url_path_pattern=model.url_path_pattern,
|
3045
|
+
params=model.params,
|
3046
|
+
headers=model.headers,
|
3047
|
+
)
|
3048
|
+
|
3049
|
+
def set_api_budget(self, component_definition: ComponentDefinition, config: Config) -> None:
|
3050
|
+
model_str = component_definition.get("type")
|
3051
|
+
if model_str == "APIBudget":
|
3052
|
+
# Annotate model_type as a type that is a subclass of BaseModel
|
3053
|
+
model_type: Union[Type[APIBudgetModel], Type[HTTPAPIBudgetModel]] = APIBudgetModel
|
3054
|
+
elif model_str == "HTTPAPIBudget":
|
3055
|
+
model_type = HTTPAPIBudgetModel
|
3056
|
+
else:
|
3057
|
+
raise ValueError(f"Unknown API Budget type: {model_str}")
|
3058
|
+
|
3059
|
+
# create_component expects a type[BaseModel] and returns an instance of that model.
|
3060
|
+
self._api_budget = self.create_component(
|
3061
|
+
model_type=model_type, component_definition=component_definition, config=config
|
3062
|
+
)
|
@@ -22,6 +22,7 @@ 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
|
25
26
|
from airbyte_cdk.sources.streams.http import HttpClient
|
26
27
|
from airbyte_cdk.sources.streams.http.error_handlers import ErrorHandler
|
27
28
|
from airbyte_cdk.sources.types import Config, StreamSlice, StreamState
|
@@ -55,6 +56,7 @@ class HttpRequester(Requester):
|
|
55
56
|
http_method: Union[str, HttpMethod] = HttpMethod.GET
|
56
57
|
request_options_provider: Optional[InterpolatedRequestOptionsProvider] = None
|
57
58
|
error_handler: Optional[ErrorHandler] = None
|
59
|
+
api_budget: Optional[APIBudget] = None
|
58
60
|
disable_retries: bool = False
|
59
61
|
message_repository: MessageRepository = NoopMessageRepository()
|
60
62
|
use_cache: bool = False
|
@@ -91,6 +93,7 @@ class HttpRequester(Requester):
|
|
91
93
|
name=self.name,
|
92
94
|
logger=self.logger,
|
93
95
|
error_handler=self.error_handler,
|
96
|
+
api_budget=self.api_budget,
|
94
97
|
authenticator=self._authenticator,
|
95
98
|
use_cache=self.use_cache,
|
96
99
|
backoff_strategy=backoff_strategies,
|
@@ -6,10 +6,12 @@ import abc
|
|
6
6
|
import dataclasses
|
7
7
|
import datetime
|
8
8
|
import logging
|
9
|
+
import re
|
9
10
|
import time
|
11
|
+
from dataclasses import InitVar, dataclass, field
|
10
12
|
from datetime import timedelta
|
11
13
|
from threading import RLock
|
12
|
-
from typing import TYPE_CHECKING, Any, Mapping, Optional
|
14
|
+
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union
|
13
15
|
from urllib import parse
|
14
16
|
|
15
17
|
import requests
|
@@ -98,43 +100,55 @@ class RequestMatcher(abc.ABC):
|
|
98
100
|
|
99
101
|
|
100
102
|
class HttpRequestMatcher(RequestMatcher):
|
101
|
-
"""
|
103
|
+
"""
|
104
|
+
Extended RequestMatcher for HTTP requests that supports matching on:
|
105
|
+
- HTTP method (case-insensitive)
|
106
|
+
- URL base (scheme + netloc) optionally
|
107
|
+
- URL path pattern (a regex applied to the path portion of the URL)
|
108
|
+
- Query parameters (must be present)
|
109
|
+
- Headers (header names compared case-insensitively)
|
110
|
+
"""
|
102
111
|
|
103
112
|
def __init__(
|
104
113
|
self,
|
105
114
|
method: Optional[str] = None,
|
106
|
-
|
115
|
+
url_base: Optional[str] = None,
|
116
|
+
url_path_pattern: Optional[str] = None,
|
107
117
|
params: Optional[Mapping[str, Any]] = None,
|
108
118
|
headers: Optional[Mapping[str, Any]] = None,
|
109
119
|
):
|
110
|
-
"""Constructor
|
111
|
-
|
112
|
-
:param method:
|
113
|
-
:param url:
|
114
|
-
:param params:
|
115
|
-
:param headers:
|
116
120
|
"""
|
117
|
-
|
118
|
-
|
121
|
+
:param method: HTTP method (e.g. "GET", "POST"); compared case-insensitively.
|
122
|
+
:param url_base: Base URL (scheme://host) that must match.
|
123
|
+
:param url_path_pattern: A regex pattern that will be applied to the path portion of the URL.
|
124
|
+
:param params: Dictionary of query parameters that must be present in the request.
|
125
|
+
:param headers: Dictionary of headers that must be present (header keys are compared case-insensitively).
|
126
|
+
"""
|
127
|
+
self._method = method.upper() if method else None
|
128
|
+
|
129
|
+
# Normalize the url_base if provided: remove trailing slash.
|
130
|
+
self._url_base = url_base.rstrip("/") if url_base else None
|
131
|
+
|
132
|
+
# Compile the URL path pattern if provided.
|
133
|
+
self._url_path_pattern = re.compile(url_path_pattern) if url_path_pattern else None
|
134
|
+
|
135
|
+
# Normalize query parameters to strings.
|
119
136
|
self._params = {str(k): str(v) for k, v in (params or {}).items()}
|
120
|
-
|
137
|
+
|
138
|
+
# Normalize header keys to lowercase.
|
139
|
+
self._headers = {str(k).lower(): str(v) for k, v in (headers or {}).items()}
|
121
140
|
|
122
141
|
@staticmethod
|
123
142
|
def _match_dict(obj: Mapping[str, Any], pattern: Mapping[str, Any]) -> bool:
|
124
|
-
"""Check that
|
125
|
-
|
126
|
-
:param obj:
|
127
|
-
:param pattern:
|
128
|
-
:return:
|
129
|
-
"""
|
143
|
+
"""Check that every key/value in the pattern exists in the object."""
|
130
144
|
return pattern.items() <= obj.items()
|
131
145
|
|
132
146
|
def __call__(self, request: Any) -> bool:
|
133
147
|
"""
|
134
|
-
|
135
|
-
:
|
136
|
-
:return: True if matches the provided request object, False - otherwise
|
148
|
+
:param request: A requests.Request or requests.PreparedRequest instance.
|
149
|
+
:return: True if the request matches all provided criteria; False otherwise.
|
137
150
|
"""
|
151
|
+
# Prepare the request (if needed) and extract the URL details.
|
138
152
|
if isinstance(request, requests.Request):
|
139
153
|
prepared_request = request.prepare()
|
140
154
|
elif isinstance(request, requests.PreparedRequest):
|
@@ -142,21 +156,40 @@ class HttpRequestMatcher(RequestMatcher):
|
|
142
156
|
else:
|
143
157
|
return False
|
144
158
|
|
145
|
-
|
146
|
-
|
159
|
+
# Check HTTP method.
|
160
|
+
if self._method is not None and prepared_request.method is not None:
|
161
|
+
if prepared_request.method.upper() != self._method:
|
147
162
|
return False
|
148
|
-
|
149
|
-
|
150
|
-
|
163
|
+
|
164
|
+
# Parse the URL.
|
165
|
+
parsed_url = parse.urlsplit(prepared_request.url)
|
166
|
+
# Reconstruct the base: scheme://netloc
|
167
|
+
request_url_base = f"{str(parsed_url.scheme)}://{str(parsed_url.netloc)}"
|
168
|
+
# The path (without query parameters)
|
169
|
+
request_path = str(parsed_url.path).rstrip("/")
|
170
|
+
|
171
|
+
# If a base URL is provided, check that it matches.
|
172
|
+
if self._url_base is not None:
|
173
|
+
if request_url_base != self._url_base:
|
151
174
|
return False
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
if not self.
|
175
|
+
|
176
|
+
# If a URL path pattern is provided, ensure the path matches the regex.
|
177
|
+
if self._url_path_pattern is not None:
|
178
|
+
if not self._url_path_pattern.search(request_path):
|
156
179
|
return False
|
157
|
-
|
158
|
-
|
180
|
+
|
181
|
+
# Check query parameters.
|
182
|
+
if self._params:
|
183
|
+
query_params = dict(parse.parse_qsl(str(parsed_url.query)))
|
184
|
+
if not self._match_dict(query_params, self._params):
|
159
185
|
return False
|
186
|
+
|
187
|
+
# Check headers (normalize keys to lower-case).
|
188
|
+
if self._headers:
|
189
|
+
req_headers = {k.lower(): v for k, v in prepared_request.headers.items()}
|
190
|
+
if not self._match_dict(req_headers, self._headers):
|
191
|
+
return False
|
192
|
+
|
160
193
|
return True
|
161
194
|
|
162
195
|
|
@@ -399,24 +432,17 @@ class AbstractAPIBudget(abc.ABC):
|
|
399
432
|
"""
|
400
433
|
|
401
434
|
|
435
|
+
@dataclass
|
402
436
|
class APIBudget(AbstractAPIBudget):
|
403
|
-
"""
|
404
|
-
|
405
|
-
|
406
|
-
self, policies: list[AbstractCallRatePolicy], maximum_attempts_to_acquire: int = 100000
|
407
|
-
) -> None:
|
408
|
-
"""Constructor
|
409
|
-
|
410
|
-
:param policies: list of policies in this budget
|
411
|
-
:param maximum_attempts_to_acquire: number of attempts before throwing hit ratelimit exception, we put some big number here
|
412
|
-
to avoid situations when many threads compete with each other for a few lots over a significant amount of time
|
413
|
-
"""
|
437
|
+
"""
|
438
|
+
Default APIBudget implementation.
|
439
|
+
"""
|
414
440
|
|
415
|
-
|
416
|
-
|
441
|
+
policies: list[AbstractCallRatePolicy]
|
442
|
+
maximum_attempts_to_acquire: int = 100000
|
417
443
|
|
418
444
|
def get_matching_policy(self, request: Any) -> Optional[AbstractCallRatePolicy]:
|
419
|
-
for policy in self.
|
445
|
+
for policy in self.policies:
|
420
446
|
if policy.matches(request):
|
421
447
|
return policy
|
422
448
|
return None
|
@@ -437,7 +463,7 @@ class APIBudget(AbstractAPIBudget):
|
|
437
463
|
policy = self.get_matching_policy(request)
|
438
464
|
if policy:
|
439
465
|
self._do_acquire(request=request, policy=policy, block=block, timeout=timeout)
|
440
|
-
elif self.
|
466
|
+
elif self.policies:
|
441
467
|
logger.info("no policies matched with requests, allow call by default")
|
442
468
|
|
443
469
|
def update_from_response(self, request: Any, response: Any) -> None:
|
@@ -460,7 +486,7 @@ class APIBudget(AbstractAPIBudget):
|
|
460
486
|
"""
|
461
487
|
last_exception = None
|
462
488
|
# sometimes we spend all budget before a second attempt, so we have few more here
|
463
|
-
for attempt in range(1, self.
|
489
|
+
for attempt in range(1, self.maximum_attempts_to_acquire):
|
464
490
|
try:
|
465
491
|
policy.try_acquire(request, weight=1)
|
466
492
|
return
|
@@ -484,31 +510,18 @@ class APIBudget(AbstractAPIBudget):
|
|
484
510
|
|
485
511
|
if last_exception:
|
486
512
|
logger.info(
|
487
|
-
"we used all %s attempts to acquire and failed", self.
|
513
|
+
"we used all %s attempts to acquire and failed", self.maximum_attempts_to_acquire
|
488
514
|
)
|
489
515
|
raise last_exception
|
490
516
|
|
491
517
|
|
518
|
+
@dataclass
|
492
519
|
class HttpAPIBudget(APIBudget):
|
493
520
|
"""Implementation of AbstractAPIBudget for HTTP"""
|
494
521
|
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
ratelimit_remaining_header: str = "ratelimit-remaining",
|
499
|
-
status_codes_for_ratelimit_hit: tuple[int] = (429,),
|
500
|
-
**kwargs: Any,
|
501
|
-
):
|
502
|
-
"""Constructor
|
503
|
-
|
504
|
-
:param ratelimit_reset_header: name of the header that has a timestamp of the next reset of call budget
|
505
|
-
:param ratelimit_remaining_header: name of the header that has the number of calls left
|
506
|
-
:param status_codes_for_ratelimit_hit: list of HTTP status codes that signal about rate limit being hit
|
507
|
-
"""
|
508
|
-
self._ratelimit_reset_header = ratelimit_reset_header
|
509
|
-
self._ratelimit_remaining_header = ratelimit_remaining_header
|
510
|
-
self._status_codes_for_ratelimit_hit = status_codes_for_ratelimit_hit
|
511
|
-
super().__init__(**kwargs)
|
522
|
+
ratelimit_reset_header: str = "ratelimit-reset"
|
523
|
+
ratelimit_remaining_header: str = "ratelimit-remaining"
|
524
|
+
status_codes_for_ratelimit_hit: Union[tuple[int], list[int]] = (429,)
|
512
525
|
|
513
526
|
def update_from_response(self, request: Any, response: Any) -> None:
|
514
527
|
policy = self.get_matching_policy(request)
|
@@ -523,17 +536,17 @@ class HttpAPIBudget(APIBudget):
|
|
523
536
|
def get_reset_ts_from_response(
|
524
537
|
self, response: requests.Response
|
525
538
|
) -> Optional[datetime.datetime]:
|
526
|
-
if response.headers.get(self.
|
539
|
+
if response.headers.get(self.ratelimit_reset_header):
|
527
540
|
return datetime.datetime.fromtimestamp(
|
528
|
-
int(response.headers[self.
|
541
|
+
int(response.headers[self.ratelimit_reset_header])
|
529
542
|
)
|
530
543
|
return None
|
531
544
|
|
532
545
|
def get_calls_left_from_response(self, response: requests.Response) -> Optional[int]:
|
533
|
-
if response.headers.get(self.
|
534
|
-
return int(response.headers[self.
|
546
|
+
if response.headers.get(self.ratelimit_remaining_header):
|
547
|
+
return int(response.headers[self.ratelimit_remaining_header])
|
535
548
|
|
536
|
-
if response.status_code in self.
|
549
|
+
if response.status_code in self.status_codes_for_ratelimit_hit:
|
537
550
|
return 0
|
538
551
|
|
539
552
|
return None
|
@@ -67,7 +67,7 @@ airbyte_cdk/sources/declarative/concurrent_declarative_source.py,sha256=x5a_Wv0c
|
|
67
67
|
airbyte_cdk/sources/declarative/datetime/__init__.py,sha256=l9LG7Qm6e5r_qgqfVKnx3mXYtg1I9MmMjomVIPfU4XA,177
|
68
68
|
airbyte_cdk/sources/declarative/datetime/datetime_parser.py,sha256=SX9JjdesN1edN2WVUVMzU_ptqp2QB1OnsnjZ4mwcX7w,2579
|
69
69
|
airbyte_cdk/sources/declarative/datetime/min_max_datetime.py,sha256=0BHBtDNQZfvwM45-tY5pNlTcKAFSGGNxemoi0Jic-0E,5785
|
70
|
-
airbyte_cdk/sources/declarative/declarative_component_schema.yaml,sha256=
|
70
|
+
airbyte_cdk/sources/declarative/declarative_component_schema.yaml,sha256=MOzhkZUsmcFiSP1ES_eEQyAta_ms5zG5IEA9XwooR8M,147035
|
71
71
|
airbyte_cdk/sources/declarative/declarative_source.py,sha256=nF7wBqFd3AQmEKAm4CnIo29CJoQL562cJGSCeL8U8bA,1531
|
72
72
|
airbyte_cdk/sources/declarative/declarative_stream.py,sha256=venZjfpvtqr3oFSuvMBWtn4h9ayLhD4L65ACuXCDZ64,10445
|
73
73
|
airbyte_cdk/sources/declarative/decoders/__init__.py,sha256=KSpQetKGqPCv-38QgcVJ5kzM5nzbFldTSsYDCS3Xf0Y,1035
|
@@ -104,18 +104,18 @@ airbyte_cdk/sources/declarative/interpolation/interpolated_string.py,sha256=LYEZ
|
|
104
104
|
airbyte_cdk/sources/declarative/interpolation/interpolation.py,sha256=-V5UddGm69UKEB6o_O1EIES9kfY8FV_X4Ji8w1yOuSA,981
|
105
105
|
airbyte_cdk/sources/declarative/interpolation/jinja.py,sha256=BtsY_jtT4MihFqeQgc05HXj3Ndt-e2ESQgGwbg3Sdxc,6430
|
106
106
|
airbyte_cdk/sources/declarative/interpolation/macros.py,sha256=Y5AWYxbJTUtJ_Jm7DV9qrZDiymFR9LST7fBt4piT2-U,4585
|
107
|
-
airbyte_cdk/sources/declarative/manifest_declarative_source.py,sha256=
|
107
|
+
airbyte_cdk/sources/declarative/manifest_declarative_source.py,sha256=TN6GCgLXaWDONTaJwQ3A5ELqC-sxwKz-UYSraJYB-dI,17078
|
108
108
|
airbyte_cdk/sources/declarative/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
109
109
|
airbyte_cdk/sources/declarative/migrations/legacy_to_per_partition_state_migration.py,sha256=iemy3fKLczcU0-Aor7tx5jcT6DRedKMqyK7kCOp01hg,3924
|
110
110
|
airbyte_cdk/sources/declarative/migrations/state_migration.py,sha256=KWPjealMLKSMtajXgkdGgKg7EmTLR-CqqD7UIh0-eDU,794
|
111
111
|
airbyte_cdk/sources/declarative/models/__init__.py,sha256=nUFxNCiKeYRVXuZEKA7GD-lTHxsiKcQ8FitZjKhPIvE,100
|
112
|
-
airbyte_cdk/sources/declarative/models/declarative_component_schema.py,sha256=
|
112
|
+
airbyte_cdk/sources/declarative/models/declarative_component_schema.py,sha256=gRRQoZ4VAuyxtBALvHQnGMF9rOLgPSLSBp0yzWW-w4Y,103695
|
113
113
|
airbyte_cdk/sources/declarative/parsers/__init__.py,sha256=ZnqYNxHsKCgO38IwB34RQyRMXTs4GTvlRi3ImKnIioo,61
|
114
114
|
airbyte_cdk/sources/declarative/parsers/custom_code_compiler.py,sha256=958MMX6_ZOJUlDDdNr9Krosgi2bCKGx2Z765M2Woz18,5505
|
115
115
|
airbyte_cdk/sources/declarative/parsers/custom_exceptions.py,sha256=Rir9_z3Kcd5Es0-LChrzk-0qubAsiK_RSEnLmK2OXm8,553
|
116
116
|
airbyte_cdk/sources/declarative/parsers/manifest_component_transformer.py,sha256=CXwTfD3wSQq3okcqwigpprbHhSURUokh4GK2OmOyKC8,9132
|
117
117
|
airbyte_cdk/sources/declarative/parsers/manifest_reference_resolver.py,sha256=IWUOdF03o-aQn0Occo1BJCxU0Pz-QILk5L67nzw2thw,6803
|
118
|
-
airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py,sha256=
|
118
|
+
airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py,sha256=ee3BYsYxpGH3D6fLb8BWpGG1HFHcAgFRsCJXUO98nbA,134255
|
119
119
|
airbyte_cdk/sources/declarative/partition_routers/__init__.py,sha256=HJ-Syp3p7RpyR_OK0X_a2kSyISfu3W-PKrRI16iY0a8,957
|
120
120
|
airbyte_cdk/sources/declarative/partition_routers/async_job_partition_router.py,sha256=VelO7zKqKtzMJ35jyFeg0ypJLQC0plqqIBNXoBW1G2E,3001
|
121
121
|
airbyte_cdk/sources/declarative/partition_routers/cartesian_product_stream_slicer.py,sha256=c5cuVFM6NFkuQqG8Z5IwkBuwDrvXZN1CunUOM_L0ezg,6892
|
@@ -139,7 +139,7 @@ airbyte_cdk/sources/declarative/requesters/error_handlers/default_http_response_
|
|
139
139
|
airbyte_cdk/sources/declarative/requesters/error_handlers/error_handler.py,sha256=Tan66odx8VHzfdyyXMQkXz2pJYksllGqvxmpoajgcK4,669
|
140
140
|
airbyte_cdk/sources/declarative/requesters/error_handlers/http_response_filter.py,sha256=E-fQbt4ShfxZVoqfnmOx69C6FUPWZz8BIqI3DN9Kcjs,7935
|
141
141
|
airbyte_cdk/sources/declarative/requesters/http_job_repository.py,sha256=3GtOefPH08evlSUxaILkiKLTHbIspFY4qd5B3ZqNE60,10063
|
142
|
-
airbyte_cdk/sources/declarative/requesters/http_requester.py,sha256=
|
142
|
+
airbyte_cdk/sources/declarative/requesters/http_requester.py,sha256=F1lydK00pbImprvauxzsFiy_IpQI59iErqtuf2vES1Q,14866
|
143
143
|
airbyte_cdk/sources/declarative/requesters/paginators/__init__.py,sha256=uArbKs9JKNCt7t9tZoeWwjDpyI1HoPp29FNW0JzvaEM,644
|
144
144
|
airbyte_cdk/sources/declarative/requesters/paginators/default_paginator.py,sha256=FnSl3qPvv5wD6ieAI2Ic5c4dqBk-3fRe4tCaWzq3YwM,11840
|
145
145
|
airbyte_cdk/sources/declarative/requesters/paginators/no_pagination.py,sha256=j6j9QRPaTbKQ2N661RFVKthhkWiodEp6ut0tKeEd0Ng,2019
|
@@ -249,7 +249,7 @@ airbyte_cdk/sources/message/repository.py,sha256=SG7avgti_-dj8FcRHTTrhgLLGJbElv1
|
|
249
249
|
airbyte_cdk/sources/source.py,sha256=KIBBH5VLEb8BZ8B9aROlfaI6OLoJqKDPMJ10jkAR7nk,3611
|
250
250
|
airbyte_cdk/sources/streams/__init__.py,sha256=8fzTKpRTnSx5PggXgQPKJzHNZUV2BCA40N-dI6JM1xI,256
|
251
251
|
airbyte_cdk/sources/streams/availability_strategy.py,sha256=_RU4JITrxMEN36g1RDHMu0iSw0I_3yWGfo5N8_YRvOg,3247
|
252
|
-
airbyte_cdk/sources/streams/call_rate.py,sha256=
|
252
|
+
airbyte_cdk/sources/streams/call_rate.py,sha256=sf_AvWe6R_CqGkn1dnwQiDROBEvRESrPUv-zQeQ91Es,21779
|
253
253
|
airbyte_cdk/sources/streams/checkpoint/__init__.py,sha256=3oy7Hd4ivVWTZlN6dKAf4Fv_G7U5iZrvhO9hT871UIo,712
|
254
254
|
airbyte_cdk/sources/streams/checkpoint/checkpoint_reader.py,sha256=6HMT2NI-FQuaW0nt95NcyWrt5rZN4gF-Arx0sxdgbv4,15221
|
255
255
|
airbyte_cdk/sources/streams/checkpoint/cursor.py,sha256=3e-3c-54k8U7Awno7DMmAD9ndbnl9OM48EnbEgeDUO0,3499
|
@@ -351,9 +351,9 @@ airbyte_cdk/utils/slice_hasher.py,sha256=EDxgROHDbfG-QKQb59m7h_7crN1tRiawdf5uU7G
|
|
351
351
|
airbyte_cdk/utils/spec_schema_transformations.py,sha256=-5HTuNsnDBAhj-oLeQXwpTGA0HdcjFOf2zTEMUTTg_Y,816
|
352
352
|
airbyte_cdk/utils/stream_status_utils.py,sha256=ZmBoiy5HVbUEHAMrUONxZvxnvfV9CesmQJLDTAIWnWw,1171
|
353
353
|
airbyte_cdk/utils/traced_exception.py,sha256=C8uIBuCL_E4WnBAOPSxBicD06JAldoN9fGsQDp463OY,6292
|
354
|
-
airbyte_cdk-6.
|
355
|
-
airbyte_cdk-6.
|
356
|
-
airbyte_cdk-6.
|
357
|
-
airbyte_cdk-6.
|
358
|
-
airbyte_cdk-6.
|
359
|
-
airbyte_cdk-6.
|
354
|
+
airbyte_cdk-6.33.0.dev0.dist-info/LICENSE.txt,sha256=Wfe61S4BaGPj404v8lrAbvhjYR68SHlkzeYrg3_bbuM,1051
|
355
|
+
airbyte_cdk-6.33.0.dev0.dist-info/LICENSE_SHORT,sha256=aqF6D1NcESmpn-cqsxBtszTEnHKnlsp8L4x9wAh3Nxg,55
|
356
|
+
airbyte_cdk-6.33.0.dev0.dist-info/METADATA,sha256=U-Epy8I3SzZzuU46_xkRtIpomk90rBI5BSigUTU4Sa4,6015
|
357
|
+
airbyte_cdk-6.33.0.dev0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
358
|
+
airbyte_cdk-6.33.0.dev0.dist-info/entry_points.txt,sha256=fj-e3PAQvsxsQzyyq8UkG1k8spunWnD4BAH2AwlR6NM,95
|
359
|
+
airbyte_cdk-6.33.0.dev0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|