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.0.tar.gz
(5.4 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.0.tar.gz.
File metadata
- Download URL: dynamicads-2.0.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3a079c4c486089ab8c274dbf4d36f2c5e5fee5ef49ffb6902af89f40342f449
|
|
| MD5 |
0cb4ff5e0aba1039cc174bba892951e9
|
|
| BLAKE2b-256 |
62f4985844a385269a7d1ceaa9bcbfd099575ba70edfed789e333d934a24b814
|
File details
Details for the file dynamicads-2.0.0-py3-none-any.whl.
File metadata
- Download URL: dynamicads-2.0.0-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 |
ebed1fbb390dd1a247b0bcacab35ed2357f5abe557ded92c8b2033ec5d829363
|
|
| MD5 |
b70fed288eff840c45185a105f6d5c5b
|
|
| BLAKE2b-256 |
9e639b5747711abb1eb809ef806983cba3fdac566584855f42011ff13ff84185
|