From ff00acb07fa04ef54c995143316e39f7cef5b78b Mon Sep 17 00:00:00 2001 From: Ivanildo Barauna de Souza Junior Date: Sat, 15 Jun 2024 01:07:13 -0300 Subject: [PATCH] docs: Update Readme + Added Docs Strings + Include only constructor --- README.md | 36 ++++++++++++++++++- pyproject.toml | 20 +++++++---- src/api_to_dataframe/__init__.py | 6 ++-- .../controller/client_builder.py | 33 +++++++++++++++++ 4 files changed, 86 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e7a6143..438056c 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) +``` \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 5e0f763..76079b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] readme = "README.md" license = "MIT" -packages = [{ include = "api_to_dataframe", from = "src" }] classifiers=[ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", @@ -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" diff --git a/src/api_to_dataframe/__init__.py b/src/api_to_dataframe/__init__.py index f4f2620..d6947d0 100644 --- a/src/api_to_dataframe/__init__.py +++ b/src/api_to_dataframe/__init__.py @@ -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'] diff --git a/src/api_to_dataframe/controller/client_builder.py b/src/api_to_dataframe/controller/client_builder.py index 0d68f81..bb9495f 100644 --- a/src/api_to_dataframe/controller/client_builder.py +++ b/src/api_to_dataframe/controller/client_builder.py @@ -3,7 +3,25 @@ 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: @@ -11,10 +29,25 @@ def __init__(self, endpoint: str, retry_strategy: RetryStrategies = RetryStrateg 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