Official Python SDK for DynamicAds API
Project description
DynamicAds Python SDK
Official Python SDK for the DynamicAds API.
Installation
pip install dynamicads
Quick Start
from dynamicads import DynamicAdsClient
# Initialize the client
client = DynamicAdsClient('your-api-key')
# Generate a new ad
ad = client.generate(
prompt='Create a dynamic product showcase',
media_type='video',
dimensions={'width': 672, 'height': 384}
)
# Wait for completion
completed_ad = client.wait_for_completion(ad.id)
print(f"Ad generated: {completed_ad.media_url}")
Features
- Generate video and image ads
- Track generation status
- List all your ads
- Monitor API usage
- Type hints for better IDE support
- Comprehensive error handling
Examples
Generate an Ad
# Start generation
ad = client.generate(
prompt='Create a dynamic product showcase',
media_type='video',
dimensions={'width': 672, 'height': 384}
)
# Wait for completion with custom timeout
try:
completed_ad = client.wait_for_completion(
ad.id,
timeout=600, # 10 minutes
interval=5 # Check every 5 seconds
)
print(f"Media URL: {completed_ad.media_url}")
print(f"Voice URL: {completed_ad.voice_url}")
print(f"Component Code: {completed_ad.component_code}")
except DynamicAdsTimeoutError:
print("Generation timed out")
List All Ads
# Get all ads
ads = client.list_ads()
for ad in ads:
print(f"Ad {ad.id}: {ad.status}")
if ad.is_complete:
print(f" Media URL: {ad.media_url}")
Check Usage
# Get usage info
usage = client.get_usage()
print(f"Used {usage.current_usage} out of {usage.limit} credits")
Error Handling
from dynamicads.exceptions import (
DynamicAdsError,
DynamicAdsTimeoutError,
DynamicAdsAuthError,
DynamicAdsRateLimitError,
DynamicAdsValidationError
)
try:
ad = client.generate(prompt='Create an ad')
except DynamicAdsAuthError:
print("Invalid API key")
except DynamicAdsRateLimitError:
print("Rate limit exceeded")
except DynamicAdsValidationError:
print("Invalid request parameters")
except DynamicAdsTimeoutError:
print("Operation timed out")
except DynamicAdsError as e:
print(f"Other error: {e}")
API Reference
Configuration
client = DynamicAdsClient(
api_key='your-api-key', # Required
base_url='https://api.dynamicads.dev/api', # Optional
debug=False # Optional
)
Methods
generate(prompt, media_type='video', dimensions=None)
Generate a new ad with the given options.
- prompt: Description of the ad
- media_type: 'video' or 'image'
- dimensions: Dict with 'width' and 'height'
get_ad(id)
Get details of a specific ad.
list_ads()
List all ads associated with your API key.
get_usage()
Get current usage information.
wait_for_completion(id, timeout=300, interval=2)
Wait for an ad to complete generation.
- timeout: Max time to wait in seconds
- interval: Check interval in seconds
Response Types
Ad Object
@dataclass
class Ad:
id: str
status: str # 'processing', 'complete', or 'error'
media_url: Optional[str]
voice_url: Optional[str]
component_code: Optional[str]
voice_script: Optional[str]
prompt: str
dimensions: AdDimensions
media_type: str
error: Optional[str]
created_at: Optional[str]
Usage Object
@dataclass
class Usage:
current_usage: int
limit: int
Development
To contribute to the SDK:
- Clone the repository
- Install development dependencies:
pip install -e ".[dev]"
- Run tests:
pytest
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dynamicads-2.0.1.tar.gz
(5.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dynamicads-2.0.1.tar.gz.
File metadata
- Download URL: dynamicads-2.0.1.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
876c0329ed46a1d05f739cfbce5a685f4a82dcbf783fc1c61bb45c11c75d4f15
|
|
| MD5 |
71268eaa0c4eb68d19f90051c3e7bef4
|
|
| BLAKE2b-256 |
abd43a829a61bceb26260ee745fd4ffe3dab873132410348e981e921bdd41af1
|
File details
Details for the file dynamicads-2.0.1-py3-none-any.whl.
File metadata
- Download URL: dynamicads-2.0.1-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a8e959e0af4101a924faf16070cf8b516aa7e72a3c7d6c634e885298e256ba3
|
|
| MD5 |
38a546ce5fe1edd3e06ef146c2e70e21
|
|
| BLAKE2b-256 |
f6b55f79f428da9a1a75ef79ef5a7492c99e74b7fcff6ab4b5e7512315385306
|