DynaFetch
A robust Python client for fetching paginated data from OData/REST APIs, with a focus on Dynamics Business Central integration. DynaFetch provides automatic pagination handling, retry logic, and comprehensive error handling.
Features
- 🔄 Automatic pagination handling
- 🔁 Built-in retry logic with exponential backoff
- 🛡️ Comprehensive error handling
- ⏱️ Configurable timeouts and retry settings
- 🔑 Support for basic authentication
- 📊 Flexible response data extraction
- 🚀 Session management for efficient connections
Installation
pip install dynafetch
Quick Start
from dynafetch import DynaFetchClient
# Initialize the client with your API credentials
client = DynaFetchClient(
base_url="https://api.example.com",
credentials=("username", "password")
)
# Fetch all data from an endpoint
data = client.get_data("customers")
Detailed Usage
Basic Authentication
from dynafetch import DynaFetchClient
# Initialize with basic authentication
client = DynaFetchClient(
base_url="https://api.example.com",
credentials=("username", "password")
)
Using a Custom Session
import requests
from dynafetch import DynaFetchClient
# Create a custom session with specific configurations
session = requests.Session()
session.headers.update({"Custom-Header": "value"})
# Initialize with custom session
client = DynaFetchClient(
base_url="https://api.example.com",
session=session
)
Fetching Data with Parameters
# Fetch data with query parameters
data = client.get_data(
endpoint="customers",
params={
"$filter": "status eq 'active'",
"$select": "id,name,email",
"$top": 100
}
)
Handling Single Pages
# Fetch a single page of data
page = client.get_single_page(
endpoint="customers",
params={"$top": 50}
)
Custom Headers
# Set default headers for all requests
client.set_default_headers({
"Accept": "application/json",
"Custom-Header": "value"
})
# Or provide headers for specific requests
data = client.get_data(
endpoint="customers",
headers={"Custom-Header": "specific-value"}
)
Configuration Options
The DynaFetchClient accepts the following configuration options:
| Parameter | Type | Default | Description |
|---|---|---|---|
base_url |
str | Required | Base URL for the API |
session |
requests.Session | None | Pre-configured requests session |
credentials |
tuple[str, str] | None | Tuple of (username, password) for basic auth |
timeout |
int | 30 | Request timeout in seconds |
max_retries |
int | 3 | Maximum number of retry attempts |
retry_delay |
float | 1.0 | Initial delay between retries (uses exponential backoff) |
data_key |
str | "value" | Key in response JSON containing the data array |
next_link_key |
str | "@odata.nextLink" | Key in response JSON containing the next page URL |
Error Handling
DynaFetch provides comprehensive error handling through the DynaFetchError exception:
from dynafetch import DynaFetchClient, DynaFetchError
try:
client = DynaFetchClient(
base_url="https://api.example.com",
credentials=("username", "password")
)
data = client.get_data("customers")
except DynaFetchError as e:
print(f"Error fetching data: {e}")
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for pydynafetch 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pydynafetch-0.1.0.tar.gz | 11.2 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydynafetch-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.6 kB
Release files / pydynafetch-0.1.0.tar.gz
| Download URL | pydynafetch-0.1.0.tar.gz |
|---|---|
| Size | 11.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
539e8b21b34612e2e4c4d0f653c46f8fd492f228bf3bf07ef74091f0436b9f5c
|
|
BLAKE2b-256 checksum How to use checksums |
28e744f03ae86f69646385c9ebbbd7f1514a1e0a8b2561b8556050561d5b4648
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 30, 2025.
Transparency logRelease files / pydynafetch-0.1.0-py3-none-any.whl
| Download URL | pydynafetch-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2584e1c02058b8ac8dcf9c95663ff60b50740d1dbfd10ef2d33625ca88db3e64
|
|
BLAKE2b-256 checksum How to use checksums |
933ba008b1608d6de18da1ad4429d18de8e2bf7703b97092e67672bda9069af7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 30, 2025.
Transparency logSecurity for pydynafetch 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for pydynafetch-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 30, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.