Skip to main content

Python SDK for AdsOverAI - Native advertising for AI chat interfaces

Project description

Python SDK for AdsOverAI - Native advertising for AI chat interfaces

PyPI version Python Support License: MIT

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 key
  • max_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 URL
  • debug_mode (bool, default=False): Enable debug logging
  • timeout (int, default=10): Request timeout in seconds
  • cache_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 title
  • description (str): Ad description
  • url (str): Ad URL
  • image_url (str, optional): Ad image URL
  • advertiser (str, optional): Advertiser name
  • cta_text (str): Call-to-action text
  • metadata (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 example
  • advanced_usage.py - Advanced features
  • django_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

License

MIT © AdsOverAI Team

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adsoverai-1.0.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

adsoverai-1.0.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

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

Hashes for adsoverai-1.0.0.tar.gz
Algorithm Hash digest
SHA256 377fb18fd874373925d8406f6c67106d3deedce41865934427f3d911b56015e9
MD5 6aec12e53e55a237efe598347750653f
BLAKE2b-256 7c70a71be3c74a224dfbe4bd8d8b14f08bb7e41a1290b54aa16418af66560cdc

See more details on using hashes here.

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

Hashes for adsoverai-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65c476143ea8c037e5f6c891abdf33a724c6000a5589b1b8ac4251135d7ed62c
MD5 2a1a4c81acb61cae7307db4f858c088f
BLAKE2b-256 fb2a091f96deda2b8b084ad8c365f64053db4bcf9eee32d0a910344199a055b9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page