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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: api-to-dataframe
3
- Version: 1.3.0
3
+ Version: 1.3.3
4
4
  Summary: A package to convert API responses to pandas dataframe
5
5
  License: MIT
6
6
  Author: IvanildoBarauna
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "api-to-dataframe"
3
- version = "1.3.0"
3
+ version = "1.3.3"
4
4
  description = "A package to convert API responses to pandas dataframe"
5
5
  authors = ["IvanildoBarauna <ivanildo.jnr@outlook.com>"]
6
6
  readme = "README.md"
@@ -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.NoRetryStrategy.
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 2.
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.DEBUG,
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)