Skip to content

Commit 9ec2aa4

Browse files
Merge pull request #41 from IvanildoBarauna/feature/Documentations
docs: Update Readme + Added Docs Strings + Include only constructor
2 parents 23635f8 + b188dae commit 9ec2aa4

File tree

4 files changed

+86
-9
lines changed

4 files changed

+86
-9
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Your solution to convert API responses to Pandas DataFrames with retry strategie
1212
[![CI](https://img.shields.io/github/actions/workflow/status/IvanildoBarauna/api-to-dataframe/CI.yaml?&style=for-the-badge&logo=githubactions&cacheSeconds=60&label=Tests+and+pre+build)](https://github.com/IvanildoBarauna/api-to-dataframe/actions/workflows/CI.yaml)
1313
[![CD](https://img.shields.io/github/actions/workflow/status/IvanildoBarauna/api-to-dataframe/CD.yaml?&style=for-the-badge&logo=githubactions&cacheSeconds=60&event=release&label=Package_publication)](https://github.com/IvanildoBarauna/api-to-dataframe/actions/workflows/CD.yaml)
1414

15-
![Codecov](https://img.shields.io/codecov/c/github/IvanildoBarauna/api-to-dataframe?style=for-the-badge&logo=codecov)
15+
[![Codecov](https://img.shields.io/codecov/c/github/IvanildoBarauna/api-to-dataframe?style=for-the-badge&logo=codecov)](https://app.codecov.io/gh/IvanildoBarauna/api-to-dataframe)
1616

1717
## Project Stack
1818

@@ -31,3 +31,37 @@ Your solution to convert API responses to Pandas DataFrames with retry strategie
3131

3232
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 and automatic generation of detailed reports on the received data.
3333

34+
## Installation
35+
36+
To install the package using pip, use the following command:
37+
38+
```sh
39+
pip install api-to-dataframe
40+
```
41+
42+
To install the package using poetry, use the following command:
43+
44+
```sh
45+
poetry add api-to-dataframe
46+
```
47+
48+
## How to use it
49+
50+
``` python
51+
## Importing library
52+
from api_to_dataframe import ClientBuilder, RetryStrategies
53+
54+
# Create a client for the API without retry strategy
55+
client = ClientBuilder(endpoint="https://api.example.com", retry_strategy=RetryStrategies.NoRetryStrategy)
56+
# or with LinearStrategy (In development, actually don't nothing)
57+
client = ClientBuilder(endpoint="https://api.example.com", retry_strategy=RetryStrategies.LinearStrategy)
58+
59+
# Get data from the API
60+
data = client.get_api_data()
61+
62+
# Convert the data to a DataFrame
63+
df = client.api_to_dataframe(data)
64+
65+
# Display the DataFrame
66+
print(df)
67+
```

pyproject.toml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
[tool.poetry]
22
name = "api-to-dataframe"
3-
version = "1.0.1"
3+
version = "1.0.2"
44
description = "A package to convert API responses to pandas dataframe"
55
authors = ["IvanildoBarauna <ivanildo.jnr@outlook.com>"]
66
readme = "README.md"
77
license = "MIT"
8-
packages = [{ include = "api_to_dataframe", from = "src" }]
98
classifiers=[
109
"Development Status :: 2 - Pre-Alpha",
1110
"Intended Audience :: Developers",
@@ -14,15 +13,24 @@ classifiers=[
1413
"Programming Language :: Python :: 3.8",
1514
]
1615

16+
homepage = "https://github.com/IvanildoBarauna/api-to-dataframe"
17+
repository = "https://github.com/IvanildoBarauna/api-to-dataframe"
18+
documentation = "https://github.com/IvanildoBarauna/api-to-dataframe#readme"
19+
20+
[tool.poetry.urls]
21+
Homepage = "https://github.com/IvanildoBarauna/api-to-dataframe"
22+
Documentation = "https://github.com/IvanildoBarauna/api-to-dataframe#readme"
23+
Issues = "https://github.com/IvanildoBarauna/api-to-dataframe/issues"
24+
25+
[tool.setuptools.packages.find]
26+
where = ["src"]
27+
include = ["api_to_dataframe*"]
28+
1729
[tool.poetry.group.dev.dependencies]
1830
poetry-dynamic-versioning = "^1.3.0"
1931
pytest = "^8.2.2"
2032
coverage = "^7.5.3"
2133

22-
[tool.project.urls]
23-
url="https://github.com/IvanidoBarauna/api-to-dataframe"
24-
license="MIT"
25-
2634
[tool.poetry.dependencies]
2735
python = "^3.9"
2836
pandas = "^2.2.2"

src/api_to_dataframe/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
from api_to_dataframe.controller.client_builder import ClientBuilder
2-
from api_to_dataframe.common.utils.retry_strategies import RetryStrategies
1+
from .controller.client_builder import ClientBuilder
2+
from .common.utils.retry_strategies import RetryStrategies
3+
4+
__all__ = ['ClientBuilder', 'RetryStrategies']

src/api_to_dataframe/controller/client_builder.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,51 @@
33

44

55
class ClientBuilder:
6+
"""
7+
Builder for creating clients that interact with an API endpoint and return data.
8+
9+
Attributes:
10+
endpoint (str): The API endpoint to be accessed.
11+
retry_strategy (RetryStrategies): The retry strategy for the request. Default is NoRetryStrategy.
12+
"""
13+
614
def __init__(self, endpoint: str, retry_strategy: RetryStrategies = RetryStrategies.NoRetryStrategy):
15+
"""
16+
Initializes an instance of ClientBuilder.
17+
18+
Args:
19+
endpoint (str): The API endpoint to be accessed.
20+
retry_strategy (RetryStrategies, optional): The retry strategy for the request. Default is NoRetryStrategy.
21+
22+
Raises:
23+
ValueError: If the endpoint is empty.
24+
"""
725
if endpoint == "":
826
raise ValueError("::: endpoint param is mandatory :::")
927
else:
1028
self.endpoint = endpoint
1129
self.retry_strategy = retry_strategy
1230

1331
def get_api_data(self):
32+
"""
33+
Retrieves data from the API using the defined endpoint and retry strategy.
34+
35+
Returns:
36+
dict: The response from the API.
37+
"""
1438
response = GetData.get_response(self.endpoint, self.retry_strategy)
1539
return response
1640

1741
@staticmethod
1842
def api_to_dataframe(response: dict):
43+
"""
44+
Converts the API response into a DataFrame.
45+
46+
Args:
47+
response (dict): The response from the API.
48+
49+
Returns:
50+
DataFrame: The data converted into a DataFrame.
51+
"""
1952
df = GetData.to_dataframe(response)
2053
return df

0 commit comments

Comments
 (0)