Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Your solution to convert API responses to Pandas DataFrames with retry strategie
[![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)
[![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)

![Codecov](https://img.shields.io/codecov/c/github/IvanildoBarauna/api-to-dataframe?style=for-the-badge&logo=codecov)
[![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)

## Project Stack

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

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.

## Installation

To install the package using pip, use the following command:

```sh
pip install api-to-dataframe
```

To install the package using poetry, use the following command:

```sh
poetry add api-to-dataframe
```

## How to use it

``` python
## Importing library
from api_to_dataframe import ClientBuilder, RetryStrategies

# Create a client for the API without retry strategy
client = ClientBuilder(endpoint="https://api.example.com", retry_strategy=RetryStrategies.NoRetryStrategy)
# or with LinearStrategy (In development, actually don't nothing)
client = ClientBuilder(endpoint="https://api.example.com", retry_strategy=RetryStrategies.LinearStrategy)

# Get data from the API
data = client.get_api_data()

# Convert the data to a DataFrame
df = client.api_to_dataframe(data)

# Display the DataFrame
print(df)
```
20 changes: 14 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[tool.poetry]
name = "api-to-dataframe"
version = "1.0.1"
version = "1.0.2"
description = "A package to convert API responses to pandas dataframe"
authors = ["IvanildoBarauna <ivanildo.jnr@outlook.com>"]
readme = "README.md"
license = "MIT"
packages = [{ include = "api_to_dataframe", from = "src" }]
classifiers=[
"Development Status :: 2 - Pre-Alpha",
"Intended Audience :: Developers",
Expand All @@ -14,15 +13,24 @@ classifiers=[
"Programming Language :: Python :: 3.8",
]

homepage = "https://github.com/IvanildoBarauna/api-to-dataframe"
repository = "https://github.com/IvanildoBarauna/api-to-dataframe"
documentation = "https://github.com/IvanildoBarauna/api-to-dataframe#readme"

[tool.poetry.urls]
Homepage = "https://github.com/IvanildoBarauna/api-to-dataframe"
Documentation = "https://github.com/IvanildoBarauna/api-to-dataframe#readme"
Issues = "https://github.com/IvanildoBarauna/api-to-dataframe/issues"

[tool.setuptools.packages.find]
where = ["src"]
include = ["api_to_dataframe*"]

[tool.poetry.group.dev.dependencies]
poetry-dynamic-versioning = "^1.3.0"
pytest = "^8.2.2"
coverage = "^7.5.3"

[tool.project.urls]
url="https://github.com/IvanidoBarauna/api-to-dataframe"
license="MIT"

[tool.poetry.dependencies]
python = "^3.9"
pandas = "^2.2.2"
Expand Down
6 changes: 4 additions & 2 deletions src/api_to_dataframe/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from api_to_dataframe.controller.client_builder import ClientBuilder
from api_to_dataframe.common.utils.retry_strategies import RetryStrategies
from .controller.client_builder import ClientBuilder
from .common.utils.retry_strategies import RetryStrategies

__all__ = ['ClientBuilder', 'RetryStrategies']
33 changes: 33 additions & 0 deletions src/api_to_dataframe/controller/client_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,51 @@


class ClientBuilder:
"""
Builder for creating clients that interact with an API endpoint and return data.

Attributes:
endpoint (str): The API endpoint to be accessed.
retry_strategy (RetryStrategies): The retry strategy for the request. Default is NoRetryStrategy.
"""

def __init__(self, endpoint: str, retry_strategy: RetryStrategies = RetryStrategies.NoRetryStrategy):
"""
Initializes an instance of ClientBuilder.

Args:
endpoint (str): The API endpoint to be accessed.
retry_strategy (RetryStrategies, optional): The retry strategy for the request. Default is NoRetryStrategy.

Raises:
ValueError: If the endpoint is empty.
"""
if endpoint == "":
raise ValueError("::: endpoint param is mandatory :::")
else:
self.endpoint = endpoint
self.retry_strategy = retry_strategy

def get_api_data(self):
"""
Retrieves data from the API using the defined endpoint and retry strategy.

Returns:
dict: The response from the API.
"""
response = GetData.get_response(self.endpoint, self.retry_strategy)
return response

@staticmethod
def api_to_dataframe(response: dict):
"""
Converts the API response into a DataFrame.

Args:
response (dict): The response from the API.

Returns:
DataFrame: The data converted into a DataFrame.
"""
df = GetData.to_dataframe(response)
return df