Python Decision SDK
Python Software Development Kit for Kevel Decision & UserDB APIs
Installation
Requires Python 3.7.6 or higher.
pip install adzerk-decision-sdk
Or add to your requirements.txt
file:
adzerk-decision-sdk===1.0.0b3
Examples
Fetching an Ad Decision
import adzerk_decision_sdk
# Demo network, site, and ad type IDs; find your own via the Adzerk UI!
client = adzerk_decision_sdk.Client(23, site_id=667480)
request = {
"placements": [{"adTypes": [5]}],
"user": {"key": "abc"},
"keywords": ["keyword1", "keyword2"],
}
response = client.decisions.get(request)
print(response)
Recording Impression & Clicks
Use with the fetch ad example above.
# Impression pixel; fire when user sees the ad
client.pixels.fire(decision.impression_url)
# Click pixel; fire when user clicks on the ad
# status: HTTP status code
# location: click target URL
status, location = client.pixels.fire(decision.click_url)
UserDB: Reading User Record
import adzerk_decision_sdk
# Demo network ID; find your own via the Adzerk UI!
client = adzerk_decision_sdk.Client(23)
record = client.user_db.read("abc")
print(record)
UserDB: Setting Custom Properties
import adzerk_decision_sdk
# Demo network ID; find your own via the Adzerk UI!
client = adzerk_decision_sdk.Client(23)
props = {
"favoriteColor": "blue",
"favoriteNumber": 42,
"favoriteFoods": ["strawberries", "chocolate"],
}
client.user_db.set_custom_properties("abc", props)
UserDB: Forgetting User Record
import adzerk_decision_sdk
# Demo network ID and API key; find your own via the Adzerk UI!
client = adzerk_decision_sdk.Client(23, api_key="YOUR_API_KEY")
client.user_db.forget("abc")
Decision Explainer
import adzerk_decision_sdk
import os
# Demo network, site, and ad type IDs; find your own via the Adzerk UI!
api_key = os.environ.get("ADZERK_API_KEY")
client = adzerk_decision_sdk.Client(23, site_id=667480)
request = {
"placements": [{"adTypes": [5]}],
"user": {"key": "abc"},
"keywords": ["keyword1", "keyword2"],
}
options = {
"include_explanation": True,
"api_key": api_key
}
response = client.decisions.get(request, **options)
print(response)
Updated 7 months ago