Skip to content

Commit d9a407e

Browse files
authored
Merge pull request #143 from sergioteula/add-async-support
Add async support to Creators API
2 parents 07be5e9 + 0aaa213 commit d9a407e

File tree

25 files changed

+3336
-65
lines changed

25 files changed

+3336
-65
lines changed

.github/workflows/check.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ jobs:
3535
API_SECRET: ${{ secrets.API_SECRET }}
3636
AFFILIATE_TAG: ${{ secrets.AFFILIATE_TAG }}
3737
COUNTRY_CODE: ${{ secrets.COUNTRY_CODE }}
38+
CREDENTIAL_ID: ${{ secrets.CREDENTIAL_ID }}
39+
CREDENTIAL_SECRET: ${{ secrets.CREDENTIAL_SECRET }}
40+
API_VERSION: ${{ secrets.API_VERSION }}
3841

3942
steps:
4043
- uses: actions/checkout@v5
@@ -65,7 +68,7 @@ jobs:
6568
6669
- name: Run all checks
6770
run: |
68-
uv run pre-commit run --all-files
71+
uv run --extra async pre-commit run --all-files --verbose
6972
7073
test:
7174
runs-on: ubuntu-latest
@@ -91,4 +94,4 @@ jobs:
9194
${{ runner.os }}-uv-py${{ matrix.python-version }}-
9295
9396
- name: Run tests
94-
run: uv run --python "${{ matrix.python-version }}" pytest -rs --no-cov
97+
run: uv run --python "${{ matrix.python-version }}" --extra async pytest -rs --no-cov

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [6.1.0] - 2026-02-09
9+
10+
### Added
11+
12+
- Full async/await support with new `amazon_creatorsapi.aio` subpackage ([#143](https://github.com/sergioteula/python-amazon-paapi/pull/143))
13+
- `AsyncAmazonCreatorsApi` class for non-blocking API interactions
14+
- Async HTTP client with `httpx` integration for connection pooling
15+
- `AuthenticationError` exception for improved OAuth2 error handling
16+
- Optional `[async]` installation extra: `pip install python-amazon-paapi[async]`
17+
- Comprehensive async test suite with integration tests
18+
- Documentation for async API usage in README and usage guide
19+
- `make docs` command in Makefile for building documentation
20+
21+
### Changed
22+
23+
- GitHub Actions workflow now installs async dependencies for complete test coverage
24+
- Test coverage threshold lowered from 99% to 98% to accommodate async tests
25+
- Additional Ruff linting rules for test files (ARG002, S101, S105, S106, SIM117)
26+
827
## [6.0.0] - 2026-01-29
928

1029
### Added

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ mypy:
3030

3131
pre-commit:
3232
@uv run pre-commit run -a
33+
34+
docs:
35+
@cd docs && uv run make html
36+
37+
.PHONY: setup test coverage test-all-python-tags lint format mypy pre-commit docs

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ A Python wrapper for Amazon's product APIs. This package supports both the legac
1313
## Features
1414

1515
- 🎯 **Simple object-oriented interface** for easy integration
16-
- 🔍 **Product search** by keywords, categories, or browse nodes
16+
-**Async/await support** for high-performance applications
17+
- �🔍 **Product search** by keywords, categories, or browse nodes
1718
- 📦 **Product details** via ASIN or Amazon URL
1819
- 🔄 **Item variations** support (size, color, etc.)
1920
- 💰 **OffersV2 support** for enhanced pricing and offer details
@@ -118,6 +119,40 @@ amazon = AmazonCreatorsApi(ID, SECRET, VERSION, TAG, COUNTRY, throttling=4) # M
118119
amazon = AmazonCreatorsApi(ID, SECRET, VERSION, TAG, COUNTRY, throttling=0) # No wait time between requests
119120
```
120121

122+
### Async Support
123+
124+
For async/await applications, use the async version of the API with `httpx`:
125+
126+
```bash
127+
pip install python-amazon-paapi[async] --upgrade
128+
```
129+
130+
The async API provides the same methods as the synchronous version, but they must be called with `await`:
131+
132+
```python
133+
from amazon_creatorsapi.aio import AsyncAmazonCreatorsApi
134+
from amazon_creatorsapi import Country
135+
136+
# Use as async context manager (recommended for connection pooling)
137+
async with AsyncAmazonCreatorsApi(
138+
credential_id="your_credential_id",
139+
credential_secret="your_credential_secret",
140+
version="2.2",
141+
tag="your-affiliate-tag",
142+
country=Country.US,
143+
) as api:
144+
items = await api.get_items(["B01N5IB20Q"])
145+
results = await api.search_items(keywords="laptop")
146+
variations = await api.get_variations("B01N5IB20Q")
147+
nodes = await api.get_browse_nodes(["667049031"])
148+
149+
# Or use without context manager (creates new connection per request)
150+
api = AsyncAmazonCreatorsApi(ID, SECRET, VERSION, TAG, COUNTRY)
151+
items = await api.get_items(["B01N5IB20Q"])
152+
```
153+
154+
> **Note:** All synchronous methods and parameters work identically in async mode. Use `async with` for better performance when making multiple API calls.
155+
121156
### Working with Models
122157

123158
All SDK models are re-exported through `amazon_creatorsapi.models` for convenient access:

amazon_creatorsapi/aio/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Async support for Amazon Creators API."""
2+
3+
try:
4+
import httpx # noqa: F401
5+
except ImportError as exc: # pragma: no cover
6+
msg = (
7+
"httpx is required for async support. "
8+
"Install it with: pip install python-amazon-paapi[async]"
9+
)
10+
raise ImportError(msg) from exc
11+
12+
from amazon_creatorsapi.aio.api import AsyncAmazonCreatorsApi
13+
14+
__all__ = ["AsyncAmazonCreatorsApi"]

0 commit comments

Comments
 (0)