ไผไธ็บง Amazon Ads API Python SDK - ๅ็บงๆฒป็็ API ่ฆ็
ๆฌ SDK ้็จไธ็้ฆๅ็ API ๅ็บงๆฒป็ไฝ็ณป๏ผ่งฃๅณ Amazon Ads API ็ข็ๅ้ฎ้ข๏ผ
| ็ญ็บง | ็ฎๅฝ | ๅฏไฟกๅบฆ | ๆฐ้ | ่ฏดๆ |
|---|---|---|---|---|
| L1 Gold ๐ฅ | core/ |
โญโญโญโญโญ | ~270 | OpenAPI ้ช่ฏ๏ผ็ไบงๅฏ็จ |
| L2 Silver ๐ฅ | reference/ |
โญโญโญโญ | ~30 | ๅฎๆนๆๆกฃ็กฎ่ฎค๏ผ้ๆพๅผ่ฎฟ้ฎ |
| L3 Bronze ๐ฅ | services/ |
โญโญโญ | ~15 | ไบงๅ็บง่ๅ๏ผไพฟๅฉๅฐ่ฃ |
| L4 Red ๐ด | experimental/ |
โญโญ | ~20 | Beta/ๅฎ้ชๆง๏ผ้็กฎ่ฎค้ฃ้ฉ |
# L1: ้ป่ฎค่ฎฟ้ฎ๏ผๆๅฎๅ
จ๏ผ
campaigns = client.sp.campaigns.list()
# L2: ๆพๅผๅฝๅ็ฉบ้ด๏ผๅฎๆนไฝ้ OpenAPI๏ผ
result = client.reference.amc.run_query(...)
# L3: ๆๅกๅฑ
report = client.services.reporting.create_report(...)
# L4: ้็กฎ่ฎค้ฃ้ฉ
exp = client.experimental(acknowledge_risk=True)
exp.sponsored_tv.create_campaign(...)
- ๐ API ๅ็บงๆฒป็ - L1~L4 ๅฏไฟกๅบฆๅ็บง๏ผๅๅซ่ๅ API
- ๐ฏ 335+ API ่ฆ็ - ่ฆ็ๅ จ้จ Amazon Ads API ไบงๅ็บฟ
- ๐ OpenAPI ้ช่ฏ - L1 API 100% OpenAPI ่ง่้ช่ฏ
- ๐ ็ฎๆดๆ็จ - ็ปไธๅฎขๆท็ซฏๅ ฅๅฃ๏ผ้พๅผ่ฐ็จ
- ๐ ่ชๅจ่ฎค่ฏ - OAuth2 Token ่ชๅจๅทๆฐ
- โก ่ชๅจ้่ฏ - ๅ ็ฝฎๆๆฐ้้ฟ้่ฏๆบๅถ
- ๐ก๏ธ Rate Limit - ่ชๅจๅค็้ๆต
- ๐ ็ฑปๅๅฎๅ จ - ๅฎๆด็็ฑปๅๆ็คบ
- ๐งช ๅฎๆดๆต่ฏ - ๅๅ ๆต่ฏ + ้ๆๆต่ฏ
| ๆจกๅ | ๆ่ฟฐ | ็ซฏ็นๆฐ | OpenAPI |
|---|---|---|---|
| sp/ | Sponsored Products | ~80 | โ v3 |
| sb/ | Sponsored Brands | ~50 | โ v4 |
| sd/ | Sponsored Display | ~40 | โ v3 |
| dsp/ | Amazon DSP | ~60 | โ v3 |
| accounts/ | Profiles, Portfolios, Billing | ~15 | โ |
| audiences/ | Audiences Discovery | ~5 | โ |
| eligibility/ | Eligibility | ~3 | โ |
| exports/ | Exports | ~5 | โ |
| products/ | Product Selector, Metadata | ~10 | โ |
| ๆจกๅ | ๆ่ฟฐ | ็ซฏ็นๆฐ | ๆๆกฃ |
|---|---|---|---|
| amc/ | Amazon Marketing Cloud | ~20 | API Reference |
| stream/ | Amazon Marketing Stream | ~5 | API Reference |
| retail_ad/ | Retail Ad Service | ~15 | API Reference |
| attribution/ | Amazon Attribution | ~5 | API Reference |
| posts/ | Posts | ~5 | API Reference |
| ๆจกๅ | ๆ่ฟฐ | ่ฏดๆ |
|---|---|---|
| reporting/ | Reports v3, Brand Metrics | ไพฟๅฉๅฐ่ฃ |
| insights/ | Audience/Keyword Insights | ้ซๅฑๆฝ่ฑก |
| recommendations/ | Recommendations | ่ๅๆๅก |
| ๆจกๅ | ๆ่ฟฐ | ็ถๆ |
|---|---|---|
| sponsored_tv/ | Sponsored TV | Beta |
| moderation/ | Creative Moderation | UI-bound |
| localization/ | Localization | ไธ็จณๅฎ |
# ไป PyPI ๅฎ่ฃ
pip install amazon-ads-api
# ๆไป GitHub ๅฎ่ฃ
ๆๆฐ็
pip install git+https://github.com/vanling1111/amazon-ads-api-python-sdk.git
from amazon_ads_api import AmazonAdsClient, AdsRegion
# ๅๅปบๅฎขๆท็ซฏ
client = AmazonAdsClient(
client_id="your_client_id",
client_secret="your_client_secret",
refresh_token="your_refresh_token",
profile_id="your_profile_id", # ๅฟ
้
region=AdsRegion.NA, # NA, EU, FE
)
# ่ทๅ SP Campaigns
campaigns = await client.sp.campaigns.list_campaigns()
print(campaigns)
# ่ทๅๅ
ณ้ฎ่ฏ
keywords = await client.sp.keywords.list_keywords(campaign_id="123456")
# ๆดๆฐ็ซไปท
await client.sp.keywords.update_bid(keyword_id="789", new_bid=1.50)
This SDK is multi-account capable and designed for concurrent use:
โ What the SDK provides:
- Multiple Amazon Ads accounts/profiles can run concurrently
- Each
AmazonAdsClientinstance is completely isolated - Safe for async concurrent operations
- Handles authentication, rate limiting, and retries per-client
โ What the SDK does NOT manage:
- SaaS tenant or user management
- Persistent OAuth token storage
- Account authorization flows
- User-to-profile permission mapping
These are responsibilities of your application's Service layer.
import asyncio
from amazon_ads_api import AmazonAdsClient, AdsRegion
# Create independent clients for different profiles
client1 = AmazonAdsClient(
client_id='...',
client_secret='...',
refresh_token='token_for_profile_1',
profile_id='profile-123',
region=AdsRegion.NA
)
client2 = AmazonAdsClient(
client_id='...',
client_secret='...',
refresh_token='token_for_profile_2',
profile_id='profile-456',
region=AdsRegion.NA
)
# Concurrent operations are safe!
campaigns1, campaigns2 = await asyncio.gather(
client1.sp.campaigns.list_campaigns(),
client2.sp.campaigns.list_campaigns()
)
If you're building a multi-tenant SaaS platform:
- Your database stores user-to-profile mappings
- Your Service layer validates user permissions
- Your Service layer creates one
AmazonAdsClientper profile - Your API layer enforces tenant boundaries
See examples/saas_integration.py for a complete example.
# ========== L1 Core APIs (็ดๆฅ่ฎฟ้ฎ) ==========
# Sponsored Products
campaigns = client.sp.campaigns.list_campaigns()
keywords = client.sp.keywords.list_keywords(campaign_id="123")
# Sponsored Brands
sb_campaigns = client.sb.campaigns.list_campaigns()
# Sponsored Display
sd_campaigns = client.sd.campaigns.list_campaigns()
# DSP
dsp_campaigns = client.dsp.campaigns.list_campaigns(advertiser_id="xxx")
dsp_audiences = client.dsp.audiences.list_audiences()
# Accounts
profiles = client.accounts.profiles.list_profiles()
portfolios = client.accounts.portfolios.list_portfolios()
# ========== L2 Reference APIs (ๆพๅผๅฝๅ็ฉบ้ด) ==========
# Amazon Marketing Cloud
query_result = client.reference.amc.queries.execute_query(
query="SELECT * FROM your_table WHERE date > '2024-01-01'"
)
# Marketing Stream
subscriptions = client.reference.stream.subscriptions.list()
# Retail Ad Service
ras_campaigns = client.reference.retail_ad_service.campaigns.list()
# ========== L3 Services (ไบงๅ็บง่ๅ) ==========
# Reports
report = client.services.reporting.reports.create_report(
report_type="spCampaigns",
time_unit="DAILY",
start_date="2024-01-01",
end_date="2024-01-31",
)
# Insights
keyword_insights = client.services.insights.keywords.get_ranking_keywords()
# Common utilities
assets = client.services.common.assets.upload_asset(...)
# ========== L4 Experimental (้็กฎ่ฎค้ฃ้ฉ) ==========
# Sponsored TV (Beta)
tv_campaigns = client.experimental.sponsored_tv.campaigns.list_campaigns()
# Pre-moderation
moderation = client.experimental.moderation.pre_moderation.submit()
client
โโโ sp # L1 - Sponsored Products
โโโ sb # L1 - Sponsored Brands
โโโ sd # L1 - Sponsored Display
โโโ dsp # L1 - Amazon DSP
โโโ accounts # L1 - Profiles, Portfolios, Billing
โ
โโโ reference/ # L2 - API Reference ็กฎ่ฎค
โ โโโ amc # Amazon Marketing Cloud
โ โโโ stream # Marketing Stream
โ โโโ retail_ad_service # Retail Ad Service
โ โโโ data_provider # Data Provider
โ โโโ posts # Posts
โ โโโ unified_api # Unified API
โ
โโโ services/ # L3 - ไบงๅ็บง่ๅ
โ โโโ reporting # Reports V3, Brand Metrics, MMM
โ โโโ insights # Keyword/Audience Insights
โ โโโ recommendations # Recommendations
โ โโโ common # Assets, History, Stores
โ โโโ brand_associations
โ โโโ ads_data_manager
โ โโโ media_planning
โ
โโโ experimental/ # L4 - Beta/ๅฎ้ชๆง
โโโ sponsored_tv # Sponsored TV (Beta)
โโโ moderation # Pre/Unified Moderation
โโโ localization # Localization
โโโ ad_library # Ad Library
โโโ brand_home # Brand Home
core/
โโโ sp/ # Sponsored Products (~80 endpoints)
โ โโโ campaigns
โ โโโ ad_groups
โ โโโ keywords
โ โโโ targeting
โ โโโ budget_rules
โ โโโ recommendations
โ โโโ product_eligibility
โ โโโ theme_targeting
โ โโโ target_promotion_groups
โ โโโ global_recommendations
โโโ sb/ # Sponsored Brands (~50 endpoints)
โ โโโ campaigns
โ โโโ ads
โ โโโ keywords
โ โโโ creatives
โ โโโ brand_video
โ โโโ moderation
โ โโโ optimization
โ โโโ forecasts
โ โโโ targeting
โ โโโ legacy_migration
โโโ sd/ # Sponsored Display (~40 endpoints)
โ โโโ campaigns
โ โโโ targeting
โ โโโ creatives
โ โโโ audiences
โ โโโ moderation
โ โโโ optimization
โ โโโ brand_safety
โ โโโ locations
โ โโโ reports
โโโ dsp/ # Amazon DSP (~60 endpoints)
โ โโโ campaigns
โ โโโ advertisers
โ โโโ audiences
โ โโโ conversions
โ โโโ measurement
โ โโโ target_kpi
โโโ accounts/ # Accounts (~15 endpoints)
โ โโโ profiles
โ โโโ portfolios
โ โโโ billing
โ โโโ budgets
โ โโโ test_accounts
โโโ audiences/ # Audiences Discovery
โโโ eligibility/ # Eligibility
โโโ exports/ # Exports
โโโ products/ # Product Selector
โโโ locations/ # Locations
client = AmazonAdsClient(
client_id="xxx",
client_secret="xxx",
refresh_token="xxx",
region=AdsRegion.NA, # API ๅบๅ
profile_id="123456", # ๅฏ้๏ผไนๅฏไปฅๅ็ปญ่ฎพ็ฝฎ
max_retries=3, # ๆๅคง้่ฏๆฌกๆฐ
timeout=30, # ่ฏทๆฑ่ถ
ๆถ๏ผ็ง๏ผ
)
- ๆณจๅ Amazon Ads Partner Network
- ๅๅปบ Login with Amazon (LwA) ๅบ็จ
- ็ณ่ฏท Amazon Ads API ๆ้
- ่ทๅ Client ID, Client Secret
- ้่ฟ OAuth2 ๆต็จ่ทๅ Refresh Token
| ๅบๅ | ็ซฏ็น |
|---|---|
| NA (ๅ็พ) | https://advertising-api.amazon.com |
| EU (ๆฌงๆดฒ) | https://advertising-api-eu.amazon.com |
| FE (่ฟไธ) | https://advertising-api-fe.amazon.com |
# ๅฎ่ฃ
ๅผๅไพ่ต
pip install -e ".[dev]"
# ่ฟ่กๆๆๆต่ฏ
pytest
# ๅช่ฟ่กๅๅ
ๆต่ฏ
pytest tests/unit/
# ๅช่ฟ่ก้ๆๆต่ฏ
pytest tests/integration/
# ่ฆ็็ๆฅๅ
pytest --cov=amazon_ads_api --cov-report=html
# ่ฟ่กๅฏผๅ
ฅๆต่ฏ
python tests/test_imports.py
tests/
โโโ conftest.py # ๆต่ฏ้
็ฝฎๅfixtures
โโโ test_imports.py # ๅฏผๅ
ฅๆต่ฏ (101ไธช็ฑป)
โโโ unit/ # ๅๅ
ๆต่ฏ
โ โโโ test_base.py # BaseAdsClient ๆต่ฏ
โ โโโ test_client.py # AmazonAdsClient ๆต่ฏ
โ โโโ test_sp.py # SP ๆจกๅๆต่ฏ
โ โโโ test_sb.py # SB ๆจกๅๆต่ฏ
โ โโโ ...
โโโ integration/ # ้ๆๆต่ฏ
โโโ test_auth.py # ่ฎค่ฏๆต็จๆต่ฏ
โโโ test_sp_api.py # SP API ้ๆๆต่ฏ
โโโ ...
MIT License
ๆฌข่ฟๆไบค Issue ๅ Pull Request๏ผ
- Fork ๆฌไปๅบ
- ๅๅปบ็นๆงๅๆฏ (
git checkout -b feature/amazing-feature) - ๆไบคๆดๆน (
git commit -m 'Add some amazing feature') - ๆจ้ๅฐๅๆฏ (
git push origin feature/amazing-feature) - ๆไบค Pull Request
- ๐ง Email: [email protected]
- ๐ ๆๆกฃ: GitHub Wiki
- ๐ ้ฎ้ข: GitHub Issues
- API ็ฑปๆฐ้: 101
- ๆจกๅๆฐ้: 30
- ๆต่ฏ่ฆ็็: ็ฎๆ >80%
- Python ็ๆฌ: 3.13+
Made with โค๏ธ by vanling1111