A package to convert API responses to pandas dataframe
Project description
API to DataFrame
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.
Project Stack
Installation
To install the package using pip, use the following command:
pip install api-to-dataframe
To install the package using poetry, use the following command:
poetry add api-to-dataframe
User Guide
## Importing library
from api_to_dataframe import ClientBuilder, RetryStrategies
# Create a client for simple ingest data from API (timeout 1 second)
client = ClientBuilder(endpoint="https://api.example.com")
# if you can define timeout with LINEAR_RETRY_STRATEGY and set headers:
headers = {
"application_name": "api_to_dataframe"
}
client = ClientBuilder(endpoint="https://api.example.com"
,retry_strategy=RetryStrategies.LINEAR_RETRY_STRATEGY
,connection_timeout=2
,headers=headers)
# if you can define timeout with EXPONENTIAL_RETRY_STRATEGY and set headers:
client = ClientBuilder(endpoint="https://api.example.com"
,retry_strategy=RetryStrategies.EXPONENTIAL_RETRY_STRATEGY
,connection_timeout=10
,headers=headers
,retries=5
,initial_delay=10)
# 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)
Important notes:
-
Opcionals Parameters: The params timeout, retry_strategy and headers are opcionals.
-
Default Params Value: By default the quantity of retries is 3 and the time between retries is 1 second, but you can define manually.
-
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.
-
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
RetryNumber WaitingTime 2 2s 2 4s 3 6s 4 8s 5 10s -
Linear Retry Strategy: The increment of time between retries is time passed in initial_delay e.g with initial_delay=2
RetryNumber WaitingTime 1 2s 2 2s 3 2s 4 2s 5 2s
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file api_to_dataframe-1.3.11.tar.gz
.
File metadata
- Download URL: api_to_dataframe-1.3.11.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.20 Linux/6.8.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c2e4fe51553f2edad63b27916e7f1b1583cc1485836155858bec458380214df |
|
MD5 | 2c2e54a6e7ace2bf3d0407f05ca6479a |
|
BLAKE2b-256 | deb23b40ebeeb3d73c22c30b825342601491924631ed645b34b2ac8cace55b45 |
File details
Details for the file api_to_dataframe-1.3.11-py3-none-any.whl
.
File metadata
- Download URL: api_to_dataframe-1.3.11-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.20 Linux/6.8.0-1014-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a13a384ef8c875bbe1e595759ba8480d73158a2b625b8003c1e5ec3eb3754d2f |
|
MD5 | 2d9a5da205ae417f1b39e713d587012e |
|
BLAKE2b-256 | 19e9bb3e2bf178dcc2e41939358ae6f8716e04d201cef8a24d3dac52582faa52 |