Skip to main content

async-amazon-ads-api-v1

PyPI version Python versions License: MIT

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_tokenclient_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

MIT

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)

Source distribution for async-amazon-ads-api-v1 0.10.0
File Size Uploaded
async_amazon_ads_api_v1-0.10.0.tar.gz 367.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for async-amazon-ads-api-v1 0.10.0
File Interpreter ABI Platform
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 log

Release 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

Release history Release notifications | RSS feed

0.11.0

2 release files

This release

0.10.0 This release

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.7

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.12

2 release files

0.6.11

2 release files

0.6.10

2 release files

0.6.9

2 release files

0.6.8

2 release files

0.6.7

2 release files

0.6.6

2 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page