async-amazon-ads-api-v1 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. async_amazon_ads_api_v1-0.3.0/.github/workflows/publish.yml +43 -0
  2. async_amazon_ads_api_v1-0.3.0/.gitignore +34 -0
  3. async_amazon_ads_api_v1-0.3.0/AGENTS.md +152 -0
  4. async_amazon_ads_api_v1-0.3.0/LICENSE +21 -0
  5. async_amazon_ads_api_v1-0.3.0/PKG-INFO +197 -0
  6. async_amazon_ads_api_v1-0.3.0/README.md +173 -0
  7. async_amazon_ads_api_v1-0.3.0/pyproject.toml +85 -0
  8. async_amazon_ads_api_v1-0.3.0/scripts/AmazonAdsAPISBMerged_prod_3p.json +10725 -0
  9. async_amazon_ads_api_v1-0.3.0/scripts/AmazonAdsAPISDMerged_prod_3p.json +5909 -0
  10. async_amazon_ads_api_v1-0.3.0/scripts/AmazonAdsAPISPMerged_prod_3p.json +7095 -0
  11. async_amazon_ads_api_v1-0.3.0/scripts/download_spec.py +47 -0
  12. async_amazon_ads_api_v1-0.3.0/scripts/generate_all.py +52 -0
  13. async_amazon_ads_api_v1-0.3.0/scripts/generate_file_structure.py +450 -0
  14. async_amazon_ads_api_v1-0.3.0/scripts/generate_models.py +364 -0
  15. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/__init__.py +30 -0
  16. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/_base.py +171 -0
  17. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sb/__init__.py +121 -0
  18. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sb/ad_extensions.py +39 -0
  19. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sb/ad_groups.py +41 -0
  20. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sb/ads.py +37 -0
  21. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sb/advertising_deal_targets.py +41 -0
  22. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sb/advertising_deals.py +44 -0
  23. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sb/branded_keywords_pricings.py +24 -0
  24. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sb/campaigns.py +41 -0
  25. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sb/keyword_reservation_validations.py +24 -0
  26. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sb/recommendation_types.py +26 -0
  27. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sb/recommendations.py +24 -0
  28. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sb/targets.py +41 -0
  29. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sd/__init__.py +65 -0
  30. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sd/ad_groups.py +41 -0
  31. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sd/ads.py +37 -0
  32. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sd/campaigns.py +41 -0
  33. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sd/targets.py +41 -0
  34. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sp/__init__.py +73 -0
  35. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sp/ad_extensions.py +40 -0
  36. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sp/ad_groups.py +43 -0
  37. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sp/ads.py +39 -0
  38. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sp/campaigns.py +43 -0
  39. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/client/sp/targets.py +43 -0
  40. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/config/__init__.py +1 -0
  41. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/config/loader.py +82 -0
  42. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/config/region.py +20 -0
  43. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/config/settings.py +136 -0
  44. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/config/token_cache.py +192 -0
  45. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/config/token_manager.py +124 -0
  46. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/errors.py +144 -0
  47. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/base.py +3 -0
  48. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sb/__init__.py +34 -0
  49. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sb/ad_extensions.py +262 -0
  50. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sb/ad_groups.py +197 -0
  51. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sb/ads.py +973 -0
  52. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sb/advertising_deal_targets.py +153 -0
  53. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sb/advertising_deals.py +220 -0
  54. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sb/branded_keywords_pricings.py +96 -0
  55. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sb/campaigns.py +724 -0
  56. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sb/enums.py +205 -0
  57. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sb/keyword_reservation_validations.py +67 -0
  58. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sb/recommendation_types.py +37 -0
  59. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sb/recommendations.py +177 -0
  60. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sb/shared.py +176 -0
  61. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sb/targets.py +585 -0
  62. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sd/__init__.py +27 -0
  63. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sd/ad_groups.py +348 -0
  64. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sd/ads.py +518 -0
  65. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sd/campaigns.py +413 -0
  66. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sd/enums.py +193 -0
  67. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sd/shared.py +97 -0
  68. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sd/targets.py +661 -0
  69. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sp/__init__.py +28 -0
  70. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sp/ad_extensions.py +300 -0
  71. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sp/ad_groups.py +275 -0
  72. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sp/ads.py +390 -0
  73. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sp/campaigns.py +706 -0
  74. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sp/enums.py +197 -0
  75. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sp/shared.py +217 -0
  76. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/models/sp/targets.py +668 -0
  77. async_amazon_ads_api_v1-0.3.0/src/async_amazon_ads_api_v1/py.typed +0 -0
  78. async_amazon_ads_api_v1-0.3.0/tests/__init__.py +0 -0
  79. async_amazon_ads_api_v1-0.3.0/tests/client/__init__.py +0 -0
  80. async_amazon_ads_api_v1-0.3.0/tests/client/test_mock_server_integration.py +139 -0
  81. async_amazon_ads_api_v1-0.3.0/tests/client/test_resources.py +241 -0
  82. async_amazon_ads_api_v1-0.3.0/tests/client/test_sb_client.py +129 -0
  83. async_amazon_ads_api_v1-0.3.0/tests/client/test_sd_client.py +63 -0
  84. async_amazon_ads_api_v1-0.3.0/tests/client/test_sp_client.py +70 -0
  85. async_amazon_ads_api_v1-0.3.0/tests/conftest.py +59 -0
  86. async_amazon_ads_api_v1-0.3.0/tests/e2e/PROGRESS.md +235 -0
  87. async_amazon_ads_api_v1-0.3.0/tests/e2e/README.md +121 -0
  88. async_amazon_ads_api_v1-0.3.0/tests/e2e/__init__.py +1 -0
  89. async_amazon_ads_api_v1-0.3.0/tests/e2e/config.py +39 -0
  90. async_amazon_ads_api_v1-0.3.0/tests/e2e/conftest.py +90 -0
  91. async_amazon_ads_api_v1-0.3.0/tests/e2e/helpers.py +44 -0
  92. async_amazon_ads_api_v1-0.3.0/tests/e2e/test_ads_api_context.py +102 -0
  93. async_amazon_ads_api_v1-0.3.0/tests/e2e/test_profile_isolation.py +54 -0
  94. async_amazon_ads_api_v1-0.3.0/tests/e2e/test_sp_ad_groups.py +76 -0
  95. async_amazon_ads_api_v1-0.3.0/tests/e2e/test_sp_campaigns.py +75 -0
  96. async_amazon_ads_api_v1-0.3.0/tests/test_base.py +265 -0
  97. async_amazon_ads_api_v1-0.3.0/tests/test_config.py +125 -0
  98. async_amazon_ads_api_v1-0.3.0/tests/test_errors.py +129 -0
  99. async_amazon_ads_api_v1-0.3.0/tests/test_init.py +43 -0
  100. async_amazon_ads_api_v1-0.3.0/tests/test_token_cache.py +169 -0
  101. async_amazon_ads_api_v1-0.3.0/uv.lock +970 -0
