Python SDK for AdsOverAI - Native advertising for AI chat interfaces
Project description
Python SDK for AdsOverAI - Native advertising for AI chat interfaces
Features
- 🎯 Context-Aware Ads - Display relevant ads based on AI conversation context
- ⚡ Fast & Lightweight - Optimized for performance with built-in caching
- 🔒 Type Safe - Full type hints and validation
- 🛡️ Error Handling - Comprehensive exception handling
- 🌙 Theme Support - Light, dark, and auto theme modes
- 📝 Logging - Debug mode with detailed logging
Installation
pip install adsoverai
Quick Start
from adsoverai import AdsOverAI
# Initialize the client
client = AdsOverAI(
api_key="your-api-key",
max_ads=3,
theme="auto"
)
# Fetch ads based on conversation context
ads = client.get_ads(
query="What are the best running shoes?",
response="Here are some great running shoe options..."
)
# Display ads
for ad in ads:
print(f"Title: {ad.title}")
print(f"Description: {ad.description}")
print(f"URL: {ad.url}")
print("---")
Convenience Function
from adsoverai import get_ads
ads = get_ads(
api_key="your-api-key",
query="best headphones",
response="Here are top-rated headphones...",
max_ads=2
)
API Reference
AdsOverAI
Main client class for the SDK.
Parameters
api_key(str, required): Your AdsOverAI API keymax_ads(int, default=3): Maximum number of ads to return (1-10)theme(str, default="auto"): Theme preference ("light", "dark", "auto")api_url(str): API endpoint URLdebug_mode(bool, default=False): Enable debug loggingtimeout(int, default=10): Request timeout in secondscache_ttl(int, default=300): Cache time-to-live in seconds
Methods
get_ads(query, response, max_ads=None, use_cache=True)
Fetch contextual ads based on conversation.
clear_cache()
Clear all cached results.
update_config(max_ads=None, theme=None, debug_mode=None)
Update client configuration.
close()
Close the session and cleanup resources.
AdResult
Data class representing an ad result.
Attributes
title(str): Ad titledescription(str): Ad descriptionurl(str): Ad URLimage_url(str, optional): Ad image URLadvertiser(str, optional): Advertiser namecta_text(str): Call-to-action textmetadata(dict): Additional metadata
Advanced Usage
Context Manager
with AdsOverAI(api_key="your-key") as client:
ads = client.get_ads(query="...", response="...")
for ad in ads:
print(ad.title)
# Session automatically closed
Error Handling
from adsoverai import AdsOverAI, AuthenticationError, APIError
try:
client = AdsOverAI(api_key="your-key")
ads = client.get_ads(query="...", response="...")
except AuthenticationError:
print("Invalid API key")
except APIError as e:
print(f"API error: {e}")
Debug Mode
client = AdsOverAI(
api_key="your-key",
debug_mode=True # Enable detailed logging
)
Cache Control
# Disable cache for a specific request
ads = client.get_ads(
query="...",
response="...",
use_cache=False
)
# Clear all cached results
client.clear_cache()
Examples
See the examples/ directory for more usage examples:
basic_usage.py- Simple usage exampleadvanced_usage.py- Advanced featuresdjango_integration.py- Django integration example
Development
Setup
git clone https://github.com/adsoverai/python-sdk.git
cd python-sdk
pip install -e ".[dev]"
Run Tests
pytest
Code Formatting
black adsoverai/ tests/
flake8 adsoverai/ tests/
mypy adsoverai/
Support
- 📧 Email: hello@adsoverai.com
- 🌐 Website: https://www.adsoverai.com
- 📚 Documentation: https://docs.adsoverai.com
- 🐛 Issues: https://github.com/adsoverai/python-sdk/issues
License
MIT © AdsOverAI Team
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
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 adsoverai-1.0.0.tar.gz.
File metadata
- Download URL: adsoverai-1.0.0.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
377fb18fd874373925d8406f6c67106d3deedce41865934427f3d911b56015e9
|
|
| MD5 |
6aec12e53e55a237efe598347750653f
|
|
| BLAKE2b-256 |
7c70a71be3c74a224dfbe4bd8d8b14f08bb7e41a1290b54aa16418af66560cdc
|
File details
Details for the file adsoverai-1.0.0-py3-none-any.whl.
File metadata
- Download URL: adsoverai-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65c476143ea8c037e5f6c891abdf33a724c6000a5589b1b8ac4251135d7ed62c
|
|
| MD5 |
2a1a4c81acb61cae7307db4f858c088f
|
|
| BLAKE2b-256 |
fb2a091f96deda2b8b084ad8c365f64053db4bcf9eee32d0a910344199a055b9
|