Skip to content

Commit fe9ce59

Browse files
committed
Initial pydantic version
1 parent 91aa9f9 commit fe9ce59

17 files changed

+705
-2781
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ wheels/
4949
*.egg-info/
5050
.installed.cfg
5151
*.egg
52+
*.DS_Store

pyatlan/client/atlan.py

+27-11
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,31 @@
2222
import logging
2323
import os
2424

25+
2526
import requests
2627

27-
from pyatlan.client.index import IndexClient
28+
from pydantic import BaseSettings, HttpUrl, PrivateAttr, Field
2829
from pyatlan.exceptions import AtlanServiceException
29-
from pyatlan.utils import HTTPMethod, HTTPStatus, get_logger, type_coerce
30+
from pyatlan.utils import HTTPMethod, HTTPStatus, get_logger
3031

3132
LOGGER = get_logger()
3233

3334

34-
class AtlanClient:
35-
def __init__(self, host, api_key):
36-
self.session = requests.Session()
37-
self.host = host
38-
self.request_params = {"headers": {"authorization": f"Bearer {api_key}"}}
39-
self.index_client = IndexClient(self)
35+
class AtlanClient(BaseSettings):
36+
host: HttpUrl
37+
api_key: str
38+
session: requests.Session = Field(default_factory=requests.Session)
39+
_request_params: dict = PrivateAttr()
40+
41+
class Config:
42+
env_prefix = "atlan_"
43+
44+
def __init__(self, **data):
45+
super().__init__(**data)
46+
self._request_params = {"headers": {"authorization": f"Bearer {self.api_key}"}}
4047

4148
def call_api(self, api, response_type=None, query_params=None, request_obj=None):
42-
params = copy.deepcopy(self.request_params)
49+
params = copy.deepcopy(self._request_params)
4350
path = os.path.join(self.host, api.path)
4451

4552
params["headers"]["Accept"] = api.consumes
@@ -92,8 +99,12 @@ def call_api(self, api, response_type=None, query_params=None, request_obj=None)
9299
LOGGER.debug(response.json())
93100
if response_type == str:
94101
return json.dumps(response.json())
95-
96-
return type_coerce(response.json(), response_type)
102+
with open(
103+
"/Users/ernesthill/PycharmProjects/TypeDefAnalyzer/typedefs.json",
104+
"w",
105+
) as outfile:
106+
json.dump(response.json(), outfile)
107+
return response_type(**response.json())
97108
except Exception as e:
98109
print(e)
99110
LOGGER.exception(
@@ -109,3 +120,8 @@ def call_api(self, api, response_type=None, query_params=None, request_obj=None)
109120
return None
110121
else:
111122
raise AtlanServiceException(api, response)
123+
124+
125+
if __name__ == "__main__":
126+
client = AtlanClient()
127+
print(client.dict())

pyatlan/client/bulk.py

-27
This file was deleted.

0 commit comments

Comments
 (0)