How to Get a Website's Global Rank in Python
You need to programmatically fetch a website’s global rank in Python so you can enforce traffic thresholds (e.g., block long-tail domains in an ad pipeline), enrich signups with traffic context in a CRM, or audit where your ads run. By the end of this guide, you’ll call a single API to retrieve global and country ranks plus traffic and engagement signals, then plug the results into your data flow with caching, batching, and error handling patterns that hold up at scale.
Why Klazify is a strong fit for fetching traffic ranks and using them in production
When you add traffic context to your domain data, you typically also need accurate categorization for filtering and enrichment. Klazify combines both in one API: you can retrieve global rank, country/category ranks, and also map the same domain to IAB categories for downstream brand safety or analytics rules.
- Accurate website categorization using AI: Beyond traffic ranks, Klazify analyzes on-site content, letting you anchor thresholds to industry-appropriate expectations (e.g., different rank bands per IAB category).
- Global coverage: Ranks and categories for sites in multiple languages, allowing you to evaluate international traffic consistently.
- Real-time classification: Fresh content analysis minimizes stale labels when pairing rank signals with categories or logo/company metadata.
- Industry-level categories: IAB taxonomy support ensures your traffic screens work with standard advertising and brand-safety workflows.
- Simple API integration: A clean REST interface for both traffic intelligence and categorization, easy to wire into Python jobs and data pipelines.
- Compliance and filtering: Combine ranks with categories to quickly detect, filter, or whitelist sites relevant to your use case.
The result: you fetch a website’s global rank alongside category and company context, then enforce rules like “only serve ads to sites ranked under X in these categories” or “flag new signups from high-traffic domains for SDR priority.”
What the traffic intelligence endpoint returns and how to use it
Use Klazify’s domain traffic intelligence endpoint to obtain the following fields for a given URL or domain:
- global_rank: a site’s relative position worldwide.
- country_rank: a site’s position within a specific country.
- category_rank: a site’s position within its topical category.
- monthly_visits: volume estimate you can use to bucket sites by scale.
- engagement: a bundle of engagement metrics you can use to gauge visit quality.
- traffic_sources: distribution of traffic by channel to distinguish organic vs. referral-heavy properties.
- top_countries: main geographies contributing to traffic, useful for geo-targeting and compliance.
These fields help you:
- Set minimum traffic thresholds in ad tech or affiliate programs (global_rank and monthly_visits).
- Apply geo-aware logic for campaigns or compliance (top_countries, country_rank).
- Compare a site to its peers inside a niche (category_rank).
- Detect anomalous sources (traffic_sources) or low-quality traffic patterns (engagement).
Call the traffic intelligence endpoint (cURL)
Send a POST request with your Bearer token and a JSON payload containing the URL. Failed or unreachable calls are not billed, which is helpful during integration and retry design.
curl -X POST "https://www.klazify.com/api/domain_traffic_intelligence" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://cbsnews.com"}'
Response time is suitable for synchronous enrichment, but for large batches you’ll typically parallelize requests and cache per domain. See the Documentation for up-to-date details on fields and usage.
Python example: fetch global_rank and related fields
The snippet below demonstrates a simple Python call, minimal error handling, and how to read the relevant fields. Integrate it into a worker, function, or ETL step.
import os
import json
import time
import requests
API_KEY = os.environ.get("KLAZIFY_API_KEY", "YOUR_API_KEY")
ENDPOINT = "https://www.klazify.com/api/domain_traffic_intelligence"
def get_domain_rank(url):
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Accept": "application/json",
}
payload = {"url": url}
resp = requests.post(ENDPOINT, headers=headers, json=payload, timeout=20)
# If the target is unreachable or the call fails, Klazify does not bill the request.
resp.raise_for_status()
return resp.json()
def summarize_rank(data):
# Defensive parsing: fields may be absent for brand-new or low-signal domains.
global_rank = data.get("global_rank")
country_rank = data.get("country_rank")
category_rank = data.get("category_rank")
monthly_visits = data.get("monthly_visits")
engagement = data.get("engagement") # Often includes core engagement quality metrics
traffic_sources = data.get("traffic_sources")
top_countries = data.get("top_countries")
return {
"global_rank": global_rank,
"country_rank": country_rank,
"category_rank": category_rank,
"monthly_visits": monthly_visits,
"engagement": engagement,
"traffic_sources": traffic_sources,
"top_countries": top_countries
}
if __name__ == "__main__":
domain = "https://example.com"
try:
data = get_domain_rank(domain)
summary = summarize_rank(data)
print(json.dumps(summary, indent=2))
# Example usage:
# - Block if global_rank is None or too low
# - Whitelist if category_rank is strong in your target niche
# - Route leads if monthly_visits crosses your SDR threshold
except requests.HTTPError as e:
# Retry/backoff logic for transient network issues
print(f"HTTP error: {e}")
time.sleep(2)
except requests.RequestException as e:
print(f"Request error: {e}")
Store the raw JSON for auditing and reprocessing; persist a parsed summary for fast lookups in downstream services.
Using categorization and company data alongside rank
Many pipelines pair traffic signals with categorization and company data. For example, you might require a minimum global_rank and also restrict to certain IAB categories for brand safety. The categorization endpoint returns categories, social, logo, company details, and related signals you can combine with rank-based rules.
Below is an official sample response you can expect from a categorization call. Use the categories array for IAB mapping and the logo/company information for UI, analytics, or lead enrichment.
{
"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"
]
}
How to use these fields:
- domain.categories: Map to your internal taxonomy or use directly for IAB-based filtering. The confidence score helps with override logic.
- domain.logo_url: Display in admin tools and reports that include rank and category context.
- objects.company.*: Enrich CRMs with name, location, and tags alongside traffic ranks.
- domain_registration_data: Consider domain age when interpreting rank/engagement for new sites.
- similar_domains: Build discovery or competitive intelligence lists and pre-fetch their ranks.
End-to-end path: from a URL to actionable rank logic
1) Normalize and cache the domain
- Normalize input to an eTLD+1 (e.g., sub.example.co.uk → example.co.uk) for caching and deduplication.
- Cache by domain for a TTL that fits your freshness needs; traffic patterns don’t need minute-by-minute refresh for most workflows.
2) Fetch traffic rank and engagement
- Call domain_traffic_intelligence, read global_rank, country_rank, category_rank, monthly_visits, engagement, traffic_sources, and top_countries.
- If the domain is new or low-signal, some fields may be missing; treat missing values as “unknown” and queue for later re-checks.
3) Fetch categorization (optional but recommended)
- Call the categorization endpoint to get IAB categories, logo, and company info.
- Use categories to set rank thresholds per vertical (e.g., more lenient ranks for niche B2B categories).
4) Apply rules in your pipeline
- Ad tech: Permit inventory when global_rank is within your target band and categories match your allowed list.
- CRM enrichment: Flag signups from domains with strong category_rank or high monthly_visits for manual follow-up.
- Analytics: Segment partner performance by top_countries or traffic_sources composition.
A quick comparison of rank-related fields
| Field | What it tells you | Common usage | Notes |
|---|---|---|---|
| global_rank | Worldwide relative ranking | Gatekeeping; global thresholds for ads and partnerships | Lower is stronger when interpreting ranks |
| country_rank | Ranking within a specific country | Geo-targeting and compliance checks | Use with top_countries to align markets |
| category_rank | Ranking within the site’s topic | Peer comparisons; niche discovery | Great for shortlists of vertical leaders |
| monthly_visits | Estimated visit volume | Lead prioritization; inventory tiering | Set buckets (e.g., small/medium/large) |
| engagement | Quality of visits | Filter weak/referral-heavy sites | Supports quality thresholds |
| traffic_sources | Share by channel | Detect anomalies; campaign alignment | Balance across organic, direct, referral, etc. |
| top_countries | Key geographies | Geo routing; regional reporting | Combine with localization decisions |
Batching, rate limits, retries, and timeouts
For small lookups (e.g., back-office UI), synchronous calls are fine. For enrichment at scale:
- Batch by queueing domains and processing in worker pools to respect rate limits. If you expect bursts, use exponential backoff on 429/5xx responses and circuit-breakers to protect upstream services.
- Cache aggressively by domain with a TTL aligned to your SLA for freshness. Many teams refresh ranks daily or weekly, then override on-demand for priority domains.
- Use idempotent task keys so retries do not trigger duplicate processing downstream.
- Log the status code and a short error reason for observability, especially for unreachable targets (not billed).
Handling unknown or new domains
Some domains will be new or have sparse signals. Recommended patterns:
- Return a neutral default in your rule engine when global_rank or monthly_visits are absent, and queue a refresh.
- Use domain_registration_data (from categorization) to interpret newness; younger domains may stabilize in rank later.
- Add a “pending classification” state in your UI and prevent irreversible decisions until data is available.
Mapping to your own taxonomy
If you already maintain internal verticals, use the IAB mapping from categorization to translate Klazify categories into your schema. Typical approaches:
- Direct mapping: For each IAB code/name, store a single internal category ID.
- Weighted mapping: Use confidence to prefer primary categories when multiple are present.
- Overrides: Allow analysts to override mappings for edge cases and persist those rules.
This lets you compare category_rank against peer sets you manage internally, while still aligning with IAB standards where helpful.
Storing and serving results
- Key by normalized domain (eTLD+1) and store both the raw JSON and a flattened summary for quick reads.
- Version records to track when a domain’s rank shifts. This is useful for audits or partner reviews.
- Propagate a “last_updated” timestamp to every consumer service to prevent stale decisions.
Security and governance
- Keep your API key in a secret manager or environment variable; rotate on a schedule.
- Implement per-tenant caching if you serve many customers from a common backend, so usage accounting and privacy remain clear.
- Audit access to enrichment data if you surface it in dashboards shared across teams.
Pricing, trial, and where to start
The Starter plan is $39.99/month with a 7-day trial. Because failed or unreachable calls are not billed, you can integrate confidently with retries and health checks during your build-out. Create a free account to get an API key and start testing your rank filters in Python.
Register to get your API key and start retrieving ranks. Refer to the Documentation for endpoint details and examples, and explore integration patterns via MCP.
FAQ
-
Which endpoint gives me global_rank in Python?
Use the POST https://www.klazify.com/api/domain_traffic_intelligence endpoint with a JSON payload containing {"url": "..."} and a Bearer token. -
Can I rely only on global_rank to filter sites?
You can, but it’s more robust to combine global_rank with category_rank, monthly_visits, engagement, and IAB categories for context-aware rules. -
How should I handle missing fields for a domain?
Treat them as unknown, apply a neutral decision, and schedule a re-check. New or low-signal domains may populate over time. -
What’s the best way to cache results?
Cache by normalized domain (eTLD+1) with a TTL that matches your freshness goals (e.g., daily). Keep the raw JSON and a flattened summary for fast reads. -
Do failed or unreachable requests count against my usage?
No—failed or unreachable calls are not billed, which simplifies retry strategies during integration and production operations.
Ready to enrich your pipeline with traffic ranks and categories? Create your account now and start testing with your own domains: Register. For implementation details, examples, and field references, check the Documentation and integration options via MCP.
Ready to use Klazify?
Start classifying websites, enriching company data, and exploring web intelligence.
Get Started Free