api-to-dataframe 1.3.0__tar.gz → 1.3.3__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.
- {api_to_dataframe-1.3.0 → api_to_dataframe-1.3.3}/PKG-INFO +1 -1
- {api_to_dataframe-1.3.0 → api_to_dataframe-1.3.3}/pyproject.toml +1 -1
- {api_to_dataframe-1.3.0 → api_to_dataframe-1.3.3}/src/api_to_dataframe/controller/client_builder.py +20 -11
- {api_to_dataframe-1.3.0 → api_to_dataframe-1.3.3}/src/api_to_dataframe/utils/logger.py +2 -7
- {api_to_dataframe-1.3.0 → api_to_dataframe-1.3.3}/LICENSE +0 -0
- {api_to_dataframe-1.3.0 → api_to_dataframe-1.3.3}/README.md +0 -0
- {api_to_dataframe-1.3.0 → api_to_dataframe-1.3.3}/src/api_to_dataframe/__init__.py +0 -0
- {api_to_dataframe-1.3.0 → api_to_dataframe-1.3.3}/src/api_to_dataframe/config/config.py +0 -0
- {api_to_dataframe-1.3.0 → api_to_dataframe-1.3.3}/src/api_to_dataframe/models/get_data.py +0 -0
- {api_to_dataframe-1.3.0 → api_to_dataframe-1.3.3}/src/api_to_dataframe/models/retainer.py +0 -0
{api_to_dataframe-1.3.0 → api_to_dataframe-1.3.3}/src/api_to_dataframe/controller/client_builder.py
RENAMED
|
@@ -19,10 +19,10 @@ class ClientBuilder:
|
|
|
19
19
|
Args:
|
|
20
20
|
endpoint (str): The API endpoint to connect to.
|
|
21
21
|
headers (dict, optional): The headers to use for the API request. Defaults to None.
|
|
22
|
-
retry_strategy (Strategies, optional): Defaults to Strategies.
|
|
22
|
+
retry_strategy (Strategies, optional): Defaults to Strategies.NO_RETRY_STRATEGY.
|
|
23
23
|
retries (int): The number of times to retry a failed request. Defaults to 3.
|
|
24
24
|
initial_delay (int): The delay between retries in seconds. Defaults to 1.
|
|
25
|
-
connection_timeout (int): The timeout for the connection in seconds. Defaults to
|
|
25
|
+
connection_timeout (int): The timeout for the connection in seconds. Defaults to 1.
|
|
26
26
|
|
|
27
27
|
Raises:
|
|
28
28
|
ValueError: If endpoint is an empty string.
|
|
@@ -58,8 +58,12 @@ class ClientBuilder:
|
|
|
58
58
|
"""
|
|
59
59
|
Retrieves data from the API using the defined endpoint and retry strategy.
|
|
60
60
|
|
|
61
|
+
This function sends a request to the API using the endpoint, headers, and
|
|
62
|
+
connection timeout specified in the instance attributes. It uses the
|
|
63
|
+
defined retry strategy to handle potential failures and retries.
|
|
64
|
+
|
|
61
65
|
Returns:
|
|
62
|
-
dict: The response from the API.
|
|
66
|
+
dict: The JSON response from the API as a dictionary.
|
|
63
67
|
"""
|
|
64
68
|
response = GetData.get_response(
|
|
65
69
|
endpoint=self.endpoint,
|
|
@@ -69,16 +73,21 @@ class ClientBuilder:
|
|
|
69
73
|
|
|
70
74
|
return response.json()
|
|
71
75
|
|
|
72
|
-
def _get_raw_api_data(self):
|
|
73
|
-
response = GetData.get_response(
|
|
74
|
-
endpoint=self.endpoint,
|
|
75
|
-
headers=self.headers,
|
|
76
|
-
connection_timeout=self.connection_timeout,
|
|
77
|
-
)
|
|
78
|
-
return response
|
|
79
|
-
|
|
80
76
|
@staticmethod
|
|
81
77
|
def api_to_dataframe(response: dict):
|
|
78
|
+
"""
|
|
79
|
+
Converts an API response to a DataFrame.
|
|
80
|
+
|
|
81
|
+
This function takes a dictionary response from an API,
|
|
82
|
+
uses the `to_dataframe` function from the `GetData` class
|
|
83
|
+
to convert it into a DataFrame, and logs the operation as successful.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
response (dict): The dictionary containing the API response.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
DataFrame: A pandas DataFrame containing the data from the API response.
|
|
90
|
+
"""
|
|
82
91
|
df = GetData.to_dataframe(response)
|
|
83
92
|
log("serialized to dataframe: OK", LogLevel.INFO)
|
|
84
93
|
return df
|
|
@@ -11,17 +11,12 @@ class LogLevel(Enum):
|
|
|
11
11
|
# Configure logging once at the start of your program
|
|
12
12
|
logging.basicConfig(
|
|
13
13
|
encoding="utf-8",
|
|
14
|
-
format="%(asctime)s :: %(levelname)s :: %(message)s",
|
|
14
|
+
format="%(asctime)s :: api-to-dataframe[%(levelname)s] :: %(message)s",
|
|
15
15
|
datefmt="%Y-%m-%d %H:%M:%S %Z",
|
|
16
|
-
level=logging.
|
|
16
|
+
level=logging.INFO,
|
|
17
17
|
)
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
def log(message: str, level: LogLevel):
|
|
21
21
|
logger = logging.getLogger("api-to-dataframe")
|
|
22
22
|
logger.log(level.value, message)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
log("This is an info message", LogLevel.INFO)
|
|
26
|
-
log("This is a warning message", LogLevel.WARNING)
|
|
27
|
-
log("This is an error message", LogLevel.ERROR)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|