api-to-dataframe 2.0.6__tar.gz → 2.2.0__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-2.2.0/PKG-INFO +93 -0
- api_to_dataframe-2.2.0/README.md +67 -0
- {api_to_dataframe-2.0.6 → api_to_dataframe-2.2.0}/pyproject.toml +6 -7
- api_to_dataframe-2.2.0/src/api_to_dataframe/controller/__init__.py +0 -0
- {api_to_dataframe-2.0.6 → api_to_dataframe-2.2.0}/src/api_to_dataframe/controller/client_builder.py +15 -23
- api_to_dataframe-2.2.0/src/api_to_dataframe/models/__init__.py +0 -0
- {api_to_dataframe-2.0.6 → api_to_dataframe-2.2.0}/src/api_to_dataframe/models/retainer.py +4 -4
- api_to_dataframe-2.2.0/src/api_to_dataframe/utils/logger.py +4 -0
- api_to_dataframe-2.0.6/PKG-INFO +0 -131
- api_to_dataframe-2.0.6/README.md +0 -103
- api_to_dataframe-2.0.6/src/api_to_dataframe/utils/logger.py +0 -11
- {api_to_dataframe-2.0.6 → api_to_dataframe-2.2.0}/LICENSE +0 -0
- {api_to_dataframe-2.0.6 → api_to_dataframe-2.2.0}/src/api_to_dataframe/__init__.py +0 -0
- {api_to_dataframe-2.0.6 → api_to_dataframe-2.2.0}/src/api_to_dataframe/models/get_data.py +0 -0
- {api_to_dataframe-2.0.6 → api_to_dataframe-2.2.0}/src/api_to_dataframe/utils/__init__.py +0 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: api-to-dataframe
|
|
3
|
+
Version: 2.2.0
|
|
4
|
+
Summary: A package to convert API responses to pandas dataframe
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: IvanildoBarauna
|
|
7
|
+
Author-email: ivanildo.jnr@outlook.com
|
|
8
|
+
Requires-Python: >=3.10,<4.0
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Requires-Dist: pandas (>=2.2.3,<3.0.0)
|
|
17
|
+
Requires-Dist: requests (>=2.33.0,<3.0.0)
|
|
18
|
+
Project-URL: Documentation, https://github.com/IvanildoBarauna/api-to-dataframe/blob/main/README.md
|
|
19
|
+
Project-URL: Homepage, https://pypi.org/project/api-to-dataframe
|
|
20
|
+
Project-URL: ImplementationCase, https://github.com/IvanildoBarauna/ETL-awesome-api
|
|
21
|
+
Project-URL: Issues, https://github.com/IvanildoBarauna/api-to-dataframe/issues
|
|
22
|
+
Project-URL: Notebook, https://github.com/IvanildoBarauna/api-to-dataframe/blob/main/notebooks/example.ipynb
|
|
23
|
+
Project-URL: Repository, https://github.com/IvanildoBarauna/api-to-dataframe
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# API to DataFrame
|
|
27
|
+
|
|
28
|
+
Fetch JSON from any HTTP API and turn it into a pandas DataFrame in two calls — with optional retry strategies.
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/api-to-dataframe/#history)
|
|
31
|
+
[](https://pypi.org/project/api-to-dataframe/)
|
|
32
|
+
[](https://pypi.org/project/api-to-dataframe/)
|
|
33
|
+
[](https://github.com/ivanildobarauna-dev/api-to-dataframe/actions/workflows/CI.yaml)
|
|
34
|
+
[](https://app.codecov.io/gh/ivanildobarauna-dev/api-to-dataframe)
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
pip install api-to-dataframe
|
|
40
|
+
# or
|
|
41
|
+
poetry add api-to-dataframe
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Requires Python 3.10+.
|
|
45
|
+
|
|
46
|
+
## Quick start
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from api_to_dataframe import ClientBuilder, RetryStrategies
|
|
50
|
+
|
|
51
|
+
client = ClientBuilder(endpoint="https://api.example.com/items")
|
|
52
|
+
data = client.get_api_data()
|
|
53
|
+
df = client.api_to_dataframe(data)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`api_to_dataframe` expects the response to be a list of dicts. An empty result raises `ValueError`.
|
|
57
|
+
|
|
58
|
+
## Configuration
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
client = ClientBuilder(
|
|
62
|
+
endpoint="https://api.example.com/items",
|
|
63
|
+
headers={"Authorization": "Bearer ..."},
|
|
64
|
+
retry_strategy=RetryStrategies.EXPONENTIAL_RETRY_STRATEGY,
|
|
65
|
+
retries=5,
|
|
66
|
+
initial_delay=2,
|
|
67
|
+
connection_timeout=10,
|
|
68
|
+
)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
| Parameter | Default | Description |
|
|
72
|
+
| -------------------- | -------------------- | --------------------------------------------------- |
|
|
73
|
+
| `endpoint` | — (required) | Target URL. |
|
|
74
|
+
| `headers` | `None` | Request headers. |
|
|
75
|
+
| `retry_strategy` | `NO_RETRY_STRATEGY` | See strategies below. |
|
|
76
|
+
| `retries` | `3` | Max attempts. Hard-capped at 5. |
|
|
77
|
+
| `initial_delay` | `1` | Base delay in seconds between retries. |
|
|
78
|
+
| `connection_timeout` | `10` | Per-request timeout in seconds. |
|
|
79
|
+
|
|
80
|
+
## Retry strategies
|
|
81
|
+
|
|
82
|
+
- `NO_RETRY_STRATEGY` — fail fast on the first error.
|
|
83
|
+
- `LINEAR_RETRY_STRATEGY` — wait `initial_delay` seconds before each retry.
|
|
84
|
+
- `EXPONENTIAL_RETRY_STRATEGY` — wait `initial_delay * retry_number` seconds before each retry.
|
|
85
|
+
|
|
86
|
+
Retries are capped at 5 regardless of the `retries` value.
|
|
87
|
+
|
|
88
|
+
## Links
|
|
89
|
+
|
|
90
|
+
- [PyPI](https://pypi.org/project/api-to-dataframe/)
|
|
91
|
+
- [Example notebook](https://github.com/IvanildoBarauna/api-to-dataframe/blob/main/notebooks/example.ipynb)
|
|
92
|
+
- [Issues](https://github.com/IvanildoBarauna/api-to-dataframe/issues)
|
|
93
|
+
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# API to DataFrame
|
|
2
|
+
|
|
3
|
+
Fetch JSON from any HTTP API and turn it into a pandas DataFrame in two calls — with optional retry strategies.
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/api-to-dataframe/#history)
|
|
6
|
+
[](https://pypi.org/project/api-to-dataframe/)
|
|
7
|
+
[](https://pypi.org/project/api-to-dataframe/)
|
|
8
|
+
[](https://github.com/ivanildobarauna-dev/api-to-dataframe/actions/workflows/CI.yaml)
|
|
9
|
+
[](https://app.codecov.io/gh/ivanildobarauna-dev/api-to-dataframe)
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pip install api-to-dataframe
|
|
15
|
+
# or
|
|
16
|
+
poetry add api-to-dataframe
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Requires Python 3.10+.
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from api_to_dataframe import ClientBuilder, RetryStrategies
|
|
25
|
+
|
|
26
|
+
client = ClientBuilder(endpoint="https://api.example.com/items")
|
|
27
|
+
data = client.get_api_data()
|
|
28
|
+
df = client.api_to_dataframe(data)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`api_to_dataframe` expects the response to be a list of dicts. An empty result raises `ValueError`.
|
|
32
|
+
|
|
33
|
+
## Configuration
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
client = ClientBuilder(
|
|
37
|
+
endpoint="https://api.example.com/items",
|
|
38
|
+
headers={"Authorization": "Bearer ..."},
|
|
39
|
+
retry_strategy=RetryStrategies.EXPONENTIAL_RETRY_STRATEGY,
|
|
40
|
+
retries=5,
|
|
41
|
+
initial_delay=2,
|
|
42
|
+
connection_timeout=10,
|
|
43
|
+
)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| Parameter | Default | Description |
|
|
47
|
+
| -------------------- | -------------------- | --------------------------------------------------- |
|
|
48
|
+
| `endpoint` | — (required) | Target URL. |
|
|
49
|
+
| `headers` | `None` | Request headers. |
|
|
50
|
+
| `retry_strategy` | `NO_RETRY_STRATEGY` | See strategies below. |
|
|
51
|
+
| `retries` | `3` | Max attempts. Hard-capped at 5. |
|
|
52
|
+
| `initial_delay` | `1` | Base delay in seconds between retries. |
|
|
53
|
+
| `connection_timeout` | `10` | Per-request timeout in seconds. |
|
|
54
|
+
|
|
55
|
+
## Retry strategies
|
|
56
|
+
|
|
57
|
+
- `NO_RETRY_STRATEGY` — fail fast on the first error.
|
|
58
|
+
- `LINEAR_RETRY_STRATEGY` — wait `initial_delay` seconds before each retry.
|
|
59
|
+
- `EXPONENTIAL_RETRY_STRATEGY` — wait `initial_delay * retry_number` seconds before each retry.
|
|
60
|
+
|
|
61
|
+
Retries are capped at 5 regardless of the `retries` value.
|
|
62
|
+
|
|
63
|
+
## Links
|
|
64
|
+
|
|
65
|
+
- [PyPI](https://pypi.org/project/api-to-dataframe/)
|
|
66
|
+
- [Example notebook](https://github.com/IvanildoBarauna/api-to-dataframe/blob/main/notebooks/example.ipynb)
|
|
67
|
+
- [Issues](https://github.com/IvanildoBarauna/api-to-dataframe/issues)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "api-to-dataframe"
|
|
3
|
-
version = "2.0
|
|
3
|
+
version = "2.2.0"
|
|
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"
|
|
@@ -23,18 +23,17 @@ Issues = "https://github.com/IvanildoBarauna/api-to-dataframe/issues"
|
|
|
23
23
|
Repository = "https://github.com/IvanildoBarauna/api-to-dataframe"
|
|
24
24
|
|
|
25
25
|
[tool.poetry.dependencies]
|
|
26
|
-
python = "^3.
|
|
26
|
+
python = "^3.10"
|
|
27
27
|
pandas = "^2.2.3"
|
|
28
|
-
requests = "^2.
|
|
29
|
-
logging = "^0.4.9.6"
|
|
28
|
+
requests = "^2.33.0"
|
|
30
29
|
|
|
31
30
|
[tool.poetry.group.dev.dependencies]
|
|
32
31
|
poetry-dynamic-versioning = "^1.3.0"
|
|
33
|
-
pytest = "^
|
|
32
|
+
pytest = "^9.0.3"
|
|
34
33
|
coverage = "^7.5.3"
|
|
35
34
|
responses = ">=0.25.3,<0.27.0"
|
|
36
|
-
pylint = "
|
|
37
|
-
black = "^
|
|
35
|
+
pylint = ">=3.2.5,<5.0.0"
|
|
36
|
+
black = "^26.3.1"
|
|
38
37
|
pytest-cov = "^7.0.0"
|
|
39
38
|
|
|
40
39
|
|
|
File without changes
|
{api_to_dataframe-2.0.6 → api_to_dataframe-2.2.0}/src/api_to_dataframe/controller/client_builder.py
RENAMED
|
@@ -7,11 +7,11 @@ class ClientBuilder:
|
|
|
7
7
|
def __init__( # pylint: disable=too-many-positional-arguments,too-many-arguments
|
|
8
8
|
self,
|
|
9
9
|
endpoint: str,
|
|
10
|
-
headers: dict = None,
|
|
10
|
+
headers: dict | None = None,
|
|
11
11
|
retry_strategy: Strategies = Strategies.NO_RETRY_STRATEGY,
|
|
12
12
|
retries: int = 3,
|
|
13
13
|
initial_delay: int = 1,
|
|
14
|
-
connection_timeout: int =
|
|
14
|
+
connection_timeout: int = 10,
|
|
15
15
|
):
|
|
16
16
|
"""
|
|
17
17
|
Initializes the ClientBuilder object.
|
|
@@ -20,14 +20,14 @@ class ClientBuilder:
|
|
|
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
22
|
retry_strategy (Strategies, optional): Defaults to Strategies.NO_RETRY_STRATEGY.
|
|
23
|
-
retries (int): The number of
|
|
23
|
+
retries (int): The number of attempts to make. Must be >= 1. 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 10.
|
|
26
26
|
|
|
27
27
|
Raises:
|
|
28
28
|
ValueError: If endpoint is an empty string.
|
|
29
|
-
ValueError: If retries is not a
|
|
30
|
-
ValueError: If
|
|
29
|
+
ValueError: If retries is not a positive integer (>= 1).
|
|
30
|
+
ValueError: If initial_delay is not a non-negative integer.
|
|
31
31
|
ValueError: If connection_timeout is not a non-negative integer.
|
|
32
32
|
"""
|
|
33
33
|
|
|
@@ -36,19 +36,19 @@ class ClientBuilder:
|
|
|
36
36
|
if endpoint == "":
|
|
37
37
|
error_msg = "endpoint cannot be an empty string"
|
|
38
38
|
logger.error(error_msg)
|
|
39
|
-
raise ValueError
|
|
40
|
-
if not isinstance(retries, int) or retries <
|
|
41
|
-
error_msg = "retries must be a
|
|
39
|
+
raise ValueError(error_msg)
|
|
40
|
+
if not isinstance(retries, int) or isinstance(retries, bool) or retries < 1:
|
|
41
|
+
error_msg = "retries must be a positive integer (>= 1)"
|
|
42
42
|
logger.error(error_msg)
|
|
43
|
-
raise ValueError
|
|
44
|
-
if not isinstance(initial_delay, int) or initial_delay < 0:
|
|
43
|
+
raise ValueError(error_msg)
|
|
44
|
+
if not isinstance(initial_delay, int) or isinstance(initial_delay, bool) or initial_delay < 0:
|
|
45
45
|
error_msg = "initial_delay must be a non-negative integer"
|
|
46
46
|
logger.error(error_msg)
|
|
47
|
-
raise ValueError
|
|
48
|
-
if not isinstance(connection_timeout, int) or connection_timeout < 0:
|
|
47
|
+
raise ValueError(error_msg)
|
|
48
|
+
if not isinstance(connection_timeout, int) or isinstance(connection_timeout, bool) or connection_timeout < 0:
|
|
49
49
|
error_msg = "connection_timeout must be a non-negative integer"
|
|
50
50
|
logger.error(error_msg)
|
|
51
|
-
raise ValueError
|
|
51
|
+
raise ValueError(error_msg)
|
|
52
52
|
|
|
53
53
|
self.endpoint = endpoint
|
|
54
54
|
self.retry_strategy = retry_strategy
|
|
@@ -58,14 +58,10 @@ class ClientBuilder:
|
|
|
58
58
|
self.delay = initial_delay
|
|
59
59
|
|
|
60
60
|
@retry_strategies
|
|
61
|
-
def get_api_data(self):
|
|
61
|
+
def get_api_data(self) -> dict:
|
|
62
62
|
"""
|
|
63
63
|
Retrieves data from the API using the defined endpoint and retry strategy.
|
|
64
64
|
|
|
65
|
-
This function sends a request to the API using the endpoint, headers, and
|
|
66
|
-
connection timeout specified in the instance attributes. It uses the
|
|
67
|
-
defined retry strategy to handle potential failures and retries.
|
|
68
|
-
|
|
69
65
|
Returns:
|
|
70
66
|
dict: The JSON response from the API as a dictionary.
|
|
71
67
|
"""
|
|
@@ -82,10 +78,6 @@ class ClientBuilder:
|
|
|
82
78
|
"""
|
|
83
79
|
Converts an API response to a DataFrame.
|
|
84
80
|
|
|
85
|
-
This function takes a dictionary response from an API,
|
|
86
|
-
uses the `to_dataframe` function from the `GetData` class
|
|
87
|
-
to convert it into a DataFrame, and logs the operation as successful.
|
|
88
|
-
|
|
89
81
|
Args:
|
|
90
82
|
response (dict): The dictionary containing the API response.
|
|
91
83
|
|
|
File without changes
|
|
@@ -13,13 +13,13 @@ class Strategies(Enum):
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
def retry_strategies(func):
|
|
16
|
-
def wrapper(*args, **kwargs):
|
|
16
|
+
def wrapper(*args, **kwargs):
|
|
17
17
|
retry_number = 0
|
|
18
18
|
while retry_number < args[0].retries:
|
|
19
19
|
try:
|
|
20
20
|
if retry_number > 0:
|
|
21
21
|
logger.info(
|
|
22
|
-
f"
|
|
22
|
+
f"Attempt {retry_number} of {min(args[0].retries, Constants.MAX_OF_RETRIES)}. Strategy: {args[0].retry_strategy}"
|
|
23
23
|
)
|
|
24
24
|
return func(*args, **kwargs)
|
|
25
25
|
except RequestException as e:
|
|
@@ -27,13 +27,13 @@ def retry_strategies(func):
|
|
|
27
27
|
|
|
28
28
|
if args[0].retry_strategy == Strategies.NO_RETRY_STRATEGY:
|
|
29
29
|
raise e
|
|
30
|
-
|
|
30
|
+
elif args[0].retry_strategy == Strategies.LINEAR_RETRY_STRATEGY:
|
|
31
31
|
time.sleep(args[0].delay)
|
|
32
32
|
elif args[0].retry_strategy == Strategies.EXPONENTIAL_RETRY_STRATEGY:
|
|
33
33
|
time.sleep(args[0].delay * retry_number)
|
|
34
34
|
|
|
35
35
|
if retry_number in (args[0].retries, Constants.MAX_OF_RETRIES):
|
|
36
|
-
logger.error(f"Failed after {retry_number}
|
|
36
|
+
logger.error(f"Failed after {retry_number} attempts")
|
|
37
37
|
raise e
|
|
38
38
|
|
|
39
39
|
return wrapper
|
api_to_dataframe-2.0.6/PKG-INFO
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: api-to-dataframe
|
|
3
|
-
Version: 2.0.6
|
|
4
|
-
Summary: A package to convert API responses to pandas dataframe
|
|
5
|
-
License: MIT
|
|
6
|
-
Author: IvanildoBarauna
|
|
7
|
-
Author-email: ivanildo.jnr@outlook.com
|
|
8
|
-
Requires-Python: >=3.9,<4.0
|
|
9
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
-
Classifier: Intended Audience :: Developers
|
|
11
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
-
Classifier: Programming Language :: Python :: 3
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
-
Requires-Dist: logging (>=0.4.9.6,<0.5.0.0)
|
|
18
|
-
Requires-Dist: pandas (>=2.2.3,<3.0.0)
|
|
19
|
-
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
20
|
-
Project-URL: Documentation, https://github.com/IvanildoBarauna/api-to-dataframe/blob/main/README.md
|
|
21
|
-
Project-URL: Homepage, https://pypi.org/project/api-to-dataframe
|
|
22
|
-
Project-URL: ImplementationCase, https://github.com/IvanildoBarauna/ETL-awesome-api
|
|
23
|
-
Project-URL: Issues, https://github.com/IvanildoBarauna/api-to-dataframe/issues
|
|
24
|
-
Project-URL: Notebook, https://github.com/IvanildoBarauna/api-to-dataframe/blob/main/notebooks/example.ipynb
|
|
25
|
-
Project-URL: Repository, https://github.com/IvanildoBarauna/api-to-dataframe
|
|
26
|
-
Description-Content-Type: text/markdown
|
|
27
|
-
|
|
28
|
-
# API to DataFrame
|
|
29
|
-
Python library that simplifies obtaining data from API endpoints by converting them directly into Pandas DataFrames. This library offers robust features, including retry strategies for failed requests.
|
|
30
|
-
|
|
31
|
-
[](https://deepwiki.com/ivanildobarauna-dev/api-to-dataframe)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
[](https://pypi.org/project/api-to-dataframe/)
|
|
35
|
-
[](https://pypi.org/project/api-to-dataframe/)
|
|
36
|
-
[](https://pypi.org/project/api-to-dataframe/#history)
|
|
37
|
-
|
|
38
|
-

|
|
39
|
-
|
|
40
|
-
[](https://github.com/ivanildobarauna-dev/api-to-dataframe/actions/workflows/CI.yaml)
|
|
41
|
-
[](https://github.com/ivanildobarauna-dev/api-to-dataframe/actions/workflows/CD.yaml)
|
|
42
|
-
|
|
43
|
-
[](https://app.codecov.io/gh/ivanildobarauna-dev/api-to-dataframe)
|
|
44
|
-
|
|
45
|
-
## Project Stack
|
|
46
|
-
|
|
47
|
-

|
|
48
|
-

|
|
49
|
-

|
|
50
|
-

|
|
51
|
-

|
|
52
|
-

|
|
53
|
-

|
|
54
|
-

|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
## Installation
|
|
58
|
-
|
|
59
|
-
To install the package using pip, use the following command:
|
|
60
|
-
|
|
61
|
-
```sh
|
|
62
|
-
pip install api-to-dataframe
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
To install the package using poetry, use the following command:
|
|
66
|
-
|
|
67
|
-
```sh
|
|
68
|
-
poetry add api-to-dataframe
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## User Guide
|
|
72
|
-
|
|
73
|
-
``` python
|
|
74
|
-
## Importing library
|
|
75
|
-
from api_to_dataframe import ClientBuilder, RetryStrategies
|
|
76
|
-
|
|
77
|
-
# Create a client for simple ingest data from API (timeout 1 second)
|
|
78
|
-
client = ClientBuilder(endpoint="https://api.example.com")
|
|
79
|
-
|
|
80
|
-
# if you can define timeout with LINEAR_RETRY_STRATEGY and set headers:
|
|
81
|
-
headers = {
|
|
82
|
-
"application_name": "api_to_dataframe"
|
|
83
|
-
}
|
|
84
|
-
client = ClientBuilder(endpoint="https://api.example.com"
|
|
85
|
-
,retry_strategy=RetryStrategies.LINEAR_RETRY_STRATEGY
|
|
86
|
-
,connection_timeout=2
|
|
87
|
-
,headers=headers)
|
|
88
|
-
|
|
89
|
-
# if you can define timeout with EXPONENTIAL_RETRY_STRATEGY and set headers:
|
|
90
|
-
client = ClientBuilder(endpoint="https://api.example.com"
|
|
91
|
-
,retry_strategy=RetryStrategies.EXPONENTIAL_RETRY_STRATEGY
|
|
92
|
-
,connection_timeout=10
|
|
93
|
-
,headers=headers
|
|
94
|
-
,retries=5
|
|
95
|
-
,initial_delay=10)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
# Get data from the API
|
|
99
|
-
data = client.get_api_data()
|
|
100
|
-
|
|
101
|
-
# Convert the data to a DataFrame
|
|
102
|
-
df = client.api_to_dataframe(data)
|
|
103
|
-
|
|
104
|
-
# Display the DataFrame
|
|
105
|
-
print(df)
|
|
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
|
-
|
api_to_dataframe-2.0.6/README.md
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
# API to DataFrame
|
|
2
|
-
Python library that simplifies obtaining data from API endpoints by converting them directly into Pandas DataFrames. This library offers robust features, including retry strategies for failed requests.
|
|
3
|
-
|
|
4
|
-
[](https://deepwiki.com/ivanildobarauna-dev/api-to-dataframe)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[](https://pypi.org/project/api-to-dataframe/)
|
|
8
|
-
[](https://pypi.org/project/api-to-dataframe/)
|
|
9
|
-
[](https://pypi.org/project/api-to-dataframe/#history)
|
|
10
|
-
|
|
11
|
-

|
|
12
|
-
|
|
13
|
-
[](https://github.com/ivanildobarauna-dev/api-to-dataframe/actions/workflows/CI.yaml)
|
|
14
|
-
[](https://github.com/ivanildobarauna-dev/api-to-dataframe/actions/workflows/CD.yaml)
|
|
15
|
-
|
|
16
|
-
[](https://app.codecov.io/gh/ivanildobarauna-dev/api-to-dataframe)
|
|
17
|
-
|
|
18
|
-
## Project Stack
|
|
19
|
-
|
|
20
|
-

|
|
21
|
-

|
|
22
|
-

|
|
23
|
-

|
|
24
|
-

|
|
25
|
-

|
|
26
|
-

|
|
27
|
-

|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
## Installation
|
|
31
|
-
|
|
32
|
-
To install the package using pip, use the following command:
|
|
33
|
-
|
|
34
|
-
```sh
|
|
35
|
-
pip install api-to-dataframe
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
To install the package using poetry, use the following command:
|
|
39
|
-
|
|
40
|
-
```sh
|
|
41
|
-
poetry add api-to-dataframe
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## User Guide
|
|
45
|
-
|
|
46
|
-
``` python
|
|
47
|
-
## Importing library
|
|
48
|
-
from api_to_dataframe import ClientBuilder, RetryStrategies
|
|
49
|
-
|
|
50
|
-
# Create a client for simple ingest data from API (timeout 1 second)
|
|
51
|
-
client = ClientBuilder(endpoint="https://api.example.com")
|
|
52
|
-
|
|
53
|
-
# if you can define timeout with LINEAR_RETRY_STRATEGY and set headers:
|
|
54
|
-
headers = {
|
|
55
|
-
"application_name": "api_to_dataframe"
|
|
56
|
-
}
|
|
57
|
-
client = ClientBuilder(endpoint="https://api.example.com"
|
|
58
|
-
,retry_strategy=RetryStrategies.LINEAR_RETRY_STRATEGY
|
|
59
|
-
,connection_timeout=2
|
|
60
|
-
,headers=headers)
|
|
61
|
-
|
|
62
|
-
# if you can define timeout with EXPONENTIAL_RETRY_STRATEGY and set headers:
|
|
63
|
-
client = ClientBuilder(endpoint="https://api.example.com"
|
|
64
|
-
,retry_strategy=RetryStrategies.EXPONENTIAL_RETRY_STRATEGY
|
|
65
|
-
,connection_timeout=10
|
|
66
|
-
,headers=headers
|
|
67
|
-
,retries=5
|
|
68
|
-
,initial_delay=10)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
# Get data from the API
|
|
72
|
-
data = client.get_api_data()
|
|
73
|
-
|
|
74
|
-
# Convert the data to a DataFrame
|
|
75
|
-
df = client.api_to_dataframe(data)
|
|
76
|
-
|
|
77
|
-
# Display the DataFrame
|
|
78
|
-
print(df)
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
## Important notes:
|
|
82
|
-
* **Opcionals Parameters:** The params timeout, retry_strategy and headers are opcionals.
|
|
83
|
-
* **Default Params Value:** By default the quantity of retries is 3 and the time between retries is 1 second, but you can define manually.
|
|
84
|
-
* **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.
|
|
85
|
-
* **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
|
|
86
|
-
|
|
87
|
-
RetryNumber | WaitingTime
|
|
88
|
-
------------ | -----------
|
|
89
|
-
2 | 2s
|
|
90
|
-
2 | 4s
|
|
91
|
-
3 | 6s
|
|
92
|
-
4 | 8s
|
|
93
|
-
5 | 10s
|
|
94
|
-
* **Linear Retry Strategy:** The increment of time between retries is time passed in **initial_delay**
|
|
95
|
-
e.g with initial_delay=2
|
|
96
|
-
|
|
97
|
-
RetryNumber | WaitingTime
|
|
98
|
-
------------ | -----------
|
|
99
|
-
1 | 2s
|
|
100
|
-
2 | 2s
|
|
101
|
-
3 | 2s
|
|
102
|
-
4 | 2s
|
|
103
|
-
5 | 2s
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
|
|
3
|
-
logging.basicConfig(
|
|
4
|
-
encoding="utf-8",
|
|
5
|
-
format="%(asctime)s :: api-to-dataframe[%(levelname)s] :: %(message)s",
|
|
6
|
-
datefmt="%Y-%m-%d %H:%M:%S %Z",
|
|
7
|
-
level=logging.INFO,
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
# Initialize traditional logger
|
|
11
|
-
logger = logging.getLogger("api-to-dataframe")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|