Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 62 additions & 13 deletions .github/workflows/main-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
task: [lint, test]
task: [lint]
include:
- task: lint
command: make lint
- task: test
command: make test
name: ${{ matrix.task }}
steps:
- name: Download workspace
Expand All @@ -78,7 +76,7 @@ jobs:

- name: Install & configure poetry
run: |
python -m pip install poetry==1.4.2
python -m pip install poetry==1.7.1
python -m poetry config virtualenvs.in-project true

- name: Cache poetry virtualenv
Expand All @@ -95,8 +93,38 @@ jobs:
- name: Run ${{ matrix.task }}
run: python -m poetry run ${{ matrix.command }}

test:
needs: setup
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
name: Test Python ${{ matrix.python-version }}
steps:
- name: Download workspace
uses: actions/download-artifact@v4
with:
name: workspace

- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install & configure poetry
run: |
python -m pip install poetry==1.7.1
python -m poetry config virtualenvs.in-project true

- name: Install dependencies
run: python -m poetry install

- name: Run tests
run: python -m poetry run make test
timeout-minutes: 5

release:
needs: verify
needs: [verify, test]
runs-on: ubuntu-latest
concurrency: release
outputs:
Expand All @@ -117,22 +145,43 @@ jobs:

- name: Action | Semantic Version Release
id: release
# Adjust tag with desired version if applicable.
uses: python-semantic-release/python-semantic-release@v9.15.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
git_committer_name: "github-actions"
git_committer_email: "actions@users.noreply.github.com"

# Add PyPI publishing steps
- name: Build package
# Add Poetry-based PyPI publishing steps
- name: Set up python
if: steps.release.outputs.released == 'true'
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install poetry
if: steps.release.outputs.released == 'true'
run: |
python -m pip install poetry==1.7.1
python -m poetry config virtualenvs.in-project true

- name: Configure poetry credentials
if: steps.release.outputs.released == 'true'
run: |
python -m pip install build
python -m build
python -m poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }}

- name: Publish to PyPI
- name: Build and publish
if: steps.release.outputs.released == 'true'
uses: pypa/gh-action-pypi-publish@v1.8.14
run: |
python -m poetry build
python -m poetry publish

- name: Upload workspace
uses: actions/upload-artifact@v4
with:
password: ${{ secrets.PYPI_API_TOKEN }}
name: workspace
include-hidden-files: true
path: |
.
!.git
!.github
!.venv/**/!(*.py)
81 changes: 71 additions & 10 deletions .github/workflows/pull-request-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,29 @@ jobs:
shell: bash
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for semantic-release

- name: Set up python
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install & configure poetry
run: |
python -m pip install poetry==1.7.1
python -m poetry config virtualenvs.in-project true

- name: Cache poetry virtualenv
uses: actions/cache@v4
with:
path: ./.venv
key: ${{ runner.os }}-venv-${{ hashFiles('**/poetry.lock') }}

- name: Install poetry dependencies
run: |
python -m poetry install

- name: Upload workspace
uses: actions/upload-artifact@v4
with:
Expand All @@ -38,44 +45,98 @@ jobs:
!.github
!.venv
!node_modules

verify:
needs: setup
runs-on: ubuntu-latest
strategy:
matrix:
task: [lint, test]
task: [lint]
include:
- task: lint
command: make lint
- task: test
command: make test
name: ${{ matrix.task }}
steps:
- name: Download workspace
uses: actions/download-artifact@v4
with:
name: workspace

- name: Set up python
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install & configure poetry
run: |
python -m pip install poetry==1.7.1
python -m poetry config virtualenvs.in-project true

- name: Cache poetry virtualenv
uses: actions/cache@v4
with:
path: ./.venv
key: ${{ runner.os }}-venv-${{ hashFiles('**/poetry.lock') }}
- name: Cache node_modules
uses: actions/cache@v4
with:
path: '**/node_modules'
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node_modules-

- name: Install dependencies
run: python -m poetry install

- name: Run ${{ matrix.task }}
run: python -m poetry run ${{ matrix.command }}
timeout-minutes: 5
timeout-minutes: 5

test:
needs: setup
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
name: Test Python ${{ matrix.python-version }}
steps:
- name: Download workspace
uses: actions/download-artifact@v4
with:
name: workspace

- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install & configure poetry
run: |
python -m pip install poetry==1.7.1
python -m poetry config virtualenvs.in-project true

- name: Install dependencies
run: python -m poetry install

- name: Run tests
run: python -m poetry run make test
timeout-minutes: 5

semantic-release-dry-run:
needs: setup
runs-on: ubuntu-latest
name: Semantic Release Dry Run
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for semantic-release to access git history
ref: ${{ github.head_ref }} # This checks out the PR source branch

- name: Set up python
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install semantic-release
run: |
python -m pip install python-semantic-release==9.15.1

- name: Dry Run Semantic Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
semantic-release --noop version
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "selling-partner-api-models"]
path = selling-partner-api-models
url = https://github.com/amzn/selling-partner-api-models.git
ignore = all
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# py-sp-api

<https://developer-docs.amazon.com/sp-api/docs/tutorial-automate-your-sp-api-calls-using-python-sdk>
This is a python version of ths Amazon Seller API
<https://developer-docs.amazon.com/sp-api/docs/>

We use the openapi generator <https://openapi-generator.tech/> to convert the amazon sp-api
swagger api models <https://github.com/amzn/selling-partner-api-models.git> into a python package.

This creates a requiests base API with pydantic types. Awesome!

This project consists of tweaks I had to make to aws auth schemes to get things working
with the openapi generator client, the generator script that creates the models and a
little bit of documentation. Nothing fancy.

## Prerequisites

- python 3.9+
- amazon seller api credentials. See the docs <https://developer-docs.amazon.com/sp-api/docs/>

## Installation

Expand Down Expand Up @@ -53,11 +68,16 @@ test_get_pricing(asin="B0DP7GSWC8")

## Development

This is a poetry project so do the normal `poetry install` type things to set up your environment.

We use a Makefile for build automation.

- `make clean` removes the generated code
- `make generate` generates the schemas
- `make test` runs unit tests
- `make lint-fix` fixes linting issues and checks compliance with linting standards

### Structure
### Project Structure

```text
.
Expand All @@ -70,6 +90,7 @@ test_get_pricing(asin="B0DP7GSWC8")
├── selling-partner-api-models - git submodule from <https://github.com/amzn/selling-partner-api-models.git>
├── scripts
│ └── generate_schemas.py - script to generate api
├── tests - unit tests. (just enough to make sure things generated without error)
└── src
└── py_sp_api
├── auth - copied from selling-partner-api-models/clients/sellingpartner-api-aa-python/auth
Expand Down
Loading
Loading