A python client for Dynamics Business Central OData API
Project description
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.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydynafetch-0.1.0.tar.gz.
File metadata
- Download URL: pydynafetch-0.1.0.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
539e8b21b34612e2e4c4d0f653c46f8fd492f228bf3bf07ef74091f0436b9f5c
|
|
| MD5 |
73459e46c4fd63716bc8ed9b47f6ce30
|
|
| BLAKE2b-256 |
28e744f03ae86f69646385c9ebbbd7f1514a1e0a8b2561b8556050561d5b4648
|
Provenance
The following attestation bundles were made for pydynafetch-0.1.0.tar.gz:
Publisher:
ci-cd.yml on akshaypra26/dynafetch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydynafetch-0.1.0.tar.gz -
Subject digest:
539e8b21b34612e2e4c4d0f653c46f8fd492f228bf3bf07ef74091f0436b9f5c - Sigstore transparency entry: 225186807
- Sigstore integration time:
-
Permalink:
akshaypra26/dynafetch@ff3fc2d1b29eba28f01b9bafcc6c4fe8e6dbf7aa -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/akshaypra26
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci-cd.yml@ff3fc2d1b29eba28f01b9bafcc6c4fe8e6dbf7aa -
Trigger Event:
push
-
Statement type:
File details
Details for the file pydynafetch-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydynafetch-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2584e1c02058b8ac8dcf9c95663ff60b50740d1dbfd10ef2d33625ca88db3e64
|
|
| MD5 |
8c67b9d412bf526778e6dd1783da9fba
|
|
| BLAKE2b-256 |
933ba008b1608d6de18da1ad4429d18de8e2bf7703b97092e67672bda9069af7
|
Provenance
The following attestation bundles were made for pydynafetch-0.1.0-py3-none-any.whl:
Publisher:
ci-cd.yml on akshaypra26/dynafetch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydynafetch-0.1.0-py3-none-any.whl -
Subject digest:
2584e1c02058b8ac8dcf9c95663ff60b50740d1dbfd10ef2d33625ca88db3e64 - Sigstore transparency entry: 225186813
- Sigstore integration time:
-
Permalink:
akshaypra26/dynafetch@ff3fc2d1b29eba28f01b9bafcc6c4fe8e6dbf7aa -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/akshaypra26
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci-cd.yml@ff3fc2d1b29eba28f01b9bafcc6c4fe8e6dbf7aa -
Trigger Event:
push
-
Statement type: