Skip to content

Commit efe2161

Browse files
authored
Merge branch 'add-ruff-and-uv' into implement-offers-v2
2 parents 5d8730d + e305a7c commit efe2161

File tree

12 files changed

+287
-79
lines changed

12 files changed

+287
-79
lines changed

.github/workflows/check.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ permissions:
1010
pull-requests: read
1111

1212
jobs:
13+
changelog:
14+
if: github.event_name == 'pull_request'
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v5
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Check CHANGELOG was updated
22+
run: |
23+
if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -q "^CHANGELOG.md$"; then
24+
echo "✅ CHANGELOG.md was updated"
25+
else
26+
echo "❌ ERROR: CHANGELOG.md was not updated"
27+
echo "Please add your changes to the CHANGELOG.md file"
28+
exit 1
29+
fi
30+
1331
check:
1432
runs-on: ubuntu-latest
1533
env:
@@ -56,8 +74,7 @@ jobs:
5674
strategy:
5775
fail-fast: false
5876
matrix:
59-
python-version:
60-
["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.15"]
77+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.15"]
6178

6279
steps:
6380
- uses: actions/checkout@v5

.github/workflows/release.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Create Release
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: write
8+
9+
jobs:
10+
release:
11+
runs-on: ubuntu-latest
12+
if: github.ref == 'refs/heads/master'
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v5
17+
18+
- name: Extract version and notes from CHANGELOG
19+
id: changelog
20+
run: |
21+
# Extract version from first ## [x.x.x] header
22+
VERSION=$(grep -m1 -oP '## \[\K[0-9]+\.[0-9]+\.[0-9]+' CHANGELOG.md)
23+
echo "version=$VERSION" >> $GITHUB_OUTPUT
24+
25+
# Extract release notes (content between first and second ## headers)
26+
NOTES=$(awk '/^## \['"$VERSION"'\]/{flag=1; next} /^## \[/{flag=0} flag' CHANGELOG.md)
27+
28+
# Handle multiline output
29+
{
30+
echo "notes<<EOF"
31+
echo "$NOTES"
32+
echo "EOF"
33+
} >> $GITHUB_OUTPUT
34+
35+
- name: Check if tag already exists
36+
id: check_tag
37+
run: |
38+
if git rev-parse "v${{ steps.changelog.outputs.version }}" >/dev/null 2>&1; then
39+
echo "exists=true" >> $GITHUB_OUTPUT
40+
else
41+
echo "exists=false" >> $GITHUB_OUTPUT
42+
fi
43+
44+
- name: Create Release
45+
if: steps.check_tag.outputs.exists == 'false'
46+
uses: softprops/action-gh-release@v2
47+
with:
48+
tag_name: ${{ steps.changelog.outputs.version }}
49+
name: v${{ steps.changelog.outputs.version }}
50+
body: ${{ steps.changelog.outputs.notes }}
51+
draft: false
52+
prerelease: false
53+
54+
- name: Skip release (tag exists)
55+
if: steps.check_tag.outputs.exists == 'true'
56+
run: |
57+
echo "⚠️ Tag v${{ steps.changelog.outputs.version }} already exists. Skipping release creation."
58+
exit 1

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,10 @@ repos:
5252
entry: "bash -c 'set -a && source .env 2>/dev/null; set +a && uv run pytest -rs --cov=amazon_paapi'"
5353
types_or: [python]
5454
pass_filenames: false
55+
56+
- id: version-check
57+
name: Check version consistency
58+
language: system
59+
entry: uv run python scripts/check_version.py
60+
files: (CHANGELOG\.md|pyproject\.toml|docs/conf\.py)$
61+
pass_filenames: false

.readthedocs.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
# .readthedocs.yaml
21
# Read the Docs configuration file
32
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
43

5-
# Required
64
version: 2
75

8-
# Build documentation in the docs/ directory with Sphinx
6+
build:
7+
os: ubuntu-24.04
8+
tools:
9+
python: "3.12"
10+
911
sphinx:
10-
configuration: docs/conf.py
12+
configuration: docs/conf.py
1113

12-
# Optionally build your docs in additional formats such as PDF
1314
formats:
14-
- pdf
15+
- pdf
1516

16-
# Optionally set the version of Python and requirements required to build your docs
1717
python:
18-
version: 3
19-
install:
20-
- method: pip
21-
path: .
22-
- requirements: docs/requirements.txt
18+
install:
19+
- method: pip
20+
path: .
21+
- requirements: docs/requirements.txt

CHANGELOG.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [5.1.0] - 2026-01-11
9+
10+
### Added
11+
12+
- Integration tests with real Amazon API calls
13+
- Type hints throughout the codebase using `Literal` types for country codes
14+
- `.env.template` file for easier development setup
15+
- Code style guide for AI assistants (`.agent/rules/code-style-guide.md`)
16+
- Pre-commit hooks with Ruff integration
17+
- Version consistency check script (`scripts/check_version.py`)
18+
- Manual release workflow (`release.yml`) that creates GitHub releases from CHANGELOG
19+
- CI check to ensure CHANGELOG is updated in every PR
20+
21+
### Changed
22+
23+
- **BREAKING**: Minimum Python version raised from 3.7 to 3.9
24+
- Migrated from `setup.py` to `pyproject.toml` for project configuration
25+
- Replaced multiple linters (Flake8, isort, Black, Pylint) with Ruff
26+
- Replaced Docker-based development environment with `uv` package manager
27+
- Consolidated coverage, mypy, and pytest configuration into `pyproject.toml`
28+
- Renamed test files to use `_test.py` suffix instead of `test_` prefix
29+
- Updated GitHub Actions workflows to use `uv` instead of Docker
30+
- Improved docstrings across the codebase
31+
- Completely rewritten README with clearer structure and examples
32+
- Updated Read the Docs configuration to v2 format with modern Sphinx versions
33+
34+
### Removed
35+
36+
- `setup.py` - replaced by `pyproject.toml`
37+
- `.coveragerc` - configuration moved to `pyproject.toml`
38+
- `.flake8` - replaced by Ruff configuration in `pyproject.toml`
39+
- Docker development environment (`docker/`, `docker-compose.yml`)
40+
- Legacy shell scripts (`scripts/` directory)
41+
- Custom git hooks (`.githooks/`) - replaced by pre-commit

README.md

Lines changed: 69 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,129 @@
1-
# Amazon Product Advertising API 5.0 wrapper for Python
1+
# Python Amazon PAAPI
22

3-
A simple Python wrapper for the [last version of the Amazon Product Advertising
4-
API](https://webservices.amazon.com/paapi5/documentation/quick-start/using-sdk.html).
5-
This module allows interacting with Amazon using the official API in an easier way.
3+
A simple Python wrapper for the [Amazon Product Advertising API 5.0](https://webservices.amazon.com/paapi5/documentation/). Easily interact with Amazon's official API to retrieve product information, search for items, and more.
64

75
[![PyPI](https://img.shields.io/pypi/v/python-amazon-paapi?color=%231182C2&label=PyPI)](https://pypi.org/project/python-amazon-paapi/)
8-
[![Python](https://img.shields.io/badge/Python->3.9-%23FFD140)](https://www.python.org/)
6+
[![Python](https://img.shields.io/badge/Python-3.9-%23FFD140)](https://www.python.org/)
97
[![License](https://img.shields.io/badge/License-MIT-%23e83633)](https://github.com/sergioteula/python-amazon-paapi/blob/master/LICENSE)
108
[![Amazon API](https://img.shields.io/badge/Amazon%20API-5.0-%23FD9B15)](https://webservices.amazon.com/paapi5/documentation/)
11-
[![PyPI - Downloads](https://img.shields.io/pypi/dm/python-amazon-paapi?label=Installs)](https://pypi.org/project/python-amazon-paapi/)
9+
[![Downloads](https://img.shields.io/pypi/dm/python-amazon-paapi?label=Downloads)](https://pypi.org/project/python-amazon-paapi/)
1210

1311
## Features
1412

15-
- Object oriented interface for simple usage.
16-
- Get information about a product through its ASIN or URL.
17-
- Get item variations or search for products on Amazon.
18-
- Get browse nodes information.
19-
- Get multiple results at once without the 10 items limitation from Amazon.
20-
- Configurable throttling to avoid requests exceptions.
21-
- Type hints to help you coding.
22-
- Support for [all available countries](https://github.com/sergioteula/python-amazon-paapi/blob/956f639b2ab3eab3f61644ae2ca8ae6500881312/amazon_paapi/models/regions.py#L1).
23-
- Ask for new features through the [issues](https://github.com/sergioteula/python-amazon-paapi/issues) section.
24-
- Join our [Telegram group](https://t.me/PythonAmazonPAAPI) for support or development.
25-
- Check the [documentation](https://python-amazon-paapi.readthedocs.io/en/latest/index.html) for reference.
13+
- 🎯 **Simple object-oriented interface** for easy integration
14+
- 🔍 **Product search** by keywords, categories, or browse nodes
15+
- 📦 **Product details** via ASIN or Amazon URL
16+
- 🔄 **Item variations** support (size, color, etc.)
17+
- 🌍 **20+ countries** supported ([full list](https://github.com/sergioteula/python-amazon-paapi/blob/master/amazon_paapi/models/regions.py))
18+
-**Batch requests** to get multiple items without the 10-item limit
19+
- 🛡️ **Built-in throttling** to avoid API rate limits
20+
- 📝 **Full type hints** for better IDE support
2621

2722
## Installation
2823

29-
You can install or upgrade the module with:
30-
31-
pip install python-amazon-paapi --upgrade
32-
33-
## Usage guide
24+
```bash
25+
pip install python-amazon-paapi --upgrade
26+
```
3427

35-
**Basic usage:**
28+
## Quick Start
3629

3730
```python
3831
from amazon_paapi import AmazonApi
32+
33+
# Initialize the API (get credentials from Amazon Associates)
3934
amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY)
35+
36+
# Get product information by ASIN
4037
item = amazon.get_items('B01N5IB20Q')[0]
41-
print(item.item_info.title.display_value) # Item title
38+
print(item.item_info.title.display_value)
4239
```
4340

44-
**Get multiple items information:**
41+
## Usage Examples
42+
43+
### Get Multiple Products
4544

4645
```python
4746
items = amazon.get_items(['B01N5IB20Q', 'B01F9G43WU'])
4847
for item in items:
49-
print(item.images.primary.large.url) # Primary image url
50-
print(item.offers.listings[0].price.amount) # Current price
48+
print(item.images.primary.large.url)
49+
print(item.offers.listings[0].price.amount)
5150
```
5251

53-
**Use URL insted of ASIN:**
52+
### Use Amazon URL Instead of ASIN
5453

5554
```python
5655
item = amazon.get_items('https://www.amazon.com/dp/B01N5IB20Q')
5756
```
5857

59-
**Get item variations:**
58+
### Search Products
6059

6160
```python
62-
variations = amazon.get_variations('B01N5IB20Q')
63-
for item in variations.items:
64-
print(item.detail_page_url) # Affiliate url
61+
results = amazon.search_items(keywords='nintendo switch')
62+
for item in results.items:
63+
print(item.item_info.title.display_value)
6564
```
6665

67-
**Search items:**
66+
### Get Product Variations
6867

6968
```python
70-
search_result = amazon.search_items(keywords='nintendo')
71-
for item in search_result.items:
72-
print(item.item_info.product_info.color) # Item color
69+
variations = amazon.get_variations('B01N5IB20Q')
70+
for item in variations.items:
71+
print(item.detail_page_url)
7372
```
7473

75-
**Get browse node information:**
74+
### Get Browse Node Information
7675

7776
```python
78-
browse_nodes = amazon.get_browse_nodes(['667049031', '599385031'])
79-
for browse_node in browse_nodes:
80-
print(browse_node.display_name) # The name of the node
77+
nodes = amazon.get_browse_nodes(['667049031', '599385031'])
78+
for node in nodes:
79+
print(node.display_name)
8180
```
8281

83-
**Get the ASIN from URL:**
82+
### Extract ASIN from URL
8483

8584
```python
8685
from amazon_paapi import get_asin
86+
8787
asin = get_asin('https://www.amazon.com/dp/B01N5IB20Q')
88+
# Returns: 'B01N5IB20Q'
8889
```
8990

90-
**Throttling:**
91+
### Configure Throttling
9192

92-
Throttling value represents the wait time in seconds between API calls, being the
93-
default value 1 second. Use it to avoid reaching Amazon request limits.
93+
Control the wait time between API calls to avoid rate limits:
9494

9595
```python
96-
amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY, throttling=4) # Makes 1 request every 4 seconds
97-
amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY, throttling=0) # No wait time between requests
96+
# Wait 4 seconds between requests
97+
amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY, throttling=4)
98+
99+
# No throttling (use with caution)
100+
amazon = AmazonApi(KEY, SECRET, TAG, COUNTRY, throttling=0)
98101
```
99102

100-
## Contribution
103+
## Documentation
101104

102-
Creating pull requests for this repo is higly appreciated to add new features or solve
103-
bugs. To help during development process, githooks can be activated to run some scripts
104-
before pushing new commits. This will run checks for code format and tests, to ensure
105-
everything follows this repo guidelines. Use next command to activate them:
105+
- 📖 [Full Documentation](https://python-amazon-paapi.readthedocs.io/)
106+
- 📋 [Changelog](https://github.com/sergioteula/python-amazon-paapi/blob/master/CHANGELOG.md)
107+
- 💬 [Telegram Support Group](https://t.me/PythonAmazonPAAPI)
106108

109+
## Contributing
110+
111+
Contributions are welcome! To get started:
112+
113+
1. Install [uv](https://docs.astral.sh/uv/) package manager
114+
2. Clone and set up the project:
115+
116+
```bash
117+
git clone https://github.com/sergioteula/python-amazon-paapi.git
118+
cd python-amazon-paapi
119+
uv sync
120+
uv run pre-commit install
107121
```
108-
git config core.hooksPath .githooks
109-
```
110122

111-
The same checks will also run on the repo with GitHub Actions to ensure all tests pass
112-
before merge.
123+
3. Copy `.env.template` to `.env` and add your Amazon API credentials for integration tests.
124+
125+
Pre-commit hooks will automatically run Ruff, mypy, and tests before each commit.
113126

114127
## License
115128

116-
Copyright © 2026 Sergio Abad. See
117-
[license](https://github.com/sergioteula/python-amazon-paapi/blob/master/LICENSE) for
118-
details.
129+
MIT License © 2026 [Sergio Abad](https://github.com/sergioteula)

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
# -- Project information -----------------------------------------------------
2020

2121
project = "python-amazon-paapi"
22-
copyright = "2021, Sergio Abad"
22+
copyright = "2026, Sergio Abad"
2323
author = "Sergio Abad"
2424

2525
# The full version, including alpha/beta/rc tags
26-
release = "4.2.0"
26+
release = "5.1.0"
2727

2828

2929
# -- General configuration ---------------------------------------------------
@@ -38,7 +38,7 @@
3838
autodoc_typehints = "none"
3939

4040
# Add any paths that contain templates here, relative to this directory.
41-
templates_path = ["_templates"]
41+
# templates_path = ["_templates"]
4242

4343
# List of patterns, relative to source directory, that match files and
4444
# directories to ignore when looking for source files.

0 commit comments

Comments
 (0)