@@ -0,0 +1,43 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+
13
+ - uses: actions/setup-python@v5
14
+ with:
15
+ python-version: "3.13"
16
+
17
+ - name: Install uv
18
+ uses: astral-sh/setup-uv@v4
19
+
20
+ - name: Install dependencies
21
+ run: uv sync
22
+
23
+ - name: Build package
24
+ run: uv run hatchling build
25
+
26
+ - uses: actions/upload-artifact@v4
27
+ with:
28
+ name: dist
29
+ path: dist/
30
+
31
+ publish:
32
+ needs: build
33
+ runs-on: ubuntu-latest
34
+ environment: pypi
35
+ permissions:
36
+ id-token: write
37
+ steps:
38
+ - uses: actions/download-artifact@v4
39
+ with:
40
+ name: dist
41
+ path: dist/
42
+
43
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,34 @@
1
+ # Claude Code settings(本地,不提交)
2
+ .claude/
3
+
4
+ # Byte-compiled / optimized / DLL files
5
+ __pycache__/
6
+ *.py[cod]
7
+ *$py.class
8
+
9
+ # Caches
10
+ .mypy_cache/
11
+ .ruff_cache/
12
+ .pytest_cache/
13
+
14
+ # IDE
15
+ .idea/
16
+
17
+ # Virtual environments
18
+ .venv/
19
+ venv/
20
+ ENV/
21
+
22
+ # uv.lock 由 uv 管理,需提交
23
+
24
+ # OS
25
+ .DS_Store
26
+ *.swp
27
+ *.swo
28
+
29
+ # Distribution / build
30
+ *.egg-info/
31
+ dist/
32
+ build/
33
+
34
+ .dist/
@@ -0,0 +1,152 @@
1
+ # Amazon Ads SDK
2
+
3
+ Pure async Python SDK for the Amazon Advertising API — Sponsored Products / Sponsored Brands / Sponsored Display.
4
+
5
+ ## 项目结构
6
+
7
+ ```
8
+ .
9
+ ├── scripts/
10
+ │ ├── AmazonAdsAPISPMerged_prod_3p.json # SP OpenAPI 规范(不修改)
11
+ │ ├── AmazonAdsAPISBMerged_prod_3p.json # SB OpenAPI 规范
12
+ │ ├── AmazonAdsAPISDMerged_prod_3p.json # SD OpenAPI 规范
13
+ │ ├── download_spec.py # 下载 OpenAPI 规范
14
+ │ ├── generate_all.py # 一键生成所有产品模型
15
+ │ ├── generate_file_structure.py # 通用 schema 分类器(无硬编码)
16
+ │ └── generate_models.py # 从 JSON Schema 生成 Pydantic 模型
17
+ ├── README.md
18
+ ├── AGENTS.md # 本文件
19
+ ├── LICENSE # MIT 许可证
20
+ ├── pyproject.toml # uv 项目配置
21
+ ├── uv.lock # 依赖锁定
22
+ └── src/async_amazon_ads_api_v1/
23
+ ├── __init__.py # 导出所有公开 API
24
+ ├── _base.py # ClientContext + _ResourceBase + _ResourceSpec
25
+ ├── errors.py # 共享 HTTP 错误模型 (ErrorCode, Error, ErrorsIndex ...)
26
+ ├── py.typed # PEP 561 类型标记
27
+ ├── config/
28
+ │ ├── __init__.py
29
+ │ ├── loader.py # from_toml() 配置加载
30
+ │ ├── region.py # Region 枚举 + ENDPOINT_MAP
31
+ │ ├── settings.py # AmazonAdsConfig / CacheBackend
32
+ │ ├── token_cache.py # BaseTokenCache / FileTokenCache / RedisTokenCache
33
+ │ └── token_manager.py # TokenManager / TokenCredentials
34
+ ├── models/
35
+ │ ├── base.py
36
+ │ ├── sp/ # SP 模型(自动生成)
37
+ │ ├── sb/ # SB 模型(自动生成)
38
+ │ └── sd/ # SD 模型(自动生成)
39
+ └── client/
40
+ ├── sp/ # SPClient + 5 资源类
41
+ ├── sb/ # SBClient + 11 资源类
42
+ └── sd/ # SDClient + 4 资源类
43
+ ```
44
+
45
+ ## 项目概述
46
+
47
+ 核心使用 **httpx** 构建 Amazon Ads API 纯异步 SDK,支持三种广告产品。
48
+
49
+ ## 核心环境要求 (CRITICAL)
50
+
51
+ - **环境管理**: **必须**使用 `uv` 进行依赖管理、虚拟环境创建及任务执行。
52
+ - **Python 版本**:
53
+ - 最小支持版本为 **Python 3.13**。
54
+ - **优先兼容 Python 3.13+** 及后续更高版本。
55
+ - **禁止**考虑对 Python 3.12 及以下版本的向后兼容性。
56
+ - **特性使用**: 鼓励使用 Python 3.13+ 引入的新特性。
57
+
58
+ ## 代码质量 (MUST)
59
+
60
+ - **格式化**: 必须使用 `black` 格式化代码。
61
+ - **静态检查**: 必须使用 `ruff check --fix` 移除未使用的 imports/variables。
62
+ - 保存前执行这两条命令。
63
+
64
+ ## Git 提交规范
65
+
66
+ - **语言**: `git commit` 信息尽量使用**中文**。
67
+ - **术语**: 术语如 `uv`, `Python 3.14`, `asyncio`, `httpx`, `Pydantic` 等保持**英文**。
68
+ - **格式示例**: `feat: 使用 uv 同步依赖,支持 Python 3.14 特性`
69
+
70
+ ## 常用命令
71
+
72
+ - 同步环境: `uv sync`
73
+ - 添加依赖: `uv add <package>`
74
+ - 执行脚本: `uv run python <script>` — **禁止**直接使用 `python3` / `python` 调用 Python
75
+ - 测试: `uv run pytest`
76
+ - Lint: `uv run ruff check --fix src/`
77
+ - 格式化: `uv run black src/ scripts/`
78
+ - 类型检查: `uv run mypy src/`
79
+
80
+ ## 代码生成
81
+
82
+ 模型基于 OpenAPI 规范自动生成:
83
+
84
+ ```bash
85
+ uv run python scripts/generate_models.py --product sp --output-dir src/async_amazon_ads_api_v1/models/sp/
86
+ uv run python scripts/generate_models.py --product sb --output-dir src/async_amazon_ads_api_v1/models/sb/
87
+ uv run python scripts/generate_models.py --product sd --output-dir src/async_amazon_ads_api_v1/models/sd/
88
+ uv run ruff check --fix src/
89
+ uv run black src/
90
+ ```
91
+
92
+ - `generate_file_structure.py` 提供通用的图分类算法,不依赖硬编码
93
+ - 每次修改上游 JSON Schema 后,重新运行生成脚本
94
+ - 枚举使用 `StrEnum`,可选字段使用 Python 3.14 `X | None` 语法
95
+
96
+ ## 环境变量
97
+
98
+ ```bash
99
+ AMAZON_ACCESS_TOKEN # OAuth bearer token(必填,或使用 refresh_token 自动获取)
100
+ AMAZON_CLIENT_ID # OAuth client ID(使用 refresh_token 时必填)
101
+ AMAZON_REFRESH_TOKEN # OAuth refresh token(可选,用于自动续期)
102
+ AMAZON_CLIENT_SECRET # OAuth client secret(使用 refresh_token 时必填)
103
+ AMAZON_REGION # na | eu | fe(默认 na)
104
+ AMAZON_PROFILE_ID # 可选,数字类型
105
+ AMAZON_TOKEN_URL # 可选,自定义 token 端点
106
+ AMAZON_TOKEN_CACHE_DIR # 可选,token 缓存目录
107
+ AMAZON_CACHE_BACKEND # 可选,file | redis
108
+ AMAZON_REDIS_URL # 可选,Redis 连接 URL(使用 redis 缓存时需要)
109
+ AMAZON_ENDPOINT_NA # 可选,覆盖 NA 端点
110
+ AMAZON_ENDPOINT_EU # 可选,覆盖 EU 端点
111
+ AMAZON_ENDPOINT_FE # 可选,覆盖 FE 端点
112
+ ```
113
+
114
+ ## 使用示例
115
+
116
+ ```python
117
+ from async_amazon_ads_api_v1 import AmazonAdsConfig, Region, SPClient, SBClient, SDClient
118
+
119
+ config = AmazonAdsConfig(access_token="...", region=Region.NA)
120
+
121
+ async with SPClient(config) as sp:
122
+ resp = await sp.campaigns.query({"stateFilter": {"include": ["enabled"]}})
123
+ print(resp.model_dump_json(indent=2))
124
+
125
+ async with SBClient(config) as sb:
126
+ resp = await sb.campaigns.query({...})
127
+ resp = await sb.advertising_deals.query({...})
128
+
129
+ async with SDClient(config) as sd:
130
+ resp = await sd.campaigns.query({...})
131
+ ```
132
+
133
+ ## 公开导出
134
+
135
+ `__init__.py` 导出以下 API:
136
+
137
+ ```python
138
+ from async_amazon_ads_api_v1 import (
139
+ AmazonAdsConfig, # 核心配置
140
+ Region, # 区域枚举 (NA/EU/FE)
141
+ CacheBackend, # 缓存后端枚举 (FILE/REDIS)
142
+ SPClient, # Sponsored Products 客户端
143
+ SBClient, # Sponsored Brands 客户端
144
+ SDClient, # Sponsored Display 客户端
145
+ TokenManager, # OAuth token 生命周期管理
146
+ TokenCredentials, # token 刷新凭据
147
+ BaseTokenCache, # 缓存抽象基类
148
+ FileTokenCache, # 文件缓存实现
149
+ RedisTokenCache, # Redis 缓存实现
150
+ close_all_redis, # 关闭所有 Redis 连接
151
+ )
152
+ ```
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Amazon Ads
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,197 @@
1
+ Metadata-Version: 2.4
2
+ Name: async-amazon-ads-api-v1
3
+ Version: 0.3.0
4
+ Summary: Pure async Amazon Ads API v1 client — Sponsored Products, Sponsored Brands, Sponsored Display
5
+ Author: Amazon Ads
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Keywords: ads,advertising,amazon,api-v1,async,sponsored-brands,sponsored-display,sponsored-products
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Framework :: AsyncIO
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Typing :: Typed
18
+ Requires-Python: >=3.13
19
+ Requires-Dist: httpx>=0.28.0
20
+ Requires-Dist: pydantic>=2.10.0
21
+ Provides-Extra: redis
22
+ Requires-Dist: redis>=5.0.0; extra == 'redis'
23
+ Description-Content-Type: text/markdown
24
+
25
+ # async-amazon-ads-api-v1
26
+
27
+ [![PyPI version](https://img.shields.io/pypi/v/async-amazon-ads-api-v1)](https://pypi.org/project/async-amazon-ads-api-v1/)
28
+ [![Python versions](https://img.shields.io/pypi/pyversions/async-amazon-ads-api-v1)](https://pypi.org/project/async-amazon-ads-api-v1/)
29
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
30
+
31
+ Pure async Amazon Ads API v1 client — Sponsored Products, Sponsored Brands, Sponsored Display.
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ pip install async-amazon-ads-api-v1
37
+ # 或
38
+ uv add async-amazon-ads-api-v1
39
+ ```
40
+
41
+ Redis 缓存支持:
42
+
43
+ ```bash
44
+ pip install "async-amazon-ads-api-v1[redis]"
45
+ # 或
46
+ uv add "async-amazon-ads-api-v1[redis]"
47
+ ```
48
+
49
+ ## Quick Start
50
+
51
+ ### 使用 Access Token(直接提供)
52
+
53
+ ```python
54
+ import asyncio
55
+ from async_amazon_ads_api_v1 import AmazonAdsConfig, Region, SPClient
56
+
57
+ async def main():
58
+ config = AmazonAdsConfig(
59
+ access_token="your-access-token",
60
+ client_id="your-client-id",
61
+ region=Region.NA,
62
+ )
63
+
64
+ async with SPClient(config) as sp:
65
+ resp = await sp.campaigns.query({"stateFilter": {"include": ["enabled"]}})
66
+ print(resp.model_dump_json(indent=2))
67
+
68
+ asyncio.run(main())
69
+ ```
70
+
71
+ ### 使用 Refresh Token(自动续期)
72
+
73
+ ```python
74
+ import asyncio
75
+ from async_amazon_ads_api_v1 import AmazonAdsConfig, Region, SPClient
76
+
77
+ async def main():
78
+ config = AmazonAdsConfig(
79
+ access_token="your-access-token", # 可选,提供后直接使用
80
+ client_id="your-client-id",
81
+ refresh_token="your-refresh-token", # access_token 过期后自动刷新
82
+ client_secret="your-client-secret",
83
+ region=Region.NA,
84
+ )
85
+
86
+ async with SPClient(config) as sp:
87
+ resp = await sp.campaigns.query({"stateFilter": {"include": ["enabled"]}})
88
+ print(resp.model_dump_json(indent=2))
89
+
90
+ asyncio.run(main())
91
+ ```
92
+
93
+ ### 从环境变量加载
94
+
95
+ ```bash
96
+ export AMAZON_ACCESS_TOKEN=...
97
+ export AMAZON_CLIENT_ID=...
98
+ export AMAZON_REFRESH_TOKEN=... # 可选,用于自动续期
99
+ export AMAZON_CLIENT_SECRET=... # 可选,refresh_token 时需要
100
+ export AMAZON_REGION=na # na | eu | fe,默认 na
101
+ export AMAZON_PROFILE_ID=... # 可选
102
+ ```
103
+
104
+ ```python
105
+ from async_amazon_ads_api_v1.config.loader import from_toml
106
+
107
+ config = from_toml()
108
+ ```
109
+
110
+ ## Environment Variables
111
+
112
+ | 变量 | 必填 | 说明 |
113
+ |---|---|---|
114
+ | `AMAZON_ACCESS_TOKEN` | 条件 | OAuth bearer token(或使用 refresh_token 自动获取) |
115
+ | `AMAZON_CLIENT_ID` | 条件 | OAuth client ID(使用 refresh_token 时必填) |
116
+ | `AMAZON_REFRESH_TOKEN` | 否 | OAuth refresh token,用于自动续期 |
117
+ | `AMAZON_CLIENT_SECRET` | 条件 | OAuth client secret(使用 refresh_token 时必填) |
118
+ | `AMAZON_REGION` | 否 | `na` \| `eu` \| `fe`,默认 `na` |
119
+ | `AMAZON_PROFILE_ID` | 否 | 广告主 profile ID |
120
+ | `AMAZON_TOKEN_URL` | 否 | 自定义 token 端点 |
121
+ | `AMAZON_TOKEN_CACHE_DIR` | 否 | 文件缓存目录(默认系统临时目录) |
122
+ | `AMAZON_CACHE_BACKEND` | 否 | `file` \| `redis`,默认 `file` |
123
+ | `AMAZON_REDIS_URL` | 否 | Redis 连接 URL(使用 redis 缓存时需要) |
124
+ | `AMAZON_ENDPOINT_NA` | 否 | 覆盖 NA 端点 |
125
+ | `AMAZON_ENDPOINT_EU` | 否 | 覆盖 EU 端点 |
126
+ | `AMAZON_ENDPOINT_FE` | 否 | 覆盖 FE 端点 |
127
+
128
+ ## Token Management
129
+
130
+ SDK 内置 OAuth token 生命周期管理,支持自动续期和缓存:
131
+
132
+ ```python
133
+ from async_amazon_ads_api_v1 import (
134
+ AmazonAdsConfig, Region,
135
+ TokenManager, TokenCredentials,
136
+ FileTokenCache, RedisTokenCache,
137
+ )
138
+
139
+ # 自动续期 + 文件缓存(默认)
140
+ config = AmazonAdsConfig(
141
+ client_id="your-client-id",
142
+ client_secret="your-client-secret",
143
+ refresh_token="your-refresh-token",
144
+ region=Region.NA,
145
+ )
146
+
147
+ # 自动续期 + Redis 缓存
148
+ config = AmazonAdsConfig(
149
+ client_id="your-client-id",
150
+ client_secret="your-client-secret",
151
+ refresh_token="your-refresh-token",
152
+ region=Region.NA,
153
+ cache_backend="redis",
154
+ redis_url="redis://localhost:6379",
155
+ )
156
+ ```
157
+
158
+ ## API Reference
159
+
160
+ ### `SPClient` — Sponsored Products
161
+
162
+ | 资源 | 方法 |
163
+ |---|---|
164
+ | `client.campaigns` | `create()`, `query()`, `update()`, `delete()` |
165
+ | `client.ad_groups` | `create()`, `query()`, `update()`, `delete()` |
166
+ | `client.ads` | `create()`, `query()`, `update()`, `delete()` |
167
+ | `client.targets` | `create()`, `query()`, `update()`, `delete()` |
168
+ | `client.ad_extensions` | `create()`, `query()`, `update()` |
169
+
170
+ ### `SBClient` — Sponsored Brands
171
+
172
+ | 资源 | 方法 |
173
+ |---|---|
174
+ | `client.campaigns` | `create()`, `query()`, `update()`, `delete()` |
175
+ | `client.ad_groups` | `create()`, `query()`, `update()`, `delete()` |
176
+ | `client.ads` | `create()`, `query()`, `update()`, `delete()` |
177
+ | `client.targets` | `create()`, `query()`, `update()`, `delete()` |
178
+ | `client.ad_extensions` | `create()`, `query()`, `update()` |
179
+ | `client.advertising_deals` | `create()`, `query()`, `update()`, `delete()` |
180
+ | `client.advertising_deal_targets` | `create()`, `query()`, `delete()` |
181
+ | `client.branded_keywords_pricings` | `create()` |
182
+ | `client.keyword_reservation_validations` | `create()` |
183
+ | `client.recommendations` | `create()` |
184
+ | `client.recommendation_types` | `query()` |
185
+
186
+ ### `SDClient` — Sponsored Display
187
+
188
+ | 资源 | 方法 |
189
+ |---|---|
190
+ | `client.campaigns` | `create()`, `query()`, `update()`, `delete()` |
191
+ | `client.ad_groups` | `create()`, `query()`, `update()`, `delete()` |
192
+ | `client.ads` | `create()`, `query()`, `update()`, `delete()` |
193
+ | `client.targets` | `create()`, `query()`, `update()`, `delete()` |
194
+
195
+ ## License
196
+
197
+ [MIT](LICENSE)
@@ -0,0 +1,173 @@
1
+ # async-amazon-ads-api-v1
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/async-amazon-ads-api-v1)](https://pypi.org/project/async-amazon-ads-api-v1/)
4
+ [![Python versions](https://img.shields.io/pypi/pyversions/async-amazon-ads-api-v1)](https://pypi.org/project/async-amazon-ads-api-v1/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+
7
+ Pure async Amazon Ads API v1 client — Sponsored Products, Sponsored Brands, Sponsored Display.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pip install async-amazon-ads-api-v1
13
+ # 或
14
+ uv add async-amazon-ads-api-v1
15
+ ```
16
+
17
+ Redis 缓存支持:
18
+
19
+ ```bash
20
+ pip install "async-amazon-ads-api-v1[redis]"
21
+ # 或
22
+ uv add "async-amazon-ads-api-v1[redis]"
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ### 使用 Access Token(直接提供)
28
+
29
+ ```python
30
+ import asyncio
31
+ from async_amazon_ads_api_v1 import AmazonAdsConfig, Region, SPClient
32
+
33
+ async def main():
34
+ config = AmazonAdsConfig(
35
+ access_token="your-access-token",
36
+ client_id="your-client-id",
37
+ region=Region.NA,
38
+ )
39
+
40
+ async with SPClient(config) as sp:
41
+ resp = await sp.campaigns.query({"stateFilter": {"include": ["enabled"]}})
42
+ print(resp.model_dump_json(indent=2))
43
+
44
+ asyncio.run(main())
45
+ ```
46
+
47
+ ### 使用 Refresh Token(自动续期)
48
+
49
+ ```python
50
+ import asyncio
51
+ from async_amazon_ads_api_v1 import AmazonAdsConfig, Region, SPClient
52
+
53
+ async def main():
54
+ config = AmazonAdsConfig(
55
+ access_token="your-access-token", # 可选,提供后直接使用
56
+ client_id="your-client-id",
57
+ refresh_token="your-refresh-token", # access_token 过期后自动刷新
58
+ client_secret="your-client-secret",
59
+ region=Region.NA,
60
+ )
61
+
62
+ async with SPClient(config) as sp:
63
+ resp = await sp.campaigns.query({"stateFilter": {"include": ["enabled"]}})
64
+ print(resp.model_dump_json(indent=2))
65
+
66
+ asyncio.run(main())
67
+ ```
68
+
69
+ ### 从环境变量加载
70
+
71
+ ```bash
72
+ export AMAZON_ACCESS_TOKEN=...
73
+ export AMAZON_CLIENT_ID=...
74
+ export AMAZON_REFRESH_TOKEN=... # 可选,用于自动续期
75
+ export AMAZON_CLIENT_SECRET=... # 可选,refresh_token 时需要
76
+ export AMAZON_REGION=na # na | eu | fe,默认 na
77
+ export AMAZON_PROFILE_ID=... # 可选
78
+ ```
79
+
80
+ ```python
81
+ from async_amazon_ads_api_v1.config.loader import from_toml
82
+
83
+ config = from_toml()
84
+ ```
85
+
86
+ ## Environment Variables
87
+
88
+ | 变量 | 必填 | 说明 |
89
+ |---|---|---|
90
+ | `AMAZON_ACCESS_TOKEN` | 条件 | OAuth bearer token(或使用 refresh_token 自动获取) |
91
+ | `AMAZON_CLIENT_ID` | 条件 | OAuth client ID(使用 refresh_token 时必填) |
92
+ | `AMAZON_REFRESH_TOKEN` | 否 | OAuth refresh token,用于自动续期 |
93
+ | `AMAZON_CLIENT_SECRET` | 条件 | OAuth client secret(使用 refresh_token 时必填) |
94
+ | `AMAZON_REGION` | 否 | `na` \| `eu` \| `fe`,默认 `na` |
95
+ | `AMAZON_PROFILE_ID` | 否 | 广告主 profile ID |
96
+ | `AMAZON_TOKEN_URL` | 否 | 自定义 token 端点 |
97
+ | `AMAZON_TOKEN_CACHE_DIR` | 否 | 文件缓存目录(默认系统临时目录) |
98
+ | `AMAZON_CACHE_BACKEND` | 否 | `file` \| `redis`,默认 `file` |
99
+ | `AMAZON_REDIS_URL` | 否 | Redis 连接 URL(使用 redis 缓存时需要) |
100
+ | `AMAZON_ENDPOINT_NA` | 否 | 覆盖 NA 端点 |
101
+ | `AMAZON_ENDPOINT_EU` | 否 | 覆盖 EU 端点 |
102
+ | `AMAZON_ENDPOINT_FE` | 否 | 覆盖 FE 端点 |
103
+
104
+ ## Token Management
105
+
106
+ SDK 内置 OAuth token 生命周期管理,支持自动续期和缓存:
107
+
108
+ ```python
109
+ from async_amazon_ads_api_v1 import (
110
+ AmazonAdsConfig, Region,
111
+ TokenManager, TokenCredentials,
112
+ FileTokenCache, RedisTokenCache,
113
+ )
114
+
115
+ # 自动续期 + 文件缓存(默认)
116
+ config = AmazonAdsConfig(
117
+ client_id="your-client-id",
118
+ client_secret="your-client-secret",
119
+ refresh_token="your-refresh-token",
120
+ region=Region.NA,
121
+ )
122
+
123
+ # 自动续期 + Redis 缓存
124
+ config = AmazonAdsConfig(
125
+ client_id="your-client-id",
126
+ client_secret="your-client-secret",
127
+ refresh_token="your-refresh-token",
128
+ region=Region.NA,
129
+ cache_backend="redis",
130
+ redis_url="redis://localhost:6379",
131
+ )
132
+ ```
133
+
134
+ ## API Reference
135
+
136
+ ### `SPClient` — Sponsored Products
137
+
138
+ | 资源 | 方法 |
139
+ |---|---|
140
+ | `client.campaigns` | `create()`, `query()`, `update()`, `delete()` |
141
+ | `client.ad_groups` | `create()`, `query()`, `update()`, `delete()` |
142
+ | `client.ads` | `create()`, `query()`, `update()`, `delete()` |
143
+ | `client.targets` | `create()`, `query()`, `update()`, `delete()` |
144
+ | `client.ad_extensions` | `create()`, `query()`, `update()` |
145
+
146
+ ### `SBClient` — Sponsored Brands
147
+
148
+ | 资源 | 方法 |
149
+ |---|---|
150
+ | `client.campaigns` | `create()`, `query()`, `update()`, `delete()` |
151
+ | `client.ad_groups` | `create()`, `query()`, `update()`, `delete()` |
152
+ | `client.ads` | `create()`, `query()`, `update()`, `delete()` |
153
+ | `client.targets` | `create()`, `query()`, `update()`, `delete()` |
154
+ | `client.ad_extensions` | `create()`, `query()`, `update()` |
155
+ | `client.advertising_deals` | `create()`, `query()`, `update()`, `delete()` |
156
+ | `client.advertising_deal_targets` | `create()`, `query()`, `delete()` |
157
+ | `client.branded_keywords_pricings` | `create()` |
158
+ | `client.keyword_reservation_validations` | `create()` |
159
+ | `client.recommendations` | `create()` |
160
+ | `client.recommendation_types` | `query()` |
161
+
162
+ ### `SDClient` — Sponsored Display
163
+
164
+ | 资源 | 方法 |
165
+ |---|---|
166
+ | `client.campaigns` | `create()`, `query()`, `update()`, `delete()` |
167
+ | `client.ad_groups` | `create()`, `query()`, `update()`, `delete()` |
168
+ | `client.ads` | `create()`, `query()`, `update()`, `delete()` |
169
+ | `client.targets` | `create()`, `query()`, `update()`, `delete()` |
170
+
171
+ ## License
172
+
173
+ [MIT](LICENSE)