atlan-application-sdk 0.1.1rc32__py3-none-any.whl → 0.1.1rc34__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.
- application_sdk/activities/metadata_extraction/base.py +102 -0
- application_sdk/application/__init__.py +8 -0
- application_sdk/clients/async_atlan.py +70 -0
- application_sdk/clients/base.py +293 -0
- application_sdk/handlers/base.py +50 -0
- application_sdk/server/fastapi/models.py +1 -1
- application_sdk/version.py +1 -1
- {atlan_application_sdk-0.1.1rc32.dist-info → atlan_application_sdk-0.1.1rc34.dist-info}/METADATA +3 -3
- {atlan_application_sdk-0.1.1rc32.dist-info → atlan_application_sdk-0.1.1rc34.dist-info}/RECORD +12 -8
- {atlan_application_sdk-0.1.1rc32.dist-info → atlan_application_sdk-0.1.1rc34.dist-info}/WHEEL +0 -0
- {atlan_application_sdk-0.1.1rc32.dist-info → atlan_application_sdk-0.1.1rc34.dist-info}/licenses/LICENSE +0 -0
- {atlan_application_sdk-0.1.1rc32.dist-info → atlan_application_sdk-0.1.1rc34.dist-info}/licenses/NOTICE +0 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional, Type
|
|
2
|
+
|
|
3
|
+
from temporalio import activity
|
|
4
|
+
|
|
5
|
+
from application_sdk.activities import ActivitiesInterface, ActivitiesState
|
|
6
|
+
from application_sdk.activities.common.utils import get_workflow_id
|
|
7
|
+
from application_sdk.clients.base import BaseClient
|
|
8
|
+
from application_sdk.common.credential_utils import get_credentials
|
|
9
|
+
from application_sdk.constants import APP_TENANT_ID, APPLICATION_NAME
|
|
10
|
+
from application_sdk.handlers.base import BaseHandler
|
|
11
|
+
from application_sdk.observability.logger_adaptor import get_logger
|
|
12
|
+
from application_sdk.transformers import TransformerInterface
|
|
13
|
+
|
|
14
|
+
logger = get_logger(__name__)
|
|
15
|
+
activity.logger = logger
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class BaseMetadataExtractionActivitiesState(ActivitiesState):
|
|
19
|
+
"""State for base metadata extraction activities."""
|
|
20
|
+
|
|
21
|
+
client: Optional[BaseClient] = None
|
|
22
|
+
handler: Optional[BaseHandler] = None
|
|
23
|
+
transformer: Optional[TransformerInterface] = None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class BaseMetadataExtractionActivities(ActivitiesInterface):
|
|
27
|
+
"""Base activities for non-SQL metadata extraction workflows."""
|
|
28
|
+
|
|
29
|
+
_state: Dict[str, BaseMetadataExtractionActivitiesState] = {}
|
|
30
|
+
|
|
31
|
+
client_class: Type[BaseClient] = BaseClient
|
|
32
|
+
handler_class: Type[BaseHandler] = BaseHandler
|
|
33
|
+
transformer_class: Optional[Type[TransformerInterface]] = None
|
|
34
|
+
|
|
35
|
+
def __init__(
|
|
36
|
+
self,
|
|
37
|
+
client_class: Optional[Type[BaseClient]] = None,
|
|
38
|
+
handler_class: Optional[Type[BaseHandler]] = None,
|
|
39
|
+
transformer_class: Optional[Type[TransformerInterface]] = None,
|
|
40
|
+
):
|
|
41
|
+
"""Initialize the base metadata extraction activities.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
client_class: Client class to use. Defaults to BaseClient.
|
|
45
|
+
handler_class: Handler class to use. Defaults to BaseHandler.
|
|
46
|
+
transformer_class: Transformer class to use. Users must provide their own transformer implementation.
|
|
47
|
+
"""
|
|
48
|
+
if client_class:
|
|
49
|
+
self.client_class = client_class
|
|
50
|
+
if handler_class:
|
|
51
|
+
self.handler_class = handler_class
|
|
52
|
+
if transformer_class:
|
|
53
|
+
self.transformer_class = transformer_class
|
|
54
|
+
|
|
55
|
+
super().__init__()
|
|
56
|
+
|
|
57
|
+
async def _set_state(self, workflow_args: Dict[str, Any]):
|
|
58
|
+
"""Set up the state for the current workflow.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
workflow_args: Arguments for the workflow.
|
|
62
|
+
"""
|
|
63
|
+
workflow_id = get_workflow_id()
|
|
64
|
+
if not self._state.get(workflow_id):
|
|
65
|
+
self._state[workflow_id] = BaseMetadataExtractionActivitiesState()
|
|
66
|
+
|
|
67
|
+
await super()._set_state(workflow_args)
|
|
68
|
+
|
|
69
|
+
state = self._state[workflow_id]
|
|
70
|
+
|
|
71
|
+
# Initialize client
|
|
72
|
+
client = self.client_class()
|
|
73
|
+
# Extract credentials from state store if credential_guid is available
|
|
74
|
+
if "credential_guid" in workflow_args:
|
|
75
|
+
logger.info(
|
|
76
|
+
f"Retrieving credentials for credential_guid: {workflow_args['credential_guid']}"
|
|
77
|
+
)
|
|
78
|
+
try:
|
|
79
|
+
credentials = await get_credentials(workflow_args["credential_guid"])
|
|
80
|
+
logger.info(
|
|
81
|
+
f"Successfully retrieved credentials with keys: {list(credentials.keys())}"
|
|
82
|
+
)
|
|
83
|
+
# Load the client with credentials
|
|
84
|
+
await client.load(credentials=credentials)
|
|
85
|
+
except Exception as e:
|
|
86
|
+
logger.error(f"Failed to retrieve credentials: {e}")
|
|
87
|
+
raise
|
|
88
|
+
|
|
89
|
+
state.client = client
|
|
90
|
+
|
|
91
|
+
# Initialize handler
|
|
92
|
+
handler = self.handler_class(client=client)
|
|
93
|
+
state.handler = handler
|
|
94
|
+
|
|
95
|
+
# Initialize transformer if provided
|
|
96
|
+
if self.transformer_class:
|
|
97
|
+
transformer_params = {
|
|
98
|
+
"connector_name": APPLICATION_NAME,
|
|
99
|
+
"connector_type": APPLICATION_NAME,
|
|
100
|
+
"tenant_id": APP_TENANT_ID,
|
|
101
|
+
}
|
|
102
|
+
state.transformer = self.transformer_class(**transformer_params)
|
|
@@ -2,8 +2,10 @@ from concurrent.futures import ThreadPoolExecutor
|
|
|
2
2
|
from typing import Any, Dict, List, Optional, Tuple, Type
|
|
3
3
|
|
|
4
4
|
from application_sdk.activities import ActivitiesInterface
|
|
5
|
+
from application_sdk.clients.base import BaseClient
|
|
5
6
|
from application_sdk.clients.utils import get_workflow_client
|
|
6
7
|
from application_sdk.events.models import EventRegistration
|
|
8
|
+
from application_sdk.handlers.base import BaseHandler
|
|
7
9
|
from application_sdk.observability.logger_adaptor import get_logger
|
|
8
10
|
from application_sdk.server import ServerInterface
|
|
9
11
|
from application_sdk.server.fastapi import APIServer, HttpWorkflowTrigger
|
|
@@ -28,6 +30,8 @@ class BaseApplication:
|
|
|
28
30
|
name: str,
|
|
29
31
|
server: Optional[ServerInterface] = None,
|
|
30
32
|
application_manifest: Optional[dict] = None,
|
|
33
|
+
client_class: Optional[Type[BaseClient]] = None,
|
|
34
|
+
handler_class: Optional[Type[BaseHandler]] = None,
|
|
31
35
|
):
|
|
32
36
|
"""
|
|
33
37
|
Initialize the application.
|
|
@@ -48,6 +52,9 @@ class BaseApplication:
|
|
|
48
52
|
self.application_manifest: Dict[str, Any] = application_manifest
|
|
49
53
|
self.bootstrap_event_registration()
|
|
50
54
|
|
|
55
|
+
self.client_class = client_class or BaseClient
|
|
56
|
+
self.handler_class = handler_class or BaseHandler
|
|
57
|
+
|
|
51
58
|
def bootstrap_event_registration(self):
|
|
52
59
|
self.event_subscriptions = {}
|
|
53
60
|
if self.application_manifest is None:
|
|
@@ -168,6 +175,7 @@ class BaseApplication:
|
|
|
168
175
|
self.server = APIServer(
|
|
169
176
|
workflow_client=self.workflow_client,
|
|
170
177
|
ui_enabled=ui_enabled,
|
|
178
|
+
handler=self.handler_class(client=self.client_class()),
|
|
171
179
|
)
|
|
172
180
|
|
|
173
181
|
if self.event_subscriptions:
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from pyatlan.client.aio.client import AsyncAtlanClient
|
|
4
|
+
|
|
5
|
+
from application_sdk.common.error_codes import ClientError
|
|
6
|
+
from application_sdk.constants import (
|
|
7
|
+
ATLAN_API_KEY,
|
|
8
|
+
ATLAN_API_TOKEN_GUID,
|
|
9
|
+
ATLAN_BASE_URL,
|
|
10
|
+
ATLAN_CLIENT_ID,
|
|
11
|
+
ATLAN_CLIENT_SECRET,
|
|
12
|
+
)
|
|
13
|
+
from application_sdk.observability.logger_adaptor import get_logger
|
|
14
|
+
|
|
15
|
+
logger = get_logger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async def get_client(
|
|
19
|
+
base_url: Optional[str] = None,
|
|
20
|
+
api_key: Optional[str] = None,
|
|
21
|
+
api_token_guid: Optional[str] = None,
|
|
22
|
+
) -> AsyncAtlanClient:
|
|
23
|
+
"""
|
|
24
|
+
Returns an authenticated AsyncAtlanClient instance using provided parameters or environment variables.
|
|
25
|
+
|
|
26
|
+
Selects authentication method based on the presence of parameters or environment variables and validates the required configuration.
|
|
27
|
+
In general, the use of environment variables is recommended. Any parameters specified will override the environment variables.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
base_url: Atlan base URL (overrides ATLAN_BASE_URL)
|
|
31
|
+
api_key: Atlan API key (overrides ATLAN_API_KEY)
|
|
32
|
+
api_token_guid: API token GUID (overrides API_TOKEN_GUID)
|
|
33
|
+
"""
|
|
34
|
+
# Resolve final values (parameters override env vars)
|
|
35
|
+
final_token_guid = api_token_guid or ATLAN_API_TOKEN_GUID
|
|
36
|
+
final_base_url = base_url or ATLAN_BASE_URL
|
|
37
|
+
final_api_key = api_key or ATLAN_API_KEY
|
|
38
|
+
|
|
39
|
+
# Priority 1: Token-based auth (recommended for production)
|
|
40
|
+
if final_token_guid:
|
|
41
|
+
if final_base_url or final_api_key:
|
|
42
|
+
logger.warning(
|
|
43
|
+
"Token auth takes precedence - ignoring base_url/api_key parameters as well as ATLAN_BASE_URL and ATLAN_API_KEY environment variables."
|
|
44
|
+
)
|
|
45
|
+
return await _get_client_from_token(final_token_guid)
|
|
46
|
+
|
|
47
|
+
# Priority 2: API key + base URL auth
|
|
48
|
+
if not final_base_url:
|
|
49
|
+
raise ClientError(
|
|
50
|
+
"ATLAN_BASE_URL is required (via parameter or environment variable)"
|
|
51
|
+
)
|
|
52
|
+
if not final_api_key:
|
|
53
|
+
raise ClientError(
|
|
54
|
+
"ATLAN_API_KEY is required (via parameter or environment variable)"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
logger.info("Using API key-based authentication")
|
|
58
|
+
return AsyncAtlanClient(base_url=final_base_url, api_key=final_api_key)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
async def _get_client_from_token(api_token_guid: str):
|
|
62
|
+
if not ATLAN_CLIENT_ID:
|
|
63
|
+
raise ClientError(
|
|
64
|
+
f"{ClientError.AUTH_CONFIG_ERROR}: Environment variable CLIENT_ID is required when API_TOKEN_GUID is set."
|
|
65
|
+
)
|
|
66
|
+
if not ATLAN_CLIENT_SECRET:
|
|
67
|
+
raise ClientError(
|
|
68
|
+
f"{ClientError.AUTH_CONFIG_ERROR}: Environment variable CLIENT_SECRET is required when API_TOKEN_GUID is set."
|
|
69
|
+
)
|
|
70
|
+
return await AsyncAtlanClient.from_token_guid(guid=api_token_guid)
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional
|
|
2
|
+
|
|
3
|
+
import httpx
|
|
4
|
+
from httpx import Headers
|
|
5
|
+
from httpx._types import (
|
|
6
|
+
AuthTypes,
|
|
7
|
+
HeaderTypes,
|
|
8
|
+
QueryParamTypes,
|
|
9
|
+
RequestData,
|
|
10
|
+
RequestFiles,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
from application_sdk.clients import ClientInterface
|
|
14
|
+
from application_sdk.observability.logger_adaptor import get_logger
|
|
15
|
+
|
|
16
|
+
logger = get_logger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class BaseClient(ClientInterface):
|
|
20
|
+
"""
|
|
21
|
+
Base client for non-SQL based applications.
|
|
22
|
+
|
|
23
|
+
This class provides a base implementation for clients that need to connect
|
|
24
|
+
to non-SQL data sources. It implements the ClientInterface and provides
|
|
25
|
+
basic functionality that can be extended by subclasses.
|
|
26
|
+
|
|
27
|
+
Attributes:
|
|
28
|
+
credentials (Dict[str, Any]): Client credentials for authentication.
|
|
29
|
+
http_headers (HeaderTypes): HTTP headers for all http requests made by this client. Supports dict, Headers object, or list of tuples.
|
|
30
|
+
http_retry_transporter (httpx.AsyncBaseTransport): HTTP transport for requests. Uses httpx default transport by default.
|
|
31
|
+
Can be overridden in load() method for custom retry behavior.
|
|
32
|
+
|
|
33
|
+
Extending the Client:
|
|
34
|
+
To customize retry behavior, subclasses can override the http_retry_transporter
|
|
35
|
+
in the load() method, similar to how http_headers is set:
|
|
36
|
+
|
|
37
|
+
Example:
|
|
38
|
+
>>> class MyClient(BaseClient):
|
|
39
|
+
... async def load(self, **kwargs):
|
|
40
|
+
... # Set up HTTP headers in load method for better modularity
|
|
41
|
+
... credentials = kwargs.get("credentials", {})
|
|
42
|
+
... # Can use dict, Headers object, or list of tuples
|
|
43
|
+
... self.http_headers = {
|
|
44
|
+
... "Authorization": f"Bearer {credentials.get('token')}",
|
|
45
|
+
... "User-Agent": "MyApp/1.0"
|
|
46
|
+
... }
|
|
47
|
+
... # Optionally override retry transport with custom configuration
|
|
48
|
+
... # For advanced retry logic with status code handling, use httpx-retries:
|
|
49
|
+
... # from httpx_retries import Retry, RetryTransport
|
|
50
|
+
... # retry = Retry(total=5, backoff_factor=20)
|
|
51
|
+
... # self.http_retry_transporter = RetryTransport(retry=retry) #replace transport with custom transport if needed
|
|
52
|
+
|
|
53
|
+
Advanced Retry Configuration:
|
|
54
|
+
For applications requiring advanced retry logic (e.g., status code-based retries,
|
|
55
|
+
rate limiting, custom backoff strategies), consider using httpx-retries library:
|
|
56
|
+
|
|
57
|
+
>>> class MyClient(BaseClient):
|
|
58
|
+
... async def load(self, **kwargs):
|
|
59
|
+
... # Set up headers
|
|
60
|
+
... self.http_headers = {"Authorization": f"Bearer {kwargs.get('token')}"}
|
|
61
|
+
...
|
|
62
|
+
... # Install httpx-retries: pip install httpx-retries
|
|
63
|
+
... from httpx_retries import Retry, RetryTransport
|
|
64
|
+
...
|
|
65
|
+
... # Configure retry for status codes and network errors
|
|
66
|
+
... retry = Retry(
|
|
67
|
+
... total=5,
|
|
68
|
+
... backoff_factor=10,
|
|
69
|
+
... status_forcelist=[429, 500, 502, 503, 504]
|
|
70
|
+
... )
|
|
71
|
+
... self.http_retry_transporter = RetryTransport(retry=retry)
|
|
72
|
+
|
|
73
|
+
Header Management:
|
|
74
|
+
The client supports a two-level header system using httpx Headers for merging headers:
|
|
75
|
+
- Client-level headers: Set in the load() method and used for all requests
|
|
76
|
+
- Method-level headers: Passed to individual methods and override/add to client headers
|
|
77
|
+
|
|
78
|
+
Example:
|
|
79
|
+
>>> client = MyClient()
|
|
80
|
+
>>> await client.load(credentials={"token": "initial_token"})
|
|
81
|
+
>>> # This request will use: {"Authorization": "Bearer initial_token", "User-Agent": "MyApp/1.0", "Content-Type": "application/json"}
|
|
82
|
+
>>> response = await client.execute_http_post_request(
|
|
83
|
+
... url="https://api.example.com/data",
|
|
84
|
+
... headers={"Content-Type": "application/json"}
|
|
85
|
+
... )
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
def __init__(
|
|
89
|
+
self,
|
|
90
|
+
credentials: Dict[str, Any] = {},
|
|
91
|
+
http_headers: HeaderTypes = {},
|
|
92
|
+
):
|
|
93
|
+
"""
|
|
94
|
+
Initialize the base client.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
credentials (Dict[str, Any], optional): Client credentials for authentication. Defaults to {}.
|
|
98
|
+
http_headers (HeaderTypes, optional): HTTP headers for all requests. Defaults to {}.
|
|
99
|
+
"""
|
|
100
|
+
self.credentials = credentials
|
|
101
|
+
self.http_headers = http_headers
|
|
102
|
+
|
|
103
|
+
# Use httpx default transport (no retries on status codes)
|
|
104
|
+
self.http_retry_transport: httpx.AsyncBaseTransport = httpx.AsyncHTTPTransport()
|
|
105
|
+
|
|
106
|
+
async def load(self, **kwargs: Any) -> None:
|
|
107
|
+
"""
|
|
108
|
+
Initialize the client with credentials and necessary attributes for the client to work.
|
|
109
|
+
|
|
110
|
+
This method should be implemented by subclasses to:
|
|
111
|
+
- Set up authentication headers in self.http_headers in case of http requestss
|
|
112
|
+
- Initialize any required client state
|
|
113
|
+
- Handle credential processing
|
|
114
|
+
- Optionally override self.http_retry_transport for custom retry behavior
|
|
115
|
+
|
|
116
|
+
For advanced retry logic (status code-based retries, rate limiting, custom backoff),
|
|
117
|
+
consider using httpx-retries library and overriding http_retry_transport:
|
|
118
|
+
|
|
119
|
+
Example:
|
|
120
|
+
>>> async def load(self, **kwargs):
|
|
121
|
+
... # Set up headers
|
|
122
|
+
... self.http_headers = {"Authorization": f"Bearer {kwargs.get('token')}"}
|
|
123
|
+
...
|
|
124
|
+
... # For advanced retry logic, install httpx-retries: pip install httpx-retries
|
|
125
|
+
... from httpx_retries import Retry, RetryTransport
|
|
126
|
+
... retry = Retry(total=5, backoff_factor=10, status_forcelist=[429, 500, 502, 503, 504])
|
|
127
|
+
... self.http_retry_transport = RetryTransport(retry=retry)
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
**kwargs: Additional keyword arguments, typically including credentials.
|
|
131
|
+
May also include retry configuration parameters that can be used to
|
|
132
|
+
create a custom http_retry_transport.
|
|
133
|
+
|
|
134
|
+
Raises:
|
|
135
|
+
NotImplementedError: If the subclass does not implement this method.
|
|
136
|
+
"""
|
|
137
|
+
raise NotImplementedError("load method is not implemented")
|
|
138
|
+
|
|
139
|
+
async def execute_http_get_request(
|
|
140
|
+
self,
|
|
141
|
+
url: str,
|
|
142
|
+
headers: Optional[HeaderTypes] = None,
|
|
143
|
+
params: Optional[QueryParamTypes] = None,
|
|
144
|
+
auth: Optional[AuthTypes] = None,
|
|
145
|
+
timeout: int = 10,
|
|
146
|
+
) -> Optional[httpx.Response]:
|
|
147
|
+
"""
|
|
148
|
+
Perform an HTTP GET request using the configured transport.
|
|
149
|
+
|
|
150
|
+
This method uses httpx default transport which only retries on network-level errors
|
|
151
|
+
(connection failures, timeouts). For status code-based retries (429, 500, etc.),
|
|
152
|
+
consider overriding http_retry_transport in the load() method using httpx-retries library.
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
url (str): The URL to make the GET request to
|
|
156
|
+
headers (Optional[HeaderTypes]): HTTP headers to include in the request. Supports dict, Headers object, or list of tuples. These headers will override/add to any client-level headers set in the load() method.
|
|
157
|
+
params (Optional[QueryParamTypes]): Query parameters to include in the request. Supports dict, list of tuples, or string.
|
|
158
|
+
auth (Optional[AuthTypes]): Authentication to use for the request. Supports BasicAuth, DigestAuth, custom auth classes, or tuples for basic auth.
|
|
159
|
+
timeout (int): Request timeout in seconds. Defaults to 10.
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
Optional[httpx.Response]: The HTTP response if successful, None if failed
|
|
163
|
+
|
|
164
|
+
Example:
|
|
165
|
+
>>> # Using Basic Authentication
|
|
166
|
+
>>> from httpx import BasicAuth
|
|
167
|
+
>>> response = await client.execute_http_get_request(
|
|
168
|
+
... url="https://api.example.com/data",
|
|
169
|
+
... auth=BasicAuth("username", "password"),
|
|
170
|
+
... params={"limit": 100}
|
|
171
|
+
... )
|
|
172
|
+
>>>
|
|
173
|
+
>>> # Using tuple for basic auth (username, password)
|
|
174
|
+
>>> response = await client.execute_http_get_request(
|
|
175
|
+
... url="https://api.example.com/data",
|
|
176
|
+
... auth=("username", "password"),
|
|
177
|
+
... params={"limit": 100}
|
|
178
|
+
... )
|
|
179
|
+
>>>
|
|
180
|
+
>>> # Using custom headers for Bearer token
|
|
181
|
+
>>> response = await client.execute_http_get_request(
|
|
182
|
+
... url="https://api.example.com/data",
|
|
183
|
+
... headers={"Authorization": "Bearer token"},
|
|
184
|
+
... params={"limit": 100}
|
|
185
|
+
... )
|
|
186
|
+
"""
|
|
187
|
+
async with httpx.AsyncClient(
|
|
188
|
+
timeout=timeout, transport=self.http_retry_transport
|
|
189
|
+
) as client:
|
|
190
|
+
merged_headers = Headers(self.http_headers)
|
|
191
|
+
if headers:
|
|
192
|
+
merged_headers.update(headers)
|
|
193
|
+
|
|
194
|
+
try:
|
|
195
|
+
response = await client.get(
|
|
196
|
+
url,
|
|
197
|
+
headers=merged_headers,
|
|
198
|
+
params=params,
|
|
199
|
+
auth=auth if auth is not None else httpx.USE_CLIENT_DEFAULT,
|
|
200
|
+
)
|
|
201
|
+
return response
|
|
202
|
+
except httpx.HTTPStatusError as e:
|
|
203
|
+
logger.error(f"HTTP error for {url}: {e.response.status_code}")
|
|
204
|
+
return None
|
|
205
|
+
except Exception as e:
|
|
206
|
+
logger.error(f"Request failed for {url}: {e}")
|
|
207
|
+
return None
|
|
208
|
+
|
|
209
|
+
async def execute_http_post_request(
|
|
210
|
+
self,
|
|
211
|
+
url: str,
|
|
212
|
+
data: Optional[RequestData] = None,
|
|
213
|
+
json_data: Optional[Any] = None,
|
|
214
|
+
content: Optional[bytes] = None,
|
|
215
|
+
files: Optional[RequestFiles] = None,
|
|
216
|
+
headers: Optional[HeaderTypes] = None,
|
|
217
|
+
params: Optional[QueryParamTypes] = None,
|
|
218
|
+
cookies: Optional[Dict[str, str]] = None,
|
|
219
|
+
auth: Optional[AuthTypes] = None,
|
|
220
|
+
follow_redirects: bool = True,
|
|
221
|
+
verify: bool = True,
|
|
222
|
+
timeout: int = 30,
|
|
223
|
+
) -> Optional[httpx.Response]:
|
|
224
|
+
"""
|
|
225
|
+
Perform an HTTP POST request using the configured transport.
|
|
226
|
+
|
|
227
|
+
This method uses httpx default transport which only retries on network-level errors
|
|
228
|
+
(connection failures, timeouts). For status code-based retries (429, 500, etc.),
|
|
229
|
+
consider overriding http_retry_transport in the load() method using httpx-retries library.
|
|
230
|
+
|
|
231
|
+
Args:
|
|
232
|
+
url (str): The URL to make the POST request to
|
|
233
|
+
data (Optional[RequestData]): Form data to send in the request body. Supports dict, list of tuples, or other httpx-compatible formats.
|
|
234
|
+
json_data (Optional[Any]): JSON data to send in the request body. Any JSON-serializable object.
|
|
235
|
+
content (Optional[bytes]): Raw binary content to send in the request body
|
|
236
|
+
files (Optional[RequestFiles]): Files to upload in the request body. Supports various file formats and tuples.
|
|
237
|
+
headers (Optional[HeaderTypes]): HTTP headers to include in the request. Supports dict, Headers object, or list of tuples. These headers will override/add to any client-level headers set in the load() method.
|
|
238
|
+
params (Optional[QueryParamTypes]): Query parameters to include in the request. Supports dict, list of tuples, or string.
|
|
239
|
+
cookies (Optional[Dict[str, str]]): Cookies to include in the request
|
|
240
|
+
auth (Optional[AuthTypes]): Authentication to use for the request. Supports BasicAuth, DigestAuth, custom auth classes, or tuples for basic auth.
|
|
241
|
+
follow_redirects (bool): Whether to follow HTTP redirects. Defaults to True.
|
|
242
|
+
verify (bool): Whether to verify SSL certificates. Defaults to True.
|
|
243
|
+
timeout (int): Request timeout in seconds. Defaults to 30.
|
|
244
|
+
|
|
245
|
+
Returns:
|
|
246
|
+
Optional[httpx.Response]: The HTTP response if successful, None if failed
|
|
247
|
+
|
|
248
|
+
Example:
|
|
249
|
+
>>> # Basic JSON POST request with authentication
|
|
250
|
+
>>> from httpx import BasicAuth
|
|
251
|
+
>>> response = await client.execute_http_post_request(
|
|
252
|
+
... url="https://api.example.com/data",
|
|
253
|
+
... json_data={"name": "test", "value": 123},
|
|
254
|
+
... headers={"Content-Type": "application/json"},
|
|
255
|
+
... auth=BasicAuth("username", "password")
|
|
256
|
+
... )
|
|
257
|
+
>>>
|
|
258
|
+
>>> # File upload with basic auth tuple
|
|
259
|
+
>>> with open("file.txt", "rb") as f:
|
|
260
|
+
... response = await client.execute_http_post_request(
|
|
261
|
+
... url="https://api.example.com/upload",
|
|
262
|
+
... data={"description": "My file"},
|
|
263
|
+
... files={"file": ("file.txt", f.read(), "text/plain")},
|
|
264
|
+
... auth=("username", "password")
|
|
265
|
+
... )
|
|
266
|
+
"""
|
|
267
|
+
async with httpx.AsyncClient(
|
|
268
|
+
timeout=timeout, transport=self.http_retry_transport, verify=verify
|
|
269
|
+
) as client:
|
|
270
|
+
merged_headers = Headers(self.http_headers)
|
|
271
|
+
if headers:
|
|
272
|
+
merged_headers.update(headers)
|
|
273
|
+
|
|
274
|
+
try:
|
|
275
|
+
response = await client.post(
|
|
276
|
+
url,
|
|
277
|
+
data=data,
|
|
278
|
+
json=json_data,
|
|
279
|
+
content=content,
|
|
280
|
+
files=files,
|
|
281
|
+
headers=merged_headers,
|
|
282
|
+
params=params,
|
|
283
|
+
cookies=cookies,
|
|
284
|
+
auth=auth if auth is not None else httpx.USE_CLIENT_DEFAULT,
|
|
285
|
+
follow_redirects=follow_redirects,
|
|
286
|
+
)
|
|
287
|
+
return response
|
|
288
|
+
except httpx.HTTPStatusError as e:
|
|
289
|
+
logger.error(f"HTTP error for {url}: {e.response.status_code}")
|
|
290
|
+
return None
|
|
291
|
+
except Exception as e:
|
|
292
|
+
logger.error(f"Request failed for {url}: {e}")
|
|
293
|
+
return None
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional
|
|
2
|
+
|
|
3
|
+
from application_sdk.clients.base import BaseClient
|
|
4
|
+
from application_sdk.handlers import HandlerInterface
|
|
5
|
+
from application_sdk.observability.logger_adaptor import get_logger
|
|
6
|
+
|
|
7
|
+
logger = get_logger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class BaseHandler(HandlerInterface):
|
|
11
|
+
"""
|
|
12
|
+
Base handler for non-SQL based applications.
|
|
13
|
+
|
|
14
|
+
This class provides a base implementation for handlers that need to interact with non-SQL data sources. It implements the HandlerInterface and provides basic functionality that can be extended by subclasses.
|
|
15
|
+
|
|
16
|
+
Attributes:
|
|
17
|
+
client (BaseClient): The client instance for connecting to the target system.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self, client: Optional[BaseClient] = None):
|
|
21
|
+
"""
|
|
22
|
+
Initialize the base handler.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
client (BaseClient, optional): The client instance to use for connections. Defaults to BaseClient().
|
|
26
|
+
"""
|
|
27
|
+
self.client = client or BaseClient()
|
|
28
|
+
|
|
29
|
+
async def load(self, credentials: Dict[str, Any]) -> None:
|
|
30
|
+
"""
|
|
31
|
+
Load and initialize the handler.
|
|
32
|
+
|
|
33
|
+
This method initializes the handler and loads the client with the provided credentials.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
credentials (Dict[str, Any]): Credentials for the client.
|
|
37
|
+
"""
|
|
38
|
+
logger.info("Loading base handler")
|
|
39
|
+
|
|
40
|
+
# Load the client with credentials
|
|
41
|
+
await self.client.load(credentials=credentials)
|
|
42
|
+
|
|
43
|
+
logger.info("Base handler loaded successfully")
|
|
44
|
+
|
|
45
|
+
# The following methods are inherited from HandlerInterface and should be implemented
|
|
46
|
+
# by subclasses to handle calls from their respective FastAPI endpoints:
|
|
47
|
+
#
|
|
48
|
+
# - test_auth(**kwargs) -> bool: Called by /workflow/v1/auth endpoint
|
|
49
|
+
# - preflight_check(**kwargs) -> Any: Called by /workflow/v1/check endpoint
|
|
50
|
+
# - fetch_metadata(**kwargs) -> Any: Called by /workflow/v1/metadata endpoint
|
application_sdk/version.py
CHANGED
{atlan_application_sdk-0.1.1rc32.dist-info → atlan_application_sdk-0.1.1rc34.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: atlan-application-sdk
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1rc34
|
|
4
4
|
Summary: Atlan Application SDK is a Python library for developing applications on the Atlan Platform
|
|
5
5
|
Project-URL: Repository, https://github.com/atlanhq/application-sdk
|
|
6
6
|
Project-URL: Documentation, https://github.com/atlanhq/application-sdk/README.md
|
|
@@ -26,12 +26,12 @@ Requires-Dist: fastapi[standard]>=0.115.0
|
|
|
26
26
|
Requires-Dist: loguru>=0.7.3
|
|
27
27
|
Requires-Dist: opentelemetry-exporter-otlp>=1.27.0
|
|
28
28
|
Requires-Dist: psutil>=7.0.0
|
|
29
|
-
Requires-Dist: pyatlan>=
|
|
29
|
+
Requires-Dist: pyatlan>=8.0.0
|
|
30
30
|
Requires-Dist: pydantic>=2.10.6
|
|
31
31
|
Requires-Dist: python-dotenv>=1.1.0
|
|
32
32
|
Requires-Dist: uvloop>=0.21.0; sys_platform != 'win32'
|
|
33
33
|
Provides-Extra: daft
|
|
34
|
-
Requires-Dist: daft
|
|
34
|
+
Requires-Dist: daft>=0.4.12; extra == 'daft'
|
|
35
35
|
Provides-Extra: iam-auth
|
|
36
36
|
Requires-Dist: boto3>=1.38.6; extra == 'iam-auth'
|
|
37
37
|
Provides-Extra: iceberg
|
{atlan_application_sdk-0.1.1rc32.dist-info → atlan_application_sdk-0.1.1rc34.dist-info}/RECORD
RENAMED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
application_sdk/__init__.py,sha256=2e2mvmLJ5dxmJGPELtb33xwP-j6JMdoIuqKycEn7hjg,151
|
|
2
2
|
application_sdk/constants.py,sha256=_Fmk9PgpM68chPDHHkgrs4Zg2KK4UCqqg7Oj9_u3WVo,9486
|
|
3
|
-
application_sdk/version.py,sha256=
|
|
3
|
+
application_sdk/version.py,sha256=_RjK_lRaDoDHAbAg-jVq77m5SMKSytbbLBp_Mg4q_Hw,88
|
|
4
4
|
application_sdk/worker.py,sha256=dZLxPkAieCSw7XEWxzL-FRk0QAZm7vXQBICjZODy3B4,7488
|
|
5
5
|
application_sdk/activities/__init__.py,sha256=EH5VTHcfGykIX7V1HsG0J1Z-1FbJEXTQOET0HdzFDjU,9519
|
|
6
6
|
application_sdk/activities/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
7
|
application_sdk/activities/common/models.py,sha256=305WdrZB7EAtCOAU_q9hMw81XowUdCeuFs9zfzb-MHQ,1196
|
|
8
8
|
application_sdk/activities/common/utils.py,sha256=CWAj_tQUSQirSs5wwy-9eS8yI_4HoDfXsj2U_Xkb4Bc,6480
|
|
9
9
|
application_sdk/activities/metadata_extraction/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
application_sdk/activities/metadata_extraction/base.py,sha256=t6dpJWq-syhlyLjjmA-TkXU9SnpJ_3yMu5uI9t6-joo,3877
|
|
10
11
|
application_sdk/activities/metadata_extraction/rest.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
12
|
application_sdk/activities/metadata_extraction/sql.py,sha256=3G9_KGKyS0kTBN-nOKdvNSpTqwFv0nUectsqhMewpnU,22594
|
|
12
13
|
application_sdk/activities/query_extraction/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
14
|
application_sdk/activities/query_extraction/sql.py,sha256=xC-dC_so3D9yY88lSL2W8Q8CfDRjiIrF-OHKbITFgd0,21271
|
|
14
|
-
application_sdk/application/__init__.py,sha256=
|
|
15
|
+
application_sdk/application/__init__.py,sha256=WDWDWP-IQ-ny7okqsrdTwH60cXKgXBRcnlJ1XVYfiNU,7957
|
|
15
16
|
application_sdk/application/metadata_extraction/sql.py,sha256=ohpV4qZ92uKRlH7I_8G67ocnWkZJAZCU_7XdvqYPiN4,7966
|
|
16
17
|
application_sdk/clients/__init__.py,sha256=C9T84J7V6ZumcoWJPAxdd3tqSmbyciaGBJn-CaCCny0,1341
|
|
18
|
+
application_sdk/clients/async_atlan.py,sha256=RTgRbMw6zJWcv1C-7cU4ccaSW5XZsB5dcA1Tlkj32p8,2699
|
|
17
19
|
application_sdk/clients/atlan.py,sha256=f2-Uk5KiPIDJEhGkfYctA_f3CwoVB_mWNBMVvxeLuY4,2684
|
|
18
20
|
application_sdk/clients/atlan_auth.py,sha256=MQznmvVKrlOT_Tp232W4UrOupRrx9Dx9zQm3n1R7kD8,8938
|
|
21
|
+
application_sdk/clients/base.py,sha256=TIn3pG89eXUc1XSYf4jk66m1vajWp0WxcCQOOltdazA,14021
|
|
19
22
|
application_sdk/clients/sql.py,sha256=tW89SHuuWdU5jv8lDUP5AUCEpR2CF_5TyUvYDCBHses,17880
|
|
20
23
|
application_sdk/clients/temporal.py,sha256=jyU2MYGZXkTn0Gqy_qvYg0iSc2bKz4snflsU_XcDsfk,23662
|
|
21
24
|
application_sdk/clients/utils.py,sha256=zLFOJbTr_6TOqnjfVFGY85OtIXZ4FQy_rquzjaydkbY,779
|
|
@@ -45,6 +48,7 @@ application_sdk/docgen/parsers/manifest.py,sha256=3NP-dBTpHAUQa477usMIDaKSb_9xfL
|
|
|
45
48
|
application_sdk/events/__init__.py,sha256=OcbVWDF4ZKRTJXK9UaFVtYEwu-3DHE77S-Sn6jNafUs,204
|
|
46
49
|
application_sdk/events/models.py,sha256=7Esqp3WlbriT2EqT4kNiY_sHtRXRPLj27b8SbeC5Sb0,5121
|
|
47
50
|
application_sdk/handlers/__init__.py,sha256=U7kKwVWK0FZz1uIJ2ANN0C5tD83k_9Nyz0ns6ttr92g,1152
|
|
51
|
+
application_sdk/handlers/base.py,sha256=6GF0a4p9mbdVoBltkzXwt6i0vzOvOKUHcB6fBiqi7v0,1883
|
|
48
52
|
application_sdk/handlers/sql.py,sha256=oeB-sgWwPYo31xaD87TyMc0h51Sary1F-CmhExt9_Pk,16100
|
|
49
53
|
application_sdk/inputs/__init__.py,sha256=_d-cUhcDyoJTJR3PdQkC831go6VDw9AM6Bg7-qm3NHI,1900
|
|
50
54
|
application_sdk/inputs/iceberg.py,sha256=xiv1kNtVx1k0h3ZJbJeXjZwdfBGSy9j9orYP_AyCYlI,2756
|
|
@@ -72,7 +76,7 @@ application_sdk/outputs/secretstore.py,sha256=JS9vUzb11leDpcMQSCnLJuE9Ww-9G3wMvC
|
|
|
72
76
|
application_sdk/outputs/statestore.py,sha256=XiEag2e9WW3_D3xbWQGoNrHiFJz9916qcIvhrROX8_8,3999
|
|
73
77
|
application_sdk/server/__init__.py,sha256=KTqE1YPw_3WDVMWatJUuf9OOiobLM2K5SMaBrI62sCo,1568
|
|
74
78
|
application_sdk/server/fastapi/__init__.py,sha256=1RNP3170Es_GcxVSweqkl_iz4Sd0Evi8bs6fuVuVTiA,27770
|
|
75
|
-
application_sdk/server/fastapi/models.py,sha256=
|
|
79
|
+
application_sdk/server/fastapi/models.py,sha256=K6eNl3XXiTXKUvRTpq3oqdGH3jY1-ApobXma04J86fE,6665
|
|
76
80
|
application_sdk/server/fastapi/utils.py,sha256=2XI4DylhRQsukhX67lpAzRNCHeFCSpbuNd7TlE2IBJA,1164
|
|
77
81
|
application_sdk/server/fastapi/middleware/logmiddleware.py,sha256=CxcPtDmCbSfSZ8RyI09nIshVIbCokyyA9bByQJ2G_ns,2545
|
|
78
82
|
application_sdk/server/fastapi/middleware/metrics.py,sha256=5ddHAIg5sT-u9tB_HHMGL3Cfu2g1rm9z7ksienIr9ks,1563
|
|
@@ -134,8 +138,8 @@ application_sdk/workflows/metadata_extraction/__init__.py,sha256=jHUe_ZBQ66jx8bg
|
|
|
134
138
|
application_sdk/workflows/metadata_extraction/sql.py,sha256=_NhszxIgmcQI6lVpjJoyJRFLwPYvJw1Dyqox_m9K2RA,11947
|
|
135
139
|
application_sdk/workflows/query_extraction/__init__.py,sha256=n066_CX5RpJz6DIxGMkKS3eGSRg03ilaCtsqfJWQb7Q,117
|
|
136
140
|
application_sdk/workflows/query_extraction/sql.py,sha256=kT_JQkLCRZ44ZpaC4QvPL6DxnRIIVh8gYHLqRbMI-hA,4826
|
|
137
|
-
atlan_application_sdk-0.1.
|
|
138
|
-
atlan_application_sdk-0.1.
|
|
139
|
-
atlan_application_sdk-0.1.
|
|
140
|
-
atlan_application_sdk-0.1.
|
|
141
|
-
atlan_application_sdk-0.1.
|
|
141
|
+
atlan_application_sdk-0.1.1rc34.dist-info/METADATA,sha256=XScCLyFgrofFYSusKm-kLSlICduUMNytPqAnNWEqs7Q,5468
|
|
142
|
+
atlan_application_sdk-0.1.1rc34.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
143
|
+
atlan_application_sdk-0.1.1rc34.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
144
|
+
atlan_application_sdk-0.1.1rc34.dist-info/licenses/NOTICE,sha256=A-XVVGt3KOYuuMmvSMIFkg534F1vHiCggEBp4Ez3wGk,1041
|
|
145
|
+
atlan_application_sdk-0.1.1rc34.dist-info/RECORD,,
|
{atlan_application_sdk-0.1.1rc32.dist-info → atlan_application_sdk-0.1.1rc34.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|