dlt-utils 0.7.0__tar.gz → 0.7.2__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dlt_utils
3
- Version: 0.7.0
3
+ Version: 0.7.2
4
4
  Summary: Shared utilities for dlt data pipelines with multi-company support
5
5
  Author: Jay van den Bos
6
6
  License: MIT
@@ -20,6 +20,7 @@ Description-Content-Type: text/markdown
20
20
  Requires-Dist: dlt>=1.19.1
21
21
  Requires-Dist: azure-identity>=1.15.0
22
22
  Requires-Dist: azure-keyvault-secrets>=4.8.0
23
+ Requires-Dist: pendulum>=3.0.0
23
24
  Provides-Extra: dev
24
25
  Requires-Dist: pytest>=7.0; extra == "dev"
25
26
  Requires-Dist: pytest-cov; extra == "dev"
@@ -10,6 +10,7 @@ multiple companies/tenants, including:
10
10
  - CLI argument parsing with standard arguments
11
11
  - Logging configuration
12
12
  - Pipeline helpers
13
+ - Authentication: OAuth2 with proactive token refresh
13
14
  """
14
15
 
15
16
  from .incremental import PartitionedIncremental
@@ -30,6 +31,7 @@ from .args import (
30
31
  resolve_start_year,
31
32
  )
32
33
  from .azure_keyvault import AzureKeyVault
34
+ from .auth import BufferedOAuth2ClientCredentials
33
35
  from .logging import configure_logging
34
36
  from .pipeline import (
35
37
  cleanup_tombstones,
@@ -43,7 +45,7 @@ from .pipeline import (
43
45
  )
44
46
 
45
47
 
46
- __version__ = "0.7.0"
48
+ __version__ = "0.7.2"
47
49
 
48
50
  __all__ = [
49
51
  # Incremental
@@ -63,6 +65,9 @@ __all__ = [
63
65
  "resolve_start_year",
64
66
  # azure_keyvault
65
67
  "AzureKeyVault",
68
+ # auth
69
+ "BufferedOAuth2ClientCredentials",
70
+ "OAUTH_REFRESH_BUFFER_SECONDS",
66
71
  # logging
67
72
  "configure_logging",
68
73
  # pipeline
@@ -0,0 +1,88 @@
1
+ """
2
+ Authentication utilities for dlt pipelines.
3
+
4
+ This module provides authentication helpers including OAuth2 client credentials
5
+ with proactive token refresh.
6
+ """
7
+
8
+ import logging
9
+
10
+ import pendulum
11
+ from dlt.sources.helpers.rest_client.auth import OAuth2ClientCredentials
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+ # Default buffer in seconds to refresh OAuth token before expiry
16
+ OAUTH_REFRESH_BUFFER_SECONDS = 120
17
+
18
+
19
+ class BufferedOAuth2ClientCredentials(OAuth2ClientCredentials):
20
+ """
21
+ OAuth2 client credentials auth with proactive refresh buffer.
22
+
23
+ dlt refreshes just-in-time based on token expiry. This subclass refreshes
24
+ earlier to avoid edge cases around network latency and clock skew.
25
+
26
+ The buffer works by marking the token as expired earlier than its actual expiry time.
27
+ For example, if a token has expires_in=3600 seconds (1 hour) and the buffer is 120
28
+ seconds, the token will be refreshed after 3480 seconds (3600 - 120), giving a
29
+ 120-second safety margin before actual expiry.
30
+
31
+ Args:
32
+ refresh_buffer_seconds: Seconds before actual expiry to refresh token (default: 120)
33
+ forced_expires_in_seconds: Override the expires_in from token response (optional)
34
+
35
+ Example:
36
+ ```python
37
+ from dlt_utils import BufferedOAuth2ClientCredentials
38
+
39
+ # Use default 120-second buffer
40
+ auth = BufferedOAuth2ClientCredentials(
41
+ client_id="...",
42
+ client_secret="...",
43
+ token_url="https://..."
44
+ )
45
+
46
+ # Use custom 300-second buffer
47
+ auth = BufferedOAuth2ClientCredentials(
48
+ client_id="...",
49
+ client_secret="...",
50
+ token_url="https://...",
51
+ refresh_buffer_seconds=300
52
+ )
53
+ ```
54
+ """
55
+
56
+ refresh_buffer_seconds: int = OAUTH_REFRESH_BUFFER_SECONDS
57
+ forced_expires_in_seconds: int | None = None
58
+
59
+ def __init__(
60
+ self,
61
+ *args: object,
62
+ refresh_buffer_seconds: int = OAUTH_REFRESH_BUFFER_SECONDS,
63
+ forced_expires_in_seconds: int | None = None,
64
+ **kwargs: object,
65
+ ) -> None:
66
+ super().__init__(*args, **kwargs)
67
+ self.refresh_buffer_seconds = refresh_buffer_seconds
68
+ self.forced_expires_in_seconds = forced_expires_in_seconds
69
+
70
+ def is_token_expired(self) -> bool:
71
+ return (
72
+ self.token_expiry is None
73
+ or pendulum.now().add(seconds=self.refresh_buffer_seconds)
74
+ >= self.token_expiry
75
+ )
76
+
77
+ def obtain_token(self) -> None:
78
+ super().obtain_token()
79
+ if self.forced_expires_in_seconds is not None:
80
+ self.token_expiry = pendulum.now().add(
81
+ seconds=self.forced_expires_in_seconds
82
+ )
83
+ logger.debug(
84
+ "OAuth token refreshed; expires_at=%s (buffer=%ss, forced_expires_in=%s)",
85
+ self.token_expiry,
86
+ self.refresh_buffer_seconds,
87
+ self.forced_expires_in_seconds,
88
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dlt_utils
3
- Version: 0.7.0
3
+ Version: 0.7.2
4
4
  Summary: Shared utilities for dlt data pipelines with multi-company support
5
5
  Author: Jay van den Bos
6
6
  License: MIT
@@ -20,6 +20,7 @@ Description-Content-Type: text/markdown
20
20
  Requires-Dist: dlt>=1.19.1
21
21
  Requires-Dist: azure-identity>=1.15.0
22
22
  Requires-Dist: azure-keyvault-secrets>=4.8.0
23
+ Requires-Dist: pendulum>=3.0.0
23
24
  Provides-Extra: dev
24
25
  Requires-Dist: pytest>=7.0; extra == "dev"
25
26
  Requires-Dist: pytest-cov; extra == "dev"
@@ -2,6 +2,7 @@ README.md
2
2
  pyproject.toml
3
3
  dlt_utils/__init__.py
4
4
  dlt_utils/args.py
5
+ dlt_utils/auth.py
5
6
  dlt_utils/azure_keyvault.py
6
7
  dlt_utils/dates.py
7
8
  dlt_utils/incremental.py
@@ -1,6 +1,7 @@
1
1
  dlt>=1.19.1
2
2
  azure-identity>=1.15.0
3
3
  azure-keyvault-secrets>=4.8.0
4
+ pendulum>=3.0.0
4
5
 
5
6
  [dev]
6
7
  pytest>=7.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "dlt_utils"
7
- version = "0.7.0"
7
+ version = "0.7.2"
8
8
  description = "Shared utilities for dlt data pipelines with multi-company support"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -27,6 +27,7 @@ dependencies = [
27
27
  "dlt>=1.19.1",
28
28
  "azure-identity>=1.15.0",
29
29
  "azure-keyvault-secrets>=4.8.0",
30
+ "pendulum>=3.0.0",
30
31
  ]
31
32
 
32
33
  [project.optional-dependencies]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes