{"id":20936203,"url":"https://github.com/adzerk/adzerk-decision-sdk-python","last_synced_at":"2025-05-13T21:30:59.876Z","repository":{"id":43374207,"uuid":"239925136","full_name":"adzerk/adzerk-decision-sdk-python","owner":"adzerk","description":"Python SDK for Adzerk's Decision API","archived":false,"fork":false,"pushed_at":"2025-02-11T09:35:27.000Z","size":251,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-04-30T22:40:43.982Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adzerk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-12T04:15:48.000Z","updated_at":"2025-02-11T09:34:39.000Z","dependencies_parsed_at":"2025-02-08T07:19:54.642Z","dependency_job_id":"3f69452a-a8e1-4fb5-9ebf-50e9b4796868","html_url":"https://github.com/adzerk/adzerk-decision-sdk-python","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adzerk%2Fadzerk-decision-sdk-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adzerk%2Fadzerk-decision-sdk-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adzerk%2Fadzerk-decision-sdk-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adzerk%2Fadzerk-decision-sdk-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adzerk","download_url":"https://codeload.github.com/adzerk/adzerk-decision-sdk-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254030885,"owners_count":22002666,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T22:18:21.665Z","updated_at":"2025-05-13T21:30:58.459Z","avatar_url":"https://github.com/adzerk.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Adzerk Python Decision SDK\n\nPython Software Development Kit for Adzerk Decision \u0026 UserDB APIs\n\n## Installation\n\nRequires [Python 3.7.6](https://en.wikipedia.org/wiki/History_of_Python#Table_of_versions) or higher.\n\n[PyPI Package](https://pypi.org/project/adzerk-decision-sdk/)\n\n```shell\npip install adzerk-decision-sdk\n```\n\nOr add to your `requirements.txt` file:\n\n```\nadzerk-decision-sdk===1.0.0b3\n```\n\n## Examples\n\n### API Credentials \u0026 Required IDs\n\n- Network ID: Log into [Adzerk UI](https://app.adzerk.com/) \u0026 use the \"circle-i\" help menu in upper right corner to find Network ID. Required for all SDK operations.\n- Site ID: Go to [Manage Sites page](https://app.adzerk.com/#!/sites/) to find site IDs. Required when fetching an ad decision.\n- Ad Type ID: Go to [Ad Sizes page](https://app.adzerk.com/#!/ad-sizes/) to find Ad Type IDs. Required when fetching an ad decision.\n- API Key: Go to [API Keys page](https://app.adzerk.com/#!/api-keys/) find active API keys. Required when writing to UserDB.\n- User Key: UserDB IDs are [specified or generated for each user](https://dev.adzerk.com/reference/userdb#passing-the-userkey).\n\n### Fetching an Ad Decision\n\n```python\nimport adzerk_decision_sdk\n\n# Demo network, site, and ad type IDs; find your own via the Adzerk UI!\nclient = adzerk_decision_sdk.Client(23, site_id=667480)\n\nrequest = {\n  \"placements\": [{\"adTypes\": [5]}],\n  \"user\": {\"key\": \"abc\"},\n  \"keywords\": [\"keyword1\", \"keyword2\"],\n}\n\nresponse = client.decisions.get(request)\nprint(response)\n```\n\n### Recording Impression \u0026 Clicks\n\nUse with the fetch ad example above.\n\n```python\n# Impression pixel; fire when user sees the ad\nclient.pixels.fire(decision.impression_url)\n\n# Click pixel; fire when user clicks on the ad\n# status: HTTP status code\n# location: click target URL\nstatus, location = client.pixels.fire(decision.click_url)\n```\n\n### UserDB: Reading User Record\n\n```python\nimport adzerk_decision_sdk\n\n# Demo network ID; find your own via the Adzerk UI!\nclient = adzerk_decision_sdk.Client(23)\nrecord = client.user_db.read(\"abc\")\nprint(record)\n```\n\n### UserDB: Setting Custom Properties\n\n```python\nimport adzerk_decision_sdk\n\n# Demo network ID; find your own via the Adzerk UI!\nclient = adzerk_decision_sdk.Client(23)\n\nprops = {\n  \"favoriteColor\": \"blue\",\n  \"favoriteNumber\": 42,\n  \"favoriteFoods\": [\"strawberries\", \"chocolate\"],\n}\n\nclient.user_db.set_custom_properties(\"abc\", props)\n```\n\n### UserDB: Forgetting User Record\n\n```python\nimport adzerk_decision_sdk\nimport os\n\n# Demo network ID and API key; find your own via the Adzerk UI!\napi_key = os.environ.get(\"ADZERK_API_KEY\")\nclient = adzerk_decision_sdk.Client(23, api_key=api_key)\nclient.user_db.forget(\"abc\")\n```\n\n### Decision Explainer\n\nThe Decision Explainer returns information on a Decision API request explaining why each candidate ad was or was not chosen. \n\n```python\nimport adzerk_decision_sdk\nimport os\n\n# Demo network, site, and ad type IDs; find your own via the Adzerk UI!\napi_key = os.environ.get(\"ADZERK_API_KEY\")\nclient = adzerk_decision_sdk.Client(23, site_id=667480)\n\nrequest = {\n  \"placements\": [{\"adTypes\": [5]}],\n  \"user\": {\"key\": \"abc\"},\n  \"keywords\": [\"keyword1\", \"keyword2\"],\n}\n\noptions = {\n  \"include_explanation\": True,\n  \"api_key\": api_key\n}\n\nresponse = client.decisions.get(request, **options)\nprint(response)\n```\n\nThe response returns a decision object with placement, buckets, rtb logs, and result information.\n``` json\n{\n  \"div0\": {\n    \"placement\": {},\n    \"buckets\": [],\n    \"rtb_log\": [],\n    \"results\": []\n  }\n}\n```\nThe \"placement\" object represents a decision in which an ad may be served. A Explainer Request can have multiple placements in the request.\nThe \"buckets\" array contains channel and priority information.\nThe \"rtb_logs\" array contains information about Real Time Bidding.\nThe \"results\" array contains the list of candidate ads that did and did not serve, along with a brief explanation.\n\n### Logging\n\nThe Adzerk Decision SDK uses the built-in Python logging mechanism to capture log data. By default, warning and error messages will be sent to `stderr` even if no logger is configured.\n\nTo configure different log levels for the SDK, you first have to configure logging for your application. A simple configuration that enables informational level logging application wide would be:\n\n```python\nimport logging\n\n# This represents your logging framework being initialized, usually by Flask or\n# Django, etc.  This will create a base handler that will output to sys.stderr,\n# but you can override the config in several ways:\n# https://docs.python.org/3/library/logging.html\nlogging.basicConfig()\n\n# Set both the client \u0026 rest loggers to INFO to avoid over-the-wire debug logs.\nlogging.getLogger(\"adzerk_decision_sdk.client\").setLevel(logging.INFO)\nlogging.getLogger(\"adzerk_decision_sdk.rest\").setLevel(logging.INFO)\n\n# Demo network ID; find your own via the Adzerk UI!\nclient = Client(23)\n```\n\nAs a convenience, you can *optionally* specify a `logger_file` parameter to the Client and it will create an _additional_ Python log handler that will send Adzerk Decision SDK logs to the named file.  A few tips:\n\n1. Depending on your app logging config this might create *duplicate logs* between this file and your normal logging destination.  \n2. It's probably a good idea to use the `logging.DEBUG` level in this case to get all the over-the-wire debug info.\n3. You can also pass in a `logger_format` parameter to control how the logs will be displayed.  This requires the `logger_file` parameter too.  More info on how to format messages: https://docs.python.org/3/library/logging.html#logrecord-attributes\n\n```python\n# OPTIONAL use of an ADDITIONAL logger file for SDK messages only;\n# logger_format is optional but ignored unless logger_file is present;\n# Demo network ID; find your own via the Adzerk UI!\nclient = Client(23, logger_file=\"adzerk-python.log\", logger_format=\"%(asctime)s %(name)s %(levelname)s %(message)s\")\n```\n\n## Documentation\n\n- [Adzerk API Documentation](https://dev.adzerk.com/reference)\n- [Adzerk User \u0026 Developer Documentation](https://dev.adzerk.com/docs)\n\n## Contributing\n\n### Reporting Issues\n\n- For bug fixes and improvements to this SDK please use Github to [open an issue](https://github.com/adzerk/adzerk-decision-sdk-python/issues) or send us a [pull request](https://github.com/adzerk/adzerk-decision-sdk-python/pulls).\n- For questions or issues regarding Adzerk functionality, please [contact Adzerk support](https://adzerk.com/help/).\n\n### Building\n\nTo install dependencies and run the builds associated with this SDK, please use:\n\n```\npip install flake8\npip install --requirement requirements.txt\nflake8 . --count --select=E9,F63,F7,F82 --show-source --statistics\nflake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics\npython setup.py sdist bdist_wheel\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadzerk%2Fadzerk-decision-sdk-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadzerk%2Fadzerk-decision-sdk-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadzerk%2Fadzerk-decision-sdk-python/lists"}