Integrate the Website Rank API in Python
Your ad-placement audit needs more than a list of domains: it needs a way to retrieve traffic and rank signals, preserve the results, and decide which sites deserve further review. By the end of this guide, you can call Klazify’s traffic intelligence endpoint from Python, inspect the returned rank and audience fields, and combine those signals with website categorization in your pipeline.
Why combine website rank with classification?
A rank can help prioritize an audit, but it cannot tell you whether a placement fits your content policy. For example, a domain with substantial traffic may be worth reviewing first; a category result can then help an analyst understand what the site covers. Neither signal alone is a brand-safety verdict.
Documentation covers the traffic intelligence and categorization capabilities available through MCP and the API. Klazify’s content analysis considers webpage content rather than only metadata, and its hierarchical classification system includes IAB taxonomy mapping. That makes category data useful for translating a website’s content into an advertising or filtering policy.
The traffic endpoint and the categorization endpoint serve different purposes. Use the former to retrieve rank and audience signals; use categorization when your decision also depends on what a site is about. Content can change, so refresh classification according to your policy rather than treating a cached label as permanent.
Request traffic intelligence from Python
Send a JSON body with a URL to POST https://www.klazify.com/api/domain_traffic_intelligence. The request uses a Bearer API key. This curl example is useful for checking authentication and inspecting the actual response before connecting it to a larger job:
curl --request POST \
--url https://www.klazify.com/api/domain_traffic_intelligence \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{"url":"https://cbsnews.com"}'
Keep the key out of source control. For a local test, replace YOUR_API_KEY in the curl command; for a deployed integration, inject the key through your secret-management process.
Inspect the fields without assuming their nesting
The following Python script calls the same endpoint and looks for the requested traffic fields throughout the JSON response. It prints each matching field’s path and value, which helps you verify the response structure before writing a fixed mapping for your data warehouse. Install the requests package, set KLAZIFY_API_KEY and HTTP_TIMEOUT_SECONDS in the environment, and pass the target URL as the script’s first argument.
import json
import os
import sys
import requests
ENDPOINT = "https://www.klazify.com/api/domain_traffic_intelligence"
FIELDS = {
"global_rank",
"country_rank",
"category_rank",
"monthly_visits",
"engagement",
"traffic_sources",
"top_countries",
}
def find_fields(value, path="$"):
if isinstance(value, dict):
for key, child in value.items():
child_path = f"{path}.{key}"
if key in FIELDS:
yield child_path, child
yield from find_fields(child, child_path)
elif isinstance(value, list):
for index, child in enumerate(value):
yield from find_fields(child, f"{path}[{index}]")
def main():
if len(sys.argv) != 2:
raise SystemExit("Pass one target URL as an argument.")
try:
response = requests.post(
ENDPOINT,
headers={
"Authorization": f"Bearer {os.environ['KLAZIFY_API_KEY']}",
"Content-Type": "application/json",
},
json={"url": sys.argv[1]},
timeout=float(os.environ["HTTP_TIMEOUT_SECONDS"]),
)
response.raise_for_status()
payload = response.json()
except (requests.RequestException, ValueError) as exc:
raise SystemExit(f"Traffic intelligence request failed: {exc}") from exc
matches = list(find_fields(payload))
if not matches:
raise SystemExit("No requested traffic fields were found.")
for path, value in matches:
print(path)
print(json.dumps(value, indent=2, ensure_ascii=False))
if __name__ == "__main__":
main()
The script is an inspection tool, not a complete ingestion service. Once you have checked the documented response and the paths returned for your account, map the fields you need into your own schema. Treat missing fields and null values explicitly instead of silently converting them to zero.
Choose the signals your audit needs
| Field | How to use it | What to verify before comparison |
|---|---|---|
global_rank | Prioritize domains for a broad placement review. | Rank interpretation and the period represented. |
country_rank | Review prominence in a relevant geographic market. | Which country a value refers to and whether it is available. |
category_rank | Examine rank in a category context. | The associated category and whether it matches your comparison group. |
monthly_visits | Prioritize domains using the reported visit signal. | The reporting period and the documented meaning of the value. |
engagement | Add audience-engagement context to a review. | The nested metrics, their units, and their availability. |
traffic_sources | Inspect how traffic reaches a site. | The source breakdown and how its values are represented. |
top_countries | Check whether a site reaches markets relevant to an audit. | The country identifiers and any associated values. |
Check the current documentation for the structure, units, time periods, and definitions of the traffic values before comparing domains. In particular, do not assume a missing rank means a domain has no traffic, or that a category rank uses the same scope as a global rank.
Use categorization as a separate enrichment
Klazify’s https://www.klazify.com/api/categorize endpoint serves website classification and content categorization. The response below is the provided categorization example, not a response from the traffic intelligence request above. It illustrates the additional fields a separate categorization step can contribute to the same domain-enrichment workflow.
{
"domain": {
"categories": [
{
"confidence": 0.92,
"name": "/Computers & Electronics/Consumer Electronics",
"IAB-632-596": "Consumer Electronics/Technology & Computing/Consumer Electronics"
},
{
"confidence": 0.89,
"name": "/Internet & Telecom/Mobile & Wireless/Mobile Phones"
}
],
"social_media": null,
"logo_url": "https://klazify.s3.amazonaws.com/2110787991611585019600ed5fb1d1300.04730104.png"
},
"success": true,
"objects": {
"company": {
"url": "https://www.apple.com/",
"name": "Apple",
"city": "Cupertino",
"stateCode": "CA",
"countryCode": "US",
"employeesRange": "100K+",
"revenue": 274515000000,
"raised": null,
"tags": [
"E-commerce",
"Consumer Electronics",
"Mobile",
"B2C"
],
"tech": [
"omniture_adobe_analytics",
"atlassian_confluence",
"successfactors",
"apache_apex",
"talend",
"oracle_peoplesoft",
"salesforce",
"stripe",
"dell_boomi_atomsphere",
"gigya",
"sage_50cloud",
"quickbooks",
"webmethods",
"apache_tomcat",
"alteryx",
"tibco_rendezvous",
"atlassian_jira",
"..."
]
}
},
"domain_registration_data": {
"domain_age_date": "1987-02-19",
"domain_age_days_ago": "13026",
"domain_expiration_date": "2030-02-20",
"domain_expiration_days_left": "123"
},
"similar_domains": [
"bestbuy.com",
"icloud.com",
"microsoft.com",
"macrumors.com",
"google.com",
"samsung.com",
"twitter.com",
"hp.com",
"bhphotovideo.com",
"dell.com"
]
}
For an audit, start with success and domain.categories. Each category has a name and confidence; the first entry also includes an IAB mapping under IAB-632-596. A site can have multiple categories, so retain the list rather than assuming the first entry is the only useful label.
The example also shows why consumers must handle optional data: social_media and raised are null. Company details, logo_url, registration data, and similar_domains can support enrichment, but they are not traffic ranks. Treat the revenue and registration values as example data rather than current facts about the company.
Map results to your own policy
Keep Klazify’s original category names and any IAB mapping alongside your internal label. Maintain the mapping separately from the API response so a policy change does not require rewriting historical raw data. For instance, your review workflow could map the example’s consumer-electronics category to an internal review queue; the queue name and action are your own policy decisions.
Define what happens when several categories map to different actions. A conservative audit might send conflicting or low-confidence results to a human reviewer, while a CRM enrichment job might store all categories without taking an automatic action. Validate any confidence threshold against your own labeled examples; the sample’s confidence values are not an accuracy guarantee.
Make the integration reliable at scale
For a placement audit, build a queue of domains, normalize each hostname consistently, and deduplicate before requesting enrichment. Preserve the submitted URL as well as your normalized cache key so you can trace a result back to the original placement. If your use case depends on page-level content, keep page URLs distinct from domain-level cache entries.
Process queued requests with controlled concurrency and consult your account’s documented rate limits before increasing throughput. Batch work in your own queue; do not assume that a single API request accepts a batch of URLs. Retry transient failures with backoff, and keep failed requests visible for later investigation rather than counting them as successful classifications.
Cache results per domain with a retrieval timestamp and a refresh policy appropriate to your audit. Traffic and website content can change, so retain the original response or the fields and context needed to explain a past decision. Use a shorter or longer refresh interval based on your freshness requirements and observed workload, not a hard-coded assumption that all domains change at the same rate.
New, unreachable, or unknown domains require a separate state from known domains with a usable result. Route unknowns to a retry or review queue; do not automatically label them safe or blocked. Klazify states that failed or unreachable calls are not billed, but your pipeline should still record those outcomes so that gaps in an audit are visible.
Before joining traffic and categorization data, check that both records refer to the intended domain or URL and record when each was retrieved. Keep the two responses distinguishable: a category returned for content analysis is not, by itself, evidence of the category associated with a traffic rank. Review the documented definitions before making that join part of an automated decision.
FAQ
Can a website rank determine whether an ad placement is safe?
No. Rank and traffic signals can help prioritize review, but safety decisions need content-policy context. Use categorization as an additional input and define how your team handles uncertain or conflicting results.
What should I do when a traffic field is missing?
Store it as unavailable, retain the request outcome, and check the response and documentation before retrying. Do not substitute zero for a missing rank or visit value.
Can I cache results for multiple pages on the same domain?
A domain cache is useful for domain-level enrichment. If a policy depends on the content of individual pages, keep those page-level results separate so one page’s classification does not automatically stand in for every page on the site.
What does the Starter plan cost?
Starter is $39.99 per month with a 7-day trial. Check the current account details and documentation for the limits and terms that apply to your integration.
Ready to test the workflow? Register for a free account, run the traffic request, and inspect the response before mapping it into your audit pipeline.
Ready to use Klazify?
Start classifying websites, enriching company data, and exploring web intelligence.
Get Started Free