api-to-dataframe 1.3.3__tar.gz → 1.3.10__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.3
3
+ Version: 1.3.10
4
4
  Summary: A package to convert API responses to pandas dataframe
5
5
  License: MIT
6
6
  Author: IvanildoBarauna
@@ -86,20 +86,15 @@ client = ClientBuilder(endpoint="https://api.example.com"
86
86
  ,connection_timeout=2
87
87
  ,headers=headers)
88
88
 
89
- """
90
- NOTE: by default the quantity of retries is 3 and the time between retries is 1 second, but you can define manually.
91
- """
92
-
89
+ # if you can define timeout with EXPONENTIAL_RETRY_STRATEGY and set headers:
93
90
  client = ClientBuilder(endpoint="https://api.example.com"
94
- ,retry_strategy=RetryStrategies.LINEAR_RETRY_STRATEGY
91
+ ,retry_strategy=RetryStrategies.EXPONENTIAL_RETRY_STRATEGY
95
92
  ,connection_timeout=10
96
93
  ,headers=headers
97
94
  ,retries=5
98
95
  ,initial_delay=10)
99
96
 
100
97
 
101
- ### timeout, retry_strategy and headers are opcionals parameters
102
-
103
98
  # Get data from the API
104
99
  data = client.get_api_data()
105
100
 
@@ -109,3 +104,28 @@ df = client.api_to_dataframe(data)
109
104
  # Display the DataFrame
110
105
  print(df)
111
106
  ```
107
+
108
+ ## Important notes:
109
+ * **Opcionals Parameters:** The params timeout, retry_strategy and headers are opcionals.
110
+ * **Default Params Value:** By default the quantity of retries is 3 and the time between retries is 1 second, but you can define manually.
111
+ * **Max Of Retries:** For security of API Server there is a limit for quantity of retries, actually this value is 5, this value is defined in lib constant. You can inform any value in RETRIES param, but the lib only will try 5x.
112
+ * **Exponential Retry Strategy:** The increment of time between retries is time passed in **initial_delay** param * 2 * the retry_number, e.g with initial_delay=2
113
+
114
+ RetryNumber | WaitingTime
115
+ ------------ | -----------
116
+ 2 | 2s
117
+ 2 | 4s
118
+ 3 | 6s
119
+ 4 | 8s
120
+ 5 | 10s
121
+ * **Linear Retry Strategy:** The increment of time between retries is time passed in **initial_delay**
122
+ e.g with initial_delay=2
123
+
124
+ RetryNumber | WaitingTime
125
+ ------------ | -----------
126
+ 1 | 2s
127
+ 2 | 2s
128
+ 3 | 2s
129
+ 4 | 2s
130
+ 5 | 2s
131
+
@@ -58,20 +58,15 @@ client = ClientBuilder(endpoint="https://api.example.com"
58
58
  ,connection_timeout=2
59
59
  ,headers=headers)
60
60
 
61
- """
62
- NOTE: by default the quantity of retries is 3 and the time between retries is 1 second, but you can define manually.
63
- """
64
-
61
+ # if you can define timeout with EXPONENTIAL_RETRY_STRATEGY and set headers:
65
62
  client = ClientBuilder(endpoint="https://api.example.com"
66
- ,retry_strategy=RetryStrategies.LINEAR_RETRY_STRATEGY
63
+ ,retry_strategy=RetryStrategies.EXPONENTIAL_RETRY_STRATEGY
67
64
  ,connection_timeout=10
68
65
  ,headers=headers
69
66
  ,retries=5
70
67
  ,initial_delay=10)
71
68
 
72
69
 
73
- ### timeout, retry_strategy and headers are opcionals parameters
74
-
75
70
  # Get data from the API
76
71
  data = client.get_api_data()
77
72
 
@@ -80,4 +75,28 @@ df = client.api_to_dataframe(data)
80
75
 
81
76
  # Display the DataFrame
82
77
  print(df)
83
- ```
78
+ ```
79
+
80
+ ## Important notes:
81
+ * **Opcionals Parameters:** The params timeout, retry_strategy and headers are opcionals.
82
+ * **Default Params Value:** By default the quantity of retries is 3 and the time between retries is 1 second, but you can define manually.
83
+ * **Max Of Retries:** For security of API Server there is a limit for quantity of retries, actually this value is 5, this value is defined in lib constant. You can inform any value in RETRIES param, but the lib only will try 5x.
84
+ * **Exponential Retry Strategy:** The increment of time between retries is time passed in **initial_delay** param * 2 * the retry_number, e.g with initial_delay=2
85
+
86
+ RetryNumber | WaitingTime
87
+ ------------ | -----------
88
+ 2 | 2s
89
+ 2 | 4s
90
+ 3 | 6s
91
+ 4 | 8s
92
+ 5 | 10s
93
+ * **Linear Retry Strategy:** The increment of time between retries is time passed in **initial_delay**
94
+ e.g with initial_delay=2
95
+
96
+ RetryNumber | WaitingTime
97
+ ------------ | -----------
98
+ 1 | 2s
99
+ 2 | 2s
100
+ 3 | 2s
101
+ 4 | 2s
102
+ 5 | 2s
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "api-to-dataframe"
3
- version = "1.3.3"
3
+ version = "1.3.10"
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"
@@ -1,7 +1,9 @@
1
1
  import time
2
2
  from enum import Enum
3
+
3
4
  from requests.exceptions import RequestException
4
5
  from api_to_dataframe.utils.logger import log, LogLevel
6
+ from api_to_dataframe.utils import Constants
5
7
 
6
8
 
7
9
  class Strategies(Enum):
@@ -16,7 +18,7 @@ def retry_strategies(func):
16
18
  while retry_number < args[0].retries:
17
19
  try:
18
20
  log(
19
- f"Trying for the {retry_number + 1} of {args[0].retries} retries. "
21
+ f"Trying for the {retry_number} of {Constants.MAX_OF_RETRIES} retries. "
20
22
  f"Using {args[0].retry_strategy}",
21
23
  LogLevel.INFO,
22
24
  )
@@ -29,9 +31,9 @@ def retry_strategies(func):
29
31
  if args[0].retry_strategy == Strategies.LINEAR_RETRY_STRATEGY:
30
32
  time.sleep(args[0].delay)
31
33
  elif args[0].retry_strategy == Strategies.EXPONENTIAL_RETRY_STRATEGY:
32
- time.sleep(args[0].delay * 2**retry_number)
34
+ time.sleep(args[0].delay * retry_number)
33
35
 
34
- if retry_number == args[0].retries:
36
+ if retry_number in (args[0].retries, Constants.MAX_OF_RETRIES):
35
37
  log(
36
38
  f"Failed after {retry_number} retries using {args[0].retry_strategy}",
37
39
  LogLevel.ERROR,
@@ -0,0 +1,2 @@
1
+ class Constants:
2
+ MAX_OF_RETRIES = 5