AdsonAI Python SDK
Python SDK for AdsonAI - AI-powered contextual advertising platform.
🚀 Quick Start
Installation
pip install adsonai-sdk
Get API Key
- Visit AdsonAI Dashboard
- Create a new API key
- Copy your key (starts with
adsonai_)
Basic Usage
from adsonai_sdk import AdsonAI
# Initialize client
client = AdsonAI(api_key="your_adsonai_api_key")
# Get contextual ads
ads = client.get_contextual_ads("I need running shoes", max_ads=3)
# Display results
for ad in ads:
print(f"🏷️ {ad.brand_name} - {ad.product_name}")
print(f"💬 {ad.ad_text}")
print(f"💰 Bid: ${ad.bid_amount}")
if ad.landing_url:
print(f"🔗 {ad.landing_url}")
print()
client.close()
📖 Documentation
AdsonAI Class
AdsonAI(api_key, base_url=None, timeout=30)
Initialize the AdsonAI client.
Parameters:
api_key(str): Your AdsonAI API keybase_url(str, optional): Custom API base URLtimeout(int, optional): Request timeout in seconds
test_connection()
Test connection to the AdsonAI API.
Returns: bool - True if successful
get_contextual_ads(query, max_ads=3, context=None)
Get contextual ads using AI matching.
Parameters:
query(str): User query or conversation contextmax_ads(int): Maximum ads to return (1-10)context(dict, optional): Additional context for matching
Returns: List[Ad] - List of matched ads
Ad Object
Properties:
id: Unique ad identifierbrand_name: Brand or company nameproduct_name: Product or service namedescription: Ad descriptionad_text: Display text for the adbid_amount: Bid amount in USDlanding_url: Landing page URL (optional)target_keywords: Target keywordsstatus: Ad status
Exception Handling
from adsonai_sdk import AdsonAI, AuthenticationError, APIError, ValidationError
try:
client = AdsonAI(api_key="your_key")
ads = client.get_contextual_ads("search query")
except AuthenticationError:
print("Invalid API key")
except APIError as e:
print(f"API error: {e}")
except ValidationError as e:
print(f"Validation error: {e}")
💡 Examples
Context Manager
with AdsonAI(api_key="your_key") as client:
ads = client.get_contextual_ads("smart home devices")
for ad in ads:
print(f"{ad.brand_name}: {ad.ad_text}")
Convenience Function
from adsonai_sdk import get_ads
# Quick one-liner
ads = get_ads("your_key", "gaming laptop", max_ads=5)
Chatbot Integration
def get_sponsored_suggestion(user_message):
try:
ads = get_ads(API_KEY, user_message, max_ads=1)
if ads:
ad = ads[0]
return f"💡 {ad.brand_name}: {ad.ad_text}"
except Exception:
pass
return None
# In your chatbot
user_input = "I need a new coffee maker"
suggestion = get_sponsored_suggestion(user_input)
if suggestion:
print(suggestion)
E-commerce Integration
def show_sponsored_products(search_query):
with AdsonAI(api_key=API_KEY) as client:
ads = client.get_contextual_ads(search_query, max_ads=3)
print("🎯 Sponsored Products:")
for ad in ads:
print(f"• {ad.brand_name} - {ad.product_name}")
print(f" {ad.ad_text}")
print(f" ${ad.bid_amount} | {ad.landing_url}")
🔧 Advanced Usage
With Additional Context
context = {
'user_location': 'San Francisco',
'user_age': '25-34',
'interests': ['fitness', 'technology'],
'budget': 'mid-range'
}
ads = client.get_contextual_ads(
"workout equipment",
max_ads=5,
context=context
)
Error Handling with Retries
import time
from adsonai_sdk import AdsonAI, APIError
def get_ads_with_retry(query, max_retries=3):
for attempt in range(max_retries):
try:
with AdsonAI(api_key=API_KEY) as client:
return client.get_contextual_ads(query)
except APIError as e:
if e.status_code == 429: # Rate limit
time.sleep(2 ** attempt) # Exponential backoff
continue
raise
return []
🧪 Testing
# Set your API key
export ADSONAI_API_KEY="your_actual_api_key"
# Run tests
python -m pytest tests/
# Run integration test
python test_live_api.py
📝 License
MIT License - see LICENSE file for details.
🤝 Support
- 📚 Documentation: https://docs.adsonai.com
- 🎛️ Dashboard: https://adsonai.vercel.app
- 🐛 Issues: GitHub Issues
- 📧 Email: developers@adsonai.com
🛣️ Roadmap
- Async support with
aiohttp - Batch ad matching
- Advanced analytics
- Webhook support
- Ad performance tracking
Metadata
Release files for adsonai 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| adsonai-1.0.0.tar.gz | 20.3 kB | Without provenance | Details for adsonai-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| adsonai-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for adsonai-1.0.0-py3-none-any.whl |
Total release size: 36.1 kB
Release files / adsonai-1.0.0.tar.gz
| Download URL | adsonai-1.0.0.tar.gz |
|---|---|
| Size | 20.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
21ca3c5e0f8dce145c6d6125f3dac8bc874650c75e7b37437c6d751f3833b4fb
|
|
BLAKE2b-256 checksum How to use checksums |
a5f659695b2854bb4b9df913bb81334c4b82ff69ff498d951cc929e4cbcb2f41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.4
|
Release files / adsonai-1.0.0-py3-none-any.whl
| Download URL | adsonai-1.0.0-py3-none-any.whl |
|---|---|
| Size | 15.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fdf43d9cd242d3a27e7b9ce8891e3e991897c7e6efbfb4c5dfc4b6a920b8c9e1
|
|
BLAKE2b-256 checksum How to use checksums |
9e5b69219851b09764e7703638250021e671e374d8212e59a0cc705e0cd82a69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.4
|
Security for adsonai 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.