Lightweight Python client for the ChatAds affiliate scoring API
Project description
ChatAds Python SDK
A tiny, dependency-light wrapper around the ChatAds /v1/chatads-script endpoint. It mirrors the response payloads returned by the FastAPI service so you can drop it into CLIs, serverless functions, or orchestration tools.
Installation
pip install .
(Or build/upload to your internal index as needed.)
Quickstart
from chatads_sdk import ChatAdsClient, FunctionItemPayload
client = ChatAdsClient(
api_key="YOUR_X_API_KEY",
base_url="https://<your-chatads-domain>",
raise_on_failure=True, # Treat success=False payloads as exceptions
max_retries=2, # Optional automatic retries for 429/5xx responses
retry_backoff_factor=0.75, # Exponential backoff multiplier
)
payload = FunctionItemPayload(
message="Looking for a CRM to close more deals",
ip="1.2.3.4",
user_agent="Mozilla/5.0",
)
result = client.analyze(payload)
if result.success:
print(result.data.ad)
else:
print(result.error.code, result.error.message)
Error Handling
Non-2xx responses raise ChatAdsAPIError and include the parsed error payload plus the original HTTP status code so you can branch on quota/validation failures. Set raise_on_failure=True if you want 200 responses with success=false to raise the same exception class.
Notes
- Retries are opt-in. Provide
max_retries>0to automatically retry transport errors and retryable status codes. The client honorsRetry-Afterheaders and falls back to exponential backoff. FunctionItemPayloadmatches the server-sideFunctionItempydantic model. Keyword arguments passed toChatAdsClient.analyze_message()accept either snake_case (user_agent) or camelCase (userAgent) keys.- Reserved payload keys (e.g.,
message,pageUrl,userAgent) cannot be overridden throughextra_fields; doing so raisesValueErrorto prevent silent mutations.
CLI Smoke Test
For a super-quick check, edit the config block at the top of python_sdk/run_sdk_smoke.py (or set the
CHATADS_* env vars) and run:
PYTHONPATH=python_sdk python python_sdk/run_sdk_smoke.py
It prints the raw JSON response or surfaces a ChatAdsAPIError with status/error fields so you can see
exactly what the API returned.
API_KEYandMESSAGEare the only required values. LeaveCALLER_IP,USER_AGENT, orCHATADS_EXTRA_FIELDSblank to omit them from the request.
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 chatads_sdk-0.1.0.tar.gz.
File metadata
- Download URL: chatads_sdk-0.1.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef61f3071eef84856b6f34aa76a7e46ade237af4575e463bbebdc2a906e2114e
|
|
| MD5 |
149f49132b3d83e36eeafb0ed98b1101
|
|
| BLAKE2b-256 |
7e6cb209e3ce08c2dda603e627f378e965efab0fd9ef275e71ee05db7c1a8d95
|
File details
Details for the file chatads_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: chatads_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39cf0b23f93d7345ae5b76c0566d7608b77e7253518a8ccebe388b3c4faa9799
|
|
| MD5 |
fb83124e997ab7dc38f3d073419cc647
|
|
| BLAKE2b-256 |
1533d34c0b13d6e8b2b1735ed2304bef6cd3e717e889d6aaef8feaaa8f16eabc
|