apple-search-ads-client 1.0.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.

Potentially problematic release.


This version of apple-search-ads-client might be problematic. Click here for more details.

@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Your Name
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,15 @@
1
+ include README.md
2
+ include LICENSE
3
+ include requirements.txt
4
+ include requirements-dev.txt
5
+ recursive-include src *.py
6
+ recursive-include tests *.py
7
+ include pyproject.toml
8
+ prune .github
9
+ prune docs
10
+ prune utils
11
+ exclude .env
12
+ exclude .env.example
13
+ exclude .gitignore
14
+ exclude CLAUDE.md
15
+ exclude TESTING.md
@@ -0,0 +1,367 @@
1
+ Metadata-Version: 2.4
2
+ Name: apple-search-ads-client
3
+ Version: 1.0.0
4
+ Summary: A Python client for Apple Search Ads API v5
5
+ Home-page: https://github.com/bickster/apple-search-ads-python
6
+ Author: Bickster LLC
7
+ Author-email: Bickster LLC <support@bickster.com>
8
+ License: MIT
9
+ Project-URL: Homepage, https://github.com/bickster/apple-search-ads-python
10
+ Project-URL: Documentation, https://apple-search-ads-python.readthedocs.io/
11
+ Project-URL: Repository, https://github.com/bickster/apple-search-ads-python
12
+ Project-URL: Issues, https://github.com/bickster/apple-search-ads-python/issues
13
+ Keywords: apple,search,ads,api,marketing,advertising,ios,app,store
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Operating System :: OS Independent
25
+ Classifier: Topic :: Internet :: WWW/HTTP
26
+ Classifier: Topic :: Software Development :: Libraries
27
+ Requires-Python: >=3.8
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Requires-Dist: PyJWT>=2.8.0
31
+ Requires-Dist: cryptography>=41.0.0
32
+ Requires-Dist: requests>=2.31.0
33
+ Requires-Dist: pandas>=2.0.0
34
+ Requires-Dist: ratelimit>=2.2.1
35
+ Requires-Dist: python-dateutil>=2.8.0
36
+ Provides-Extra: dev
37
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
38
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
39
+ Requires-Dist: pytest-mock>=3.10.0; extra == "dev"
40
+ Requires-Dist: black>=23.0.0; extra == "dev"
41
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
42
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
43
+ Requires-Dist: sphinx>=6.0.0; extra == "dev"
44
+ Requires-Dist: sphinx-rtd-theme>=1.0.0; extra == "dev"
45
+ Dynamic: author
46
+ Dynamic: home-page
47
+ Dynamic: license-file
48
+ Dynamic: requires-python
49
+
50
+ # Apple Search Ads Python Client
51
+
52
+ A Python client library for Apple Search Ads API v5, providing a simple and intuitive interface for managing and reporting on Apple Search Ads campaigns.
53
+
54
+ ## Features
55
+
56
+ - 🔐 OAuth2 authentication with JWT
57
+ - 📊 Campaign performance reporting
58
+ - 🏢 Multi-organization support
59
+ - 💰 Spend tracking by app
60
+ - ⚡ Built-in rate limiting
61
+ - 🐼 Pandas DataFrames for easy data manipulation
62
+ - 🔄 Automatic token refresh
63
+ - 🎯 Type hints for better IDE support
64
+ - ✅ 100% test coverage
65
+
66
+ ## Installation
67
+
68
+ ```bash
69
+ pip install apple-search-ads-client
70
+ ```
71
+
72
+ ## Quick Start
73
+
74
+ ```python
75
+ from apple_search_ads import AppleSearchAdsClient
76
+
77
+ # Initialize the client
78
+ client = AppleSearchAdsClient(
79
+ client_id="your_client_id",
80
+ team_id="your_team_id",
81
+ key_id="your_key_id",
82
+ private_key_path="/path/to/private_key.p8"
83
+ )
84
+
85
+ # Get all campaigns
86
+ campaigns = client.get_campaigns()
87
+
88
+ # Get daily spend for the last 30 days
89
+ spend_df = client.get_daily_spend(days=30)
90
+ print(spend_df)
91
+ ```
92
+
93
+ ## Authentication
94
+
95
+ ### Prerequisites
96
+
97
+ 1. An Apple Search Ads account with API access
98
+ 2. API credentials from the Apple Search Ads UI:
99
+ - Client ID
100
+ - Team ID
101
+ - Key ID
102
+ - Private key file (.p8)
103
+
104
+ ### Setting up credentials
105
+
106
+ You can provide credentials in three ways:
107
+
108
+ #### 1. Direct parameters (recommended)
109
+
110
+ ```python
111
+ client = AppleSearchAdsClient(
112
+ client_id="your_client_id",
113
+ team_id="your_team_id",
114
+ key_id="your_key_id",
115
+ private_key_path="/path/to/private_key.p8"
116
+ )
117
+ ```
118
+
119
+ #### 2. Environment variables
120
+
121
+ ```bash
122
+ export APPLE_SEARCH_ADS_CLIENT_ID="your_client_id"
123
+ export APPLE_SEARCH_ADS_TEAM_ID="your_team_id"
124
+ export APPLE_SEARCH_ADS_KEY_ID="your_key_id"
125
+ export APPLE_SEARCH_ADS_PRIVATE_KEY_PATH="/path/to/private_key.p8"
126
+ ```
127
+
128
+ ```python
129
+ client = AppleSearchAdsClient() # Will use environment variables
130
+ ```
131
+
132
+ #### 3. Private key content
133
+
134
+ ```python
135
+ # Useful for environments where file access is limited
136
+ with open("private_key.p8", "r") as f:
137
+ private_key_content = f.read()
138
+
139
+ client = AppleSearchAdsClient(
140
+ client_id="your_client_id",
141
+ team_id="your_team_id",
142
+ key_id="your_key_id",
143
+ private_key_content=private_key_content
144
+ )
145
+ ```
146
+
147
+ ## Usage Examples
148
+
149
+ ### Get all organizations
150
+
151
+ ```python
152
+ # List all organizations you have access to
153
+ orgs = client.get_all_organizations()
154
+ for org in orgs:
155
+ print(f"{org['orgName']} - {org['orgId']}")
156
+ ```
157
+
158
+ ### Get campaign performance report
159
+
160
+ ```python
161
+ from datetime import datetime, timedelta
162
+
163
+ # Get campaign performance for the last 7 days
164
+ end_date = datetime.now()
165
+ start_date = end_date - timedelta(days=7)
166
+
167
+ report_df = client.get_campaign_report(
168
+ start_date=start_date,
169
+ end_date=end_date,
170
+ granularity="DAILY" # Options: DAILY, WEEKLY, MONTHLY
171
+ )
172
+
173
+ # Display key metrics
174
+ print(report_df[['date', 'campaign_name', 'spend', 'installs', 'taps']])
175
+ ```
176
+
177
+ ### Track spend by app
178
+
179
+ ```python
180
+ # Get daily spend grouped by app
181
+ app_spend_df = client.get_daily_spend_by_app(
182
+ start_date="2024-01-01",
183
+ end_date="2024-01-31",
184
+ fetch_all_orgs=True # Fetch from all organizations
185
+ )
186
+
187
+ # Group by app and sum
188
+ app_totals = app_spend_df.groupby('app_id').agg({
189
+ 'spend': 'sum',
190
+ 'installs': 'sum',
191
+ 'impressions': 'sum'
192
+ }).round(2)
193
+
194
+ print(app_totals)
195
+ ```
196
+
197
+ ### Get campaigns from all organizations
198
+
199
+ ```python
200
+ # Fetch campaigns across all organizations
201
+ all_campaigns = client.get_all_campaigns()
202
+
203
+ # Filter active campaigns
204
+ active_campaigns = [c for c in all_campaigns if c['status'] == 'ENABLED']
205
+
206
+ print(f"Found {len(active_campaigns)} active campaigns across all orgs")
207
+ ```
208
+
209
+ ### Working with specific organization
210
+
211
+ ```python
212
+ # Get campaigns for a specific org
213
+ org_id = "123456"
214
+ campaigns = client.get_campaigns(org_id=org_id)
215
+
216
+ # The client will use this org for subsequent requests
217
+ ```
218
+
219
+ ### Working with ad groups
220
+
221
+ ```python
222
+ # Get ad groups for a campaign
223
+ campaign_id = "1234567890"
224
+ adgroups = client.get_adgroups(campaign_id)
225
+
226
+ for adgroup in adgroups:
227
+ print(f"Ad Group: {adgroup['name']} (Status: {adgroup['status']})")
228
+ ```
229
+
230
+ ## API Reference
231
+
232
+ ### Client initialization
233
+
234
+ ```python
235
+ AppleSearchAdsClient(
236
+ client_id: Optional[str] = None,
237
+ team_id: Optional[str] = None,
238
+ key_id: Optional[str] = None,
239
+ private_key_path: Optional[str] = None,
240
+ private_key_content: Optional[str] = None,
241
+ org_id: Optional[str] = None
242
+ )
243
+ ```
244
+
245
+ ### Methods
246
+
247
+ #### Organizations
248
+
249
+ - `get_all_organizations()` - Get all organizations
250
+ - `get_campaigns(org_id: Optional[str] = None)` - Get campaigns for an organization
251
+ - `get_all_campaigns()` - Get campaigns from all organizations
252
+
253
+ #### Reporting
254
+
255
+ - `get_campaign_report(start_date, end_date, granularity="DAILY")` - Get campaign performance report
256
+ - `get_daily_spend(days=30, fetch_all_orgs=True)` - Get daily spend for the last N days
257
+ - `get_daily_spend_with_dates(start_date, end_date, fetch_all_orgs=True)` - Get daily spend for date range
258
+ - `get_daily_spend_by_app(start_date, end_date, fetch_all_orgs=True)` - Get spend grouped by app
259
+
260
+ #### Campaign Management
261
+
262
+ - `get_campaigns_with_details(fetch_all_orgs=True)` - Get campaigns with app details
263
+ - `get_adgroups(campaign_id)` - Get ad groups for a specific campaign
264
+
265
+ ## DataFrame Output
266
+
267
+ All reporting methods return pandas DataFrames for easy data manipulation:
268
+
269
+ ```python
270
+ # Example: Calculate weekly totals
271
+ daily_spend = client.get_daily_spend(days=30)
272
+ daily_spend['week'] = pd.to_datetime(daily_spend['date']).dt.isocalendar().week
273
+ weekly_totals = daily_spend.groupby('week')['spend'].sum()
274
+ ```
275
+
276
+ ## Rate Limiting
277
+
278
+ The client includes built-in rate limiting to respect Apple's API limits (10 requests per second). You don't need to implement any additional rate limiting.
279
+
280
+ ## Error Handling
281
+
282
+ ```python
283
+ from apple_search_ads.exceptions import (
284
+ AuthenticationError,
285
+ RateLimitError,
286
+ OrganizationNotFoundError
287
+ )
288
+
289
+ try:
290
+ campaigns = client.get_campaigns()
291
+ except AuthenticationError as e:
292
+ print(f"Authentication failed: {e}")
293
+ except RateLimitError as e:
294
+ print(f"Rate limit exceeded: {e}")
295
+ except Exception as e:
296
+ print(f"An error occurred: {e}")
297
+ ```
298
+
299
+ ## Best Practices
300
+
301
+ 1. **Reuse client instances**: Create one client and reuse it for multiple requests
302
+ 2. **Use date ranges wisely**: Large date ranges may result in slower responses
303
+ 3. **Cache organization IDs**: If working with specific orgs frequently, cache their IDs
304
+ 4. **Monitor rate limits**: Although built-in rate limiting is included, be mindful of your usage
305
+ 5. **Use DataFrame operations**: Leverage pandas for data aggregation and analysis
306
+
307
+ ## Requirements
308
+
309
+ - Python 3.8 or higher
310
+ - See `requirements.txt` for package dependencies
311
+
312
+ ## Testing
313
+
314
+ This project maintains **100% test coverage**. The test suite includes:
315
+
316
+ - Unit tests with mocked API responses
317
+ - Exception handling tests
318
+ - Edge case coverage
319
+ - Legacy API format compatibility tests
320
+ - Comprehensive integration tests
321
+
322
+ ### Running Tests
323
+
324
+ ```bash
325
+ # Run all tests with coverage report
326
+ pytest tests -v --cov=apple_search_ads --cov-report=term-missing
327
+
328
+ # Run tests in parallel for faster execution
329
+ pytest tests -n auto
330
+
331
+ # Generate HTML coverage report
332
+ pytest tests --cov=apple_search_ads --cov-report=html
333
+
334
+ # Run integration tests (requires credentials)
335
+ pytest tests/test_integration.py -v
336
+ ```
337
+
338
+ For detailed testing documentation, see [TESTING.md](TESTING.md).
339
+ For integration testing setup, see [docs/integration-testing.md](docs/integration-testing.md).
340
+
341
+ ## Contributing
342
+
343
+ Contributions are welcome! Please feel free to submit a Pull Request.
344
+
345
+ 1. Fork the repository
346
+ 2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
347
+ 3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
348
+ 4. Push to the branch (`git push origin feature/AmazingFeature`)
349
+ 5. Open a Pull Request
350
+
351
+ ## License
352
+
353
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
354
+
355
+ ## Support
356
+
357
+ - 🐛 Issues: [GitHub Issues](https://github.com/bickster/apple-search-ads-python/issues)
358
+ - 📖 Documentation: [Read the Docs](https://apple-search-ads-python.readthedocs.io/)
359
+
360
+ ## Changelog
361
+
362
+ See [CHANGELOG.md](CHANGELOG.md) for a list of changes.
363
+
364
+ ## Acknowledgments
365
+
366
+ - Apple for providing the Search Ads API
367
+ - The Python community for excellent libraries used in this project