async-amazon-ads-api-v1
Pure async Amazon Ads API client — ads_api 统一覆盖 v0 与 v1(SP、SB、SD、DSP、ST、SP Global、Accounts、Reporting、Ads Data Manager、Exports 等)。
Installation
pip install async-amazon-ads-api-v1
# 或
uv add async-amazon-ads-api-v1
Redis 缓存支持:
pip install "async-amazon-ads-api-v1[redis]"
# 或
uv add "async-amazon-ads-api-v1[redis]"
Quick Start
所有 API 方法仅接受 Pydantic model 实例,不支持 dict。默认 mode="dict",需要模型对象时传 mode="pydantic"。
使用 Access Token
import asyncio
from ads_api import AdsClient, AmazonAdsConfig, Region
from ads_api.models.v1.campaigns.sp import SPQueryCampaignRequest
async def main() -> None:
config = AmazonAdsConfig(
access_token="your-access-token",
client_id="your-client-id",
region=Region.NA,
)
body = SPQueryCampaignRequest(
adProductFilter={"include": ["SPONSORED_PRODUCTS"]},
stateFilter={"include": ["ENABLED"]},
)
async with AdsClient(config) as ads:
resp = await ads.v1.sp.campaigns.query_campaign(body)
print(resp)
asyncio.run(main())
使用 Refresh Token(自动续期)
import asyncio
from ads_api import AdsClient, AmazonAdsConfig, Region
from ads_api.models.v1.campaigns.sp import SPQueryCampaignRequest
async def main() -> None:
config = AmazonAdsConfig(
client_id="your-client-id",
refresh_token="your-refresh-token",
client_secret="your-client-secret",
region=Region.NA,
)
body = SPQueryCampaignRequest(
adProductFilter={"include": ["SPONSORED_PRODUCTS"]},
stateFilter={"include": ["ENABLED"]},
)
async with AdsClient(config) as ads:
resp = await ads.v1.sp.campaigns.query_campaign(body, mode="pydantic")
print(resp.model_dump_json(indent=2))
asyncio.run(main())
Token Management
SDK 内置 OAuth token 生命周期管理。提供 refresh_token 与 client_secret 后会自动续期;缓存按字段推断:
from ads_api import AmazonAdsConfig, Region
# 自动续期,不使用磁盘 / Redis 缓存
config = AmazonAdsConfig(
client_id="your-client-id",
client_secret="your-client-secret",
refresh_token="your-refresh-token",
region=Region.NA,
)
# 文件缓存
config = AmazonAdsConfig(
client_id="your-client-id",
client_secret="your-client-secret",
refresh_token="your-refresh-token",
region=Region.NA,
token_cache_dir="~/.cache/ads_api",
)
# Redis 缓存
config = AmazonAdsConfig(
client_id="your-client-id",
client_secret="your-client-secret",
refresh_token="your-refresh-token",
region=Region.NA,
redis_url="redis://localhost:6379",
)
API 入口
async with AdsClient(config) as ads:
# v1
await ads.v1.sp.campaigns.query_campaign(body)
await ads.v1.sb.campaigns.query_campaign(body)
await ads.v1.sd.campaigns.query_campaign(body)
await ads.v1.selling_accounts.query_selling_account(body)
# v0
await ads.v0.accounts.profiles.list_profiles()
await ads.v0.portfolios.list_portfolios()
await ads.v0.sp_v3.campaigns.create_sponsored_products_campaigns(body)
await ads.v0.sb_v4.budget_rules.create_budget_rules_for_sb_campaigns(body)
await ads.v0.sd.creatives.create_creatives(body)
详细代码生成与说明请参见 script4/README.md (v1) 与 script3/README.md (v0)。
License
Release files for async-amazon-ads-api-v1 0.10.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| async_amazon_ads_api_v1-0.10.0.tar.gz | 367.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| async_amazon_ads_api_v1-0.10.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 956.3 kB
Release files / async_amazon_ads_api_v1-0.10.0.tar.gz
| Download URL | async_amazon_ads_api_v1-0.10.0.tar.gz |
|---|---|
| Size | 367.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
09846e96f732b96c6d20a5c6d2fdf325c0d9d9a515405d8473fe91369aa43201
|
|
BLAKE2b-256 checksum How to use checksums |
e79e5c052395aa0de3cc39cecef7dae690b98f761b940cb3439ff94642e87625
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency logRelease files / async_amazon_ads_api_v1-0.10.0-py3-none-any.whl
| Download URL | async_amazon_ads_api_v1-0.10.0-py3-none-any.whl |
|---|---|
| Size | 588.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e36aa79b4de807524dbcaff64b5254bda7fc386c3d75073e39bb80e7dae67851
|
|
BLAKE2b-256 checksum How to use checksums |
625e85950822729f410518df3a6523dfdfe24c34c4a52487bfb2a6f7be6e0218
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.
Transparency log