Skip to content

Commit 06d30ef

Browse files
author
Administrator
committed
docs: add multi-account support documentation and SaaS integration example
1 parent 04c2653 commit 06d30ef

File tree

3 files changed

+538
-12
lines changed

3 files changed

+538
-12
lines changed

README.md

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,11 @@ exp.sponsored_tv.create_campaign(...)
9393
### 安装
9494

9595
```bash
96-
#GitHub 安装
97-
pip install git+https://github.com/vanling1111/amazon-ads-api-python-sdk.git
96+
#PyPI 安装
97+
pip install amazon-ads-api
9898

99-
# 或克隆后本地安装
100-
git clone https://github.com/vanling1111/amazon-ads-api-python-sdk.git
101-
cd amazon-ads-api-python-sdk
102-
pip install -e .
99+
# 或从 GitHub 安装最新版
100+
pip install git+https://github.com/vanling1111/amazon-ads-api-python-sdk.git
103101
```
104102

105103
### 基础使用
@@ -112,23 +110,79 @@ client = AmazonAdsClient(
112110
client_id="your_client_id",
113111
client_secret="your_client_secret",
114112
refresh_token="your_refresh_token",
113+
profile_id="your_profile_id", # 必需
115114
region=AdsRegion.NA, # NA, EU, FE
116115
)
117116

118-
# 设置 Profile ID
119-
client.with_profile("your_profile_id")
120-
121117
# 获取 SP Campaigns
122-
campaigns = client.sp.campaigns.list_campaigns()
118+
campaigns = await client.sp.campaigns.list_campaigns()
123119
print(campaigns)
124120

125121
# 获取关键词
126-
keywords = client.sp.keywords.list_keywords(campaign_id="123456")
122+
keywords = await client.sp.keywords.list_keywords(campaign_id="123456")
127123

128124
# 更新竞价
129-
client.sp.keywords.update_bid(keyword_id="789", new_bid=1.50)
125+
await client.sp.keywords.update_bid(keyword_id="789", new_bid=1.50)
130126
```
131127

128+
## 🏢 Multi-Account Support
129+
130+
This SDK is **multi-account capable** and designed for concurrent use:
131+
132+
**What the SDK provides:**
133+
- Multiple Amazon Ads accounts/profiles can run concurrently
134+
- Each `AmazonAdsClient` instance is completely isolated
135+
- Safe for async concurrent operations
136+
- Handles authentication, rate limiting, and retries per-client
137+
138+
**What the SDK does NOT manage:**
139+
- SaaS tenant or user management
140+
- Persistent OAuth token storage
141+
- Account authorization flows
142+
- User-to-profile permission mapping
143+
144+
**These are responsibilities of your application's Service layer.**
145+
146+
### Example: Multiple Profiles Concurrently
147+
148+
```python
149+
import asyncio
150+
from amazon_ads_api import AmazonAdsClient, AdsRegion
151+
152+
# Create independent clients for different profiles
153+
client1 = AmazonAdsClient(
154+
client_id='...',
155+
client_secret='...',
156+
refresh_token='token_for_profile_1',
157+
profile_id='profile-123',
158+
region=AdsRegion.NA
159+
)
160+
161+
client2 = AmazonAdsClient(
162+
client_id='...',
163+
client_secret='...',
164+
refresh_token='token_for_profile_2',
165+
profile_id='profile-456',
166+
region=AdsRegion.NA
167+
)
168+
169+
# Concurrent operations are safe!
170+
campaigns1, campaigns2 = await asyncio.gather(
171+
client1.sp.campaigns.list_campaigns(),
172+
client2.sp.campaigns.list_campaigns()
173+
)
174+
```
175+
176+
### For SaaS Applications
177+
178+
If you're building a multi-tenant SaaS platform:
179+
1. Your **database** stores user-to-profile mappings
180+
2. Your **Service layer** validates user permissions
181+
3. Your **Service layer** creates one `AmazonAdsClient` per profile
182+
4. Your **API layer** enforces tenant boundaries
183+
184+
**See [examples/saas_integration.py](examples/saas_integration.py) for a complete example.**
185+
132186
### 高级用法 - v2.0 分级访问
133187

134188
```python

examples/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Amazon Ads API SDK - Usage Examples
2+
3+
This directory contains practical examples for common use cases.
4+
5+
## 📁 Examples
6+
7+
### [`saas_integration.py`](saas_integration.py)
8+
9+
**Complete multi-tenant SaaS integration example**
10+
11+
Demonstrates:
12+
- ✅ Multi-tenant architecture (Tenant → Account → Profile hierarchy)
13+
- ✅ Permission validation (preventing cross-tenant access)
14+
- ✅ Service layer for client management
15+
- ✅ FastAPI API endpoints
16+
- ✅ Concurrent multi-profile operations
17+
- ✅ Database schema design
18+
19+
**Use this if you're building a SaaS platform** (like an Amazon Ads management tool).
20+
21+
---
22+
23+
## 🚀 Basic Usage
24+
25+
### Single Profile
26+
27+
```python
28+
from amazon_ads_api import AmazonAdsClient, AdsRegion
29+
30+
client = AmazonAdsClient(
31+
client_id='your_client_id',
32+
client_secret='your_client_secret',
33+
refresh_token='your_refresh_token',
34+
profile_id='your_profile_id',
35+
region=AdsRegion.NA
36+
)
37+
38+
# Get campaigns
39+
campaigns = await client.sp.campaigns.list_campaigns()
40+
print(campaigns)
41+
```
42+
43+
### Multiple Profiles (Concurrent)
44+
45+
```python
46+
import asyncio
47+
from amazon_ads_api import AmazonAdsClient, AdsRegion
48+
49+
# Create independent clients
50+
client1 = AmazonAdsClient(..., profile_id='profile-123')
51+
client2 = AmazonAdsClient(..., profile_id='profile-456')
52+
53+
# Concurrent operations
54+
campaigns1, campaigns2 = await asyncio.gather(
55+
client1.sp.campaigns.list_campaigns(),
56+
client2.sp.campaigns.list_campaigns()
57+
)
58+
```
59+
60+
---
61+
62+
## 📖 More Examples Coming Soon
63+
64+
- [ ] Async batch operations
65+
- [ ] Report generation and download
66+
- [ ] Campaign automation
67+
- [ ] Keyword optimization
68+
- [ ] Budget management
69+
- [ ] Django integration
70+
- [ ] Celery task integration
71+
72+
---
73+
74+
## 🤝 Contributing Examples
75+
76+
Have a useful example? Submit a PR!
77+
78+
1. Create a new `.py` file in `examples/`
79+
2. Include docstrings and comments
80+
3. Update this README
81+
4. Ensure it runs without errors
82+

0 commit comments

Comments
 (0)