universal-ads-sdk 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Universal Ads
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,7 @@
1
+ include README.md
2
+ include LICENSE
3
+ include requirements.txt
4
+ include pyproject.toml
5
+ recursive-include universal_ads_sdk *.py
6
+ recursive-exclude * __pycache__
7
+ recursive-exclude * *.py[co]
@@ -0,0 +1,350 @@
1
+ Metadata-Version: 2.4
2
+ Name: universal-ads-sdk
3
+ Version: 1.0.0
4
+ Summary: Python SDK for the Universal Ads Third Party API
5
+ Home-page: https://github.com/Universal-Ads/universal-ads-sdk-python
6
+ Author: Universal Ads
7
+ Author-email: Universal Ads <support@universalads.com>
8
+ License: MIT
9
+ Project-URL: Homepage, https://github.com/universal-ads/universal-ads-sdk-python
10
+ Project-URL: Documentation, https://docs.universalads.com/sdk/python
11
+ Project-URL: Repository, https://github.com/universal-ads/universal-ads-sdk-python
12
+ Project-URL: Bug Tracker, https://github.com/universal-ads/universal-ads-sdk-python/issues
13
+ Keywords: ads,advertising,api,sdk,universal-ads
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
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: Topic :: Software Development :: Libraries :: Python Modules
25
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
26
+ Requires-Python: >=3.8
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Requires-Dist: requests>=2.25.0
30
+ Requires-Dist: cryptography>=3.4.0
31
+ Requires-Dist: urllib3>=1.26.0
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=6.0; extra == "dev"
34
+ Requires-Dist: pytest-cov>=2.0; extra == "dev"
35
+ Requires-Dist: black>=21.0; extra == "dev"
36
+ Requires-Dist: flake8>=3.8; extra == "dev"
37
+ Requires-Dist: mypy>=0.800; extra == "dev"
38
+ Dynamic: author
39
+ Dynamic: home-page
40
+ Dynamic: license-file
41
+ Dynamic: requires-python
42
+
43
+ # Universal Ads SDK
44
+
45
+ A Python SDK for interacting with the Universal Ads Third Party API. This SDK provides a simple and intuitive interface for managing creatives, uploading media, and accessing performance reports.
46
+
47
+ ## Features
48
+
49
+ - **Creative Management**: Create, read, update, and delete creatives
50
+ - **Media Upload**: Upload and verify media files
51
+ - **Reports**: Access campaign, adset, and ad performance data
52
+ - **Secure Authentication**:
53
+ - **Automatic Retries**: Built-in retry logic for robust API interactions
54
+ - **Type Hints**: Full type annotation support for better development experience
55
+
56
+ ## Installation
57
+
58
+ ```bash
59
+ pip install universal-ads-sdk
60
+ ```
61
+
62
+ ## Quick Start
63
+
64
+ ### 1. Initialize the Client
65
+
66
+ ```python
67
+ from universal_ads_sdk import UniversalAdsClient
68
+
69
+ # Initialize the client with your API credentials
70
+ client = UniversalAdsClient(
71
+ api_key="your-api-key",
72
+ private_key_pem="""-----BEGIN PRIVATE KEY-----
73
+ your-private-key-content
74
+ -----END PRIVATE KEY-----"""
75
+ )
76
+ ```
77
+
78
+ ### 2. Upload Media
79
+
80
+ ```python
81
+ # Upload a media file
82
+ upload_info = client.upload_media(
83
+ file_path="/path/to/your/image.jpg",
84
+ content_type="image/jpeg"
85
+ )
86
+
87
+ # Use the presigned URL to upload your file
88
+ import requests
89
+ with open("/path/to/your/image.jpg", "rb") as f:
90
+ requests.put(upload_info["upload_url"], data=f)
91
+
92
+ # Verify the upload
93
+ media = client.verify_media(upload_info["media_id"])
94
+ print(f"Media verified: {media['status']}")
95
+ ```
96
+
97
+ ### 3. Create a Creative
98
+
99
+ ```python
100
+ # Create a new creative
101
+ creative = client.create_creative(
102
+ ad_account_id="3d49e08c-465d-4673-a445-d4ba3575f032",
103
+ name="My Creative",
104
+ media_id="cc0f46c7-d9b9-4758-9479-17e1d77c5eea"
105
+ )
106
+ print(f"Created creative: {creative['id']}")
107
+ ```
108
+
109
+ ### 4. Get Performance Reports
110
+
111
+ ```python
112
+ # Get campaign performance report
113
+ report = client.get_campaign_report(
114
+ start_date="2024-01-01",
115
+ end_date="2024-01-31",
116
+ ad_account_id="3d49e08c-465d-4673-a445-d4ba3575f032"
117
+ )
118
+ print(f"Report contains {len(report['data'])} campaigns")
119
+ ```
120
+
121
+ ## API Reference
122
+
123
+ ### Client Initialization
124
+
125
+ ```python
126
+ UniversalAdsClient(
127
+ api_key: str, # Your API key
128
+ private_key_pem: str, # Your private key in PEM format
129
+ base_url: Optional[str] = None, # API base URL (defaults to production)
130
+ timeout: int = 30, # Request timeout in seconds
131
+ max_retries: int = 3 # Maximum retry attempts
132
+ )
133
+ ```
134
+
135
+ ### Creative Management
136
+
137
+ #### Get All Creatives
138
+ ```python
139
+ creatives = client.get_creatives(
140
+ ad_account_id="account-id", # Optional: filter by account
141
+ limit=50, # Optional: limit results
142
+ offset=0, # Optional: pagination offset
143
+ sort="name_asc" # Optional: sort order
144
+ )
145
+ ```
146
+
147
+ #### Get Specific Creative
148
+ ```python
149
+ creative = client.get_creative("creative-id")
150
+ ```
151
+
152
+ #### Create Creative
153
+ ```python
154
+ creative = client.create_creative(
155
+ ad_account_id="account-id",
156
+ name="Creative Name",
157
+ media_id="media-id"
158
+ )
159
+ ```
160
+
161
+ #### Update Creative
162
+ ```python
163
+ creative = client.update_creative(
164
+ "creative-id",
165
+ name="New Name"
166
+ )
167
+ ```
168
+
169
+ #### Delete Creative
170
+ ```python
171
+ client.delete_creative("creative-id")
172
+ ```
173
+
174
+ ### Media Management
175
+
176
+ #### Upload Media
177
+ ```python
178
+ upload_info = client.upload_media(
179
+ file_path="/path/to/file",
180
+ content_type="image/jpeg",
181
+ filename="optional-filename.jpg" # Optional
182
+ )
183
+ ```
184
+
185
+ #### Verify Media
186
+ ```python
187
+ media = client.verify_media("media-id")
188
+ ```
189
+
190
+ ### Reporting
191
+
192
+ #### Campaign Report
193
+ ```python
194
+ report = client.get_campaign_report(
195
+ start_date="2024-01-01",
196
+ end_date="2024-01-31",
197
+ ad_account_id="account-id", # Optional
198
+ campaign_ids=["id1", "id2"], # Optional
199
+ limit=100, # Optional
200
+ offset=0 # Optional
201
+ )
202
+ ```
203
+
204
+ #### Adset Report
205
+ ```python
206
+ report = client.get_adset_report(
207
+ start_date="2024-01-01",
208
+ end_date="2024-01-31",
209
+ ad_account_id="account-id", # Optional
210
+ adset_ids=["id1", "id2"], # Optional
211
+ limit=100, # Optional
212
+ offset=0 # Optional
213
+ )
214
+ ```
215
+
216
+ #### Ad Report
217
+ ```python
218
+ report = client.get_ad_report(
219
+ start_date="2024-01-01",
220
+ end_date="2024-01-31",
221
+ ad_account_id="account-id", # Optional
222
+ ad_ids=["id1", "id2"], # Optional
223
+ limit=100, # Optional
224
+ offset=0 # Optional
225
+ )
226
+ ```
227
+
228
+ ## Error Handling
229
+
230
+ The SDK provides specific exception types for different error scenarios:
231
+
232
+ ```python
233
+ from universal_ads_sdk import UniversalAdsError, AuthenticationError, APIError
234
+
235
+ try:
236
+ creative = client.create_creative(...)
237
+ except AuthenticationError as e:
238
+ print(f"Authentication failed: {e}")
239
+ except APIError as e:
240
+ print(f"API error {e.status_code}: {e}")
241
+ print(f"Response data: {e.response_data}")
242
+ except UniversalAdsError as e:
243
+ print(f"SDK error: {e}")
244
+ ```
245
+
246
+ ## Configuration
247
+
248
+ ### Environment Variables
249
+
250
+ You can also initialize the client using environment variables:
251
+
252
+ ```python
253
+ import os
254
+ from universal_ads_sdk import UniversalAdsClient
255
+
256
+ client = UniversalAdsClient(
257
+ api_key=os.getenv("UNIVERSAL_ADS_API_KEY"),
258
+ private_key_pem=os.getenv("UNIVERSAL_ADS_PRIVATE_KEY")
259
+ )
260
+ ```
261
+
262
+ ### Custom Base URL
263
+
264
+ For testing or development, you can use a custom base URL:
265
+
266
+ ```python
267
+ client = UniversalAdsClient(
268
+ api_key="your-api-key",
269
+ private_key_pem="your-private-key",
270
+ base_url="https://staging-api.universalads.com/v1"
271
+ )
272
+ ```
273
+
274
+ ## Authentication
275
+
276
+ The SDK uses request signing for secure API access. Each request is signed with your private key and includes:
277
+
278
+ ## Requirements
279
+
280
+ - Python 3.8+
281
+ - requests >= 2.25.0
282
+ - cryptography >= 3.4.0
283
+ - urllib3 >= 1.26.0
284
+
285
+ ## Security
286
+
287
+ ### API Credentials
288
+ - **Never commit API credentials to version control**
289
+ - Use environment variables for production deployments
290
+ - Test files with credentials are excluded from git via `.gitignore`
291
+
292
+ ### Environment Variables (Recommended)
293
+ ```bash
294
+ export UNIVERSAL_ADS_API_KEY="your-api-key"
295
+ export UNIVERSAL_ADS_PRIVATE_KEY="your-private-key-pem"
296
+ ```
297
+
298
+ ```python
299
+ import os
300
+ from universal_ads_sdk import UniversalAdsClient
301
+
302
+ client = UniversalAdsClient(
303
+ api_key=os.getenv("UNIVERSAL_ADS_API_KEY"),
304
+ private_key_pem=os.getenv("UNIVERSAL_ADS_PRIVATE_KEY")
305
+ )
306
+ ```
307
+
308
+ ## Development
309
+
310
+ ### Running Tests
311
+
312
+ The SDK includes test templates in the `tests/` directory. For security, use environment variables:
313
+
314
+ ```bash
315
+ # Set up environment variables
316
+ cp env.template .env
317
+ # Edit .env with your credentials
318
+ pip install python-dotenv # Optional, for better .env support
319
+
320
+ # Quick test (basic validation)
321
+ python tests/test_template.py
322
+
323
+ # Comprehensive test (all endpoints)
324
+ python tests/comprehensive_test.py
325
+ ```
326
+
327
+ See `tests/README.md` for detailed testing information.
328
+
329
+ For development testing with pytest:
330
+ ```bash
331
+ pip install -e ".[dev]"
332
+ pytest
333
+ ```
334
+
335
+ ### Code Formatting
336
+
337
+ ```bash
338
+ black universal_ads_sdk/
339
+ flake8 universal_ads_sdk/
340
+ ```
341
+
342
+ ## Support
343
+
344
+ - Documentation: [https://developers.universalads.com/](https://developers.universalads.com/)
345
+ - Issues: [GitHub Issues](https://github.com/universal-ads/universal-ads-sdk-python/issues)
346
+ - Email: support+sdk@universalads.com
347
+
348
+ ## License
349
+
350
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,308 @@
1
+ # Universal Ads SDK
2
+
3
+ A Python SDK for interacting with the Universal Ads Third Party API. This SDK provides a simple and intuitive interface for managing creatives, uploading media, and accessing performance reports.
4
+
5
+ ## Features
6
+
7
+ - **Creative Management**: Create, read, update, and delete creatives
8
+ - **Media Upload**: Upload and verify media files
9
+ - **Reports**: Access campaign, adset, and ad performance data
10
+ - **Secure Authentication**:
11
+ - **Automatic Retries**: Built-in retry logic for robust API interactions
12
+ - **Type Hints**: Full type annotation support for better development experience
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pip install universal-ads-sdk
18
+ ```
19
+
20
+ ## Quick Start
21
+
22
+ ### 1. Initialize the Client
23
+
24
+ ```python
25
+ from universal_ads_sdk import UniversalAdsClient
26
+
27
+ # Initialize the client with your API credentials
28
+ client = UniversalAdsClient(
29
+ api_key="your-api-key",
30
+ private_key_pem="""-----BEGIN PRIVATE KEY-----
31
+ your-private-key-content
32
+ -----END PRIVATE KEY-----"""
33
+ )
34
+ ```
35
+
36
+ ### 2. Upload Media
37
+
38
+ ```python
39
+ # Upload a media file
40
+ upload_info = client.upload_media(
41
+ file_path="/path/to/your/image.jpg",
42
+ content_type="image/jpeg"
43
+ )
44
+
45
+ # Use the presigned URL to upload your file
46
+ import requests
47
+ with open("/path/to/your/image.jpg", "rb") as f:
48
+ requests.put(upload_info["upload_url"], data=f)
49
+
50
+ # Verify the upload
51
+ media = client.verify_media(upload_info["media_id"])
52
+ print(f"Media verified: {media['status']}")
53
+ ```
54
+
55
+ ### 3. Create a Creative
56
+
57
+ ```python
58
+ # Create a new creative
59
+ creative = client.create_creative(
60
+ ad_account_id="3d49e08c-465d-4673-a445-d4ba3575f032",
61
+ name="My Creative",
62
+ media_id="cc0f46c7-d9b9-4758-9479-17e1d77c5eea"
63
+ )
64
+ print(f"Created creative: {creative['id']}")
65
+ ```
66
+
67
+ ### 4. Get Performance Reports
68
+
69
+ ```python
70
+ # Get campaign performance report
71
+ report = client.get_campaign_report(
72
+ start_date="2024-01-01",
73
+ end_date="2024-01-31",
74
+ ad_account_id="3d49e08c-465d-4673-a445-d4ba3575f032"
75
+ )
76
+ print(f"Report contains {len(report['data'])} campaigns")
77
+ ```
78
+
79
+ ## API Reference
80
+
81
+ ### Client Initialization
82
+
83
+ ```python
84
+ UniversalAdsClient(
85
+ api_key: str, # Your API key
86
+ private_key_pem: str, # Your private key in PEM format
87
+ base_url: Optional[str] = None, # API base URL (defaults to production)
88
+ timeout: int = 30, # Request timeout in seconds
89
+ max_retries: int = 3 # Maximum retry attempts
90
+ )
91
+ ```
92
+
93
+ ### Creative Management
94
+
95
+ #### Get All Creatives
96
+ ```python
97
+ creatives = client.get_creatives(
98
+ ad_account_id="account-id", # Optional: filter by account
99
+ limit=50, # Optional: limit results
100
+ offset=0, # Optional: pagination offset
101
+ sort="name_asc" # Optional: sort order
102
+ )
103
+ ```
104
+
105
+ #### Get Specific Creative
106
+ ```python
107
+ creative = client.get_creative("creative-id")
108
+ ```
109
+
110
+ #### Create Creative
111
+ ```python
112
+ creative = client.create_creative(
113
+ ad_account_id="account-id",
114
+ name="Creative Name",
115
+ media_id="media-id"
116
+ )
117
+ ```
118
+
119
+ #### Update Creative
120
+ ```python
121
+ creative = client.update_creative(
122
+ "creative-id",
123
+ name="New Name"
124
+ )
125
+ ```
126
+
127
+ #### Delete Creative
128
+ ```python
129
+ client.delete_creative("creative-id")
130
+ ```
131
+
132
+ ### Media Management
133
+
134
+ #### Upload Media
135
+ ```python
136
+ upload_info = client.upload_media(
137
+ file_path="/path/to/file",
138
+ content_type="image/jpeg",
139
+ filename="optional-filename.jpg" # Optional
140
+ )
141
+ ```
142
+
143
+ #### Verify Media
144
+ ```python
145
+ media = client.verify_media("media-id")
146
+ ```
147
+
148
+ ### Reporting
149
+
150
+ #### Campaign Report
151
+ ```python
152
+ report = client.get_campaign_report(
153
+ start_date="2024-01-01",
154
+ end_date="2024-01-31",
155
+ ad_account_id="account-id", # Optional
156
+ campaign_ids=["id1", "id2"], # Optional
157
+ limit=100, # Optional
158
+ offset=0 # Optional
159
+ )
160
+ ```
161
+
162
+ #### Adset Report
163
+ ```python
164
+ report = client.get_adset_report(
165
+ start_date="2024-01-01",
166
+ end_date="2024-01-31",
167
+ ad_account_id="account-id", # Optional
168
+ adset_ids=["id1", "id2"], # Optional
169
+ limit=100, # Optional
170
+ offset=0 # Optional
171
+ )
172
+ ```
173
+
174
+ #### Ad Report
175
+ ```python
176
+ report = client.get_ad_report(
177
+ start_date="2024-01-01",
178
+ end_date="2024-01-31",
179
+ ad_account_id="account-id", # Optional
180
+ ad_ids=["id1", "id2"], # Optional
181
+ limit=100, # Optional
182
+ offset=0 # Optional
183
+ )
184
+ ```
185
+
186
+ ## Error Handling
187
+
188
+ The SDK provides specific exception types for different error scenarios:
189
+
190
+ ```python
191
+ from universal_ads_sdk import UniversalAdsError, AuthenticationError, APIError
192
+
193
+ try:
194
+ creative = client.create_creative(...)
195
+ except AuthenticationError as e:
196
+ print(f"Authentication failed: {e}")
197
+ except APIError as e:
198
+ print(f"API error {e.status_code}: {e}")
199
+ print(f"Response data: {e.response_data}")
200
+ except UniversalAdsError as e:
201
+ print(f"SDK error: {e}")
202
+ ```
203
+
204
+ ## Configuration
205
+
206
+ ### Environment Variables
207
+
208
+ You can also initialize the client using environment variables:
209
+
210
+ ```python
211
+ import os
212
+ from universal_ads_sdk import UniversalAdsClient
213
+
214
+ client = UniversalAdsClient(
215
+ api_key=os.getenv("UNIVERSAL_ADS_API_KEY"),
216
+ private_key_pem=os.getenv("UNIVERSAL_ADS_PRIVATE_KEY")
217
+ )
218
+ ```
219
+
220
+ ### Custom Base URL
221
+
222
+ For testing or development, you can use a custom base URL:
223
+
224
+ ```python
225
+ client = UniversalAdsClient(
226
+ api_key="your-api-key",
227
+ private_key_pem="your-private-key",
228
+ base_url="https://staging-api.universalads.com/v1"
229
+ )
230
+ ```
231
+
232
+ ## Authentication
233
+
234
+ The SDK uses request signing for secure API access. Each request is signed with your private key and includes:
235
+
236
+ ## Requirements
237
+
238
+ - Python 3.8+
239
+ - requests >= 2.25.0
240
+ - cryptography >= 3.4.0
241
+ - urllib3 >= 1.26.0
242
+
243
+ ## Security
244
+
245
+ ### API Credentials
246
+ - **Never commit API credentials to version control**
247
+ - Use environment variables for production deployments
248
+ - Test files with credentials are excluded from git via `.gitignore`
249
+
250
+ ### Environment Variables (Recommended)
251
+ ```bash
252
+ export UNIVERSAL_ADS_API_KEY="your-api-key"
253
+ export UNIVERSAL_ADS_PRIVATE_KEY="your-private-key-pem"
254
+ ```
255
+
256
+ ```python
257
+ import os
258
+ from universal_ads_sdk import UniversalAdsClient
259
+
260
+ client = UniversalAdsClient(
261
+ api_key=os.getenv("UNIVERSAL_ADS_API_KEY"),
262
+ private_key_pem=os.getenv("UNIVERSAL_ADS_PRIVATE_KEY")
263
+ )
264
+ ```
265
+
266
+ ## Development
267
+
268
+ ### Running Tests
269
+
270
+ The SDK includes test templates in the `tests/` directory. For security, use environment variables:
271
+
272
+ ```bash
273
+ # Set up environment variables
274
+ cp env.template .env
275
+ # Edit .env with your credentials
276
+ pip install python-dotenv # Optional, for better .env support
277
+
278
+ # Quick test (basic validation)
279
+ python tests/test_template.py
280
+
281
+ # Comprehensive test (all endpoints)
282
+ python tests/comprehensive_test.py
283
+ ```
284
+
285
+ See `tests/README.md` for detailed testing information.
286
+
287
+ For development testing with pytest:
288
+ ```bash
289
+ pip install -e ".[dev]"
290
+ pytest
291
+ ```
292
+
293
+ ### Code Formatting
294
+
295
+ ```bash
296
+ black universal_ads_sdk/
297
+ flake8 universal_ads_sdk/
298
+ ```
299
+
300
+ ## Support
301
+
302
+ - Documentation: [https://developers.universalads.com/](https://developers.universalads.com/)
303
+ - Issues: [GitHub Issues](https://github.com/universal-ads/universal-ads-sdk-python/issues)
304
+ - Email: support+sdk@universalads.com
305
+
306
+ ## License
307
+
308
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.