Integrate the Domain Age API in Python
A signup arrives with a company website, and your Python service needs to know whether the domain was recently registered or is approaching expiration. With Klazify, you can request registration data for that domain, read the returned age and expiration fields, and route incomplete results for review rather than treating them as a verdict.
Why use Klazify for domain-age checks?
Documentation describes Klazify’s domain intelligence capabilities, including a dedicated domain-expiration endpoint. A registration-date lookup can add useful context to signup enrichment, security triage, or a domain portfolio audit without requiring your application to maintain registration data itself.
Klazify also offers website classification based on content analysis, with a hierarchical taxonomy and IAB mapping. That is useful when a workflow needs both registration context and an understanding of what a website is about, including sites in different languages. The Python integration below focuses on the age endpoint; it does not assume that an age lookup also classifies a site.
Domain age is a signal, not proof of legitimacy. A newly registered domain is not necessarily malicious, and an older domain is not necessarily safe. Combine registration data with your own review criteria before blocking a signup, changing an ad-placement policy, or escalating an investigation.
Send a domain-age request
The endpoint accepts a JSON object containing a URL. Authenticate with a Bearer token and send the request as a POST:
curl -X POST 'https://www.klazify.com/api/domain_expiration' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"url":"https://cbsnews.com"}'
Replace YOUR_API_KEY with your API key. The URL is the site to look up, not a callback address; keep the key on the server rather than exposing it in browser code or client-side logs.
The registration fields to look for are domain_age_date, domain_age_days_ago, domain_expiration_date, and domain_expiration_days_left. The date fields represent registration and expiration dates; the other two values express elapsed or remaining time in days.
For a signup workflow, store the result alongside your internal signup record and the time you fetched it. A review rule can then use the returned age as one input, while keeping a missing or failed lookup separate from a completed lookup.
Understand the registration fields
The following Klazify example shows registration data within a broader domain response. It also illustrates categorization, company, and related-domain fields; it is not a promise that every domain-age request will return all of those fields.
{
"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"
]
}
In this example, domain_registration_data contains the four registration fields. The day counts are JSON strings, so convert them to integers before applying numeric rules. The dates are calendar dates, not timestamps with a time or timezone.
Use the date and day-count values as returned rather than assuming the example’s counts describe the current day. Day counts change over time, and an expiration date can change when a registration is renewed. Record when you fetched a response so downstream users know how fresh the values are.
| Field | Interpretation | Example use |
|---|---|---|
domain_age_date | Domain registration date | Display the date in a signup review. |
domain_age_days_ago | Elapsed age in days | Compare with an internal review threshold. |
domain_expiration_date | Domain expiration date | Show the date in a portfolio audit. |
domain_expiration_days_left | Remaining time in days | Queue a domain for renewal review. |
The category entries in the example are separate content signals. Their name values describe categories, while an IAB mapping appears on one entry; neither tells you how old the domain is. Likewise, the example’s success value and company fields should not be substituted for checking whether the registration fields you need are present.
Call the endpoint from Python
This example uses the requests package. Set KL_AZ_API_KEY in your environment, save the code as domain_age.py, and pass the website URL as the command-line argument.
import os
import sys
import requests
ENDPOINT = "https://www.klazify.com/api/domain_expiration"
def optional_days(value):
if value is None or isinstance(value, bool):
return None
try:
return int(value)
except (TypeError, ValueError):
return None
def lookup_domain(url, api_key):
response = requests.post(
ENDPOINT,
headers={
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
},
json={"url": url},
timeout=15,
)
response.raise_for_status()
payload = response.json()
if not isinstance(payload, dict):
raise ValueError("Expected a JSON object")
if payload.get("success") is False:
raise ValueError("Lookup did not succeed")
# The broader response example nests registration data here.
# Also accept registration fields at the top level.
registration = payload.get("domain_registration_data", payload)
if not isinstance(registration, dict):
raise ValueError("Registration data is unavailable")
return {
"domain_age_date": registration.get("domain_age_date"),
"domain_age_days_ago": optional_days(
registration.get("domain_age_days_ago")
),
"domain_expiration_date": registration.get("domain_expiration_date"),
"domain_expiration_days_left": optional_days(
registration.get("domain_expiration_days_left")
),
}
def main():
api_key = os.environ.get("KL_AZ_API_KEY")
if not api_key or len(sys.argv) != 2:
sys.exit("Set KL_AZ_API_KEY and pass one website URL.")
try:
result = lookup_domain(sys.argv[1], api_key)
except (requests.RequestException, ValueError) as exc:
sys.exit(f"Domain lookup failed: {exc}")
for field, value in result.items():
print(f"{field}: {value if value is not None else 'unknown'}")
if result["domain_age_days_ago"] is None:
print("Review: domain age is unavailable.")
else:
print("Review: apply your domain-age policy to the returned value.")
if __name__ == "__main__":
main()
Install the dependency with pip install requests, then run python domain_age.py "$DOMAIN_URL" after setting both environment variables. The URL variable should contain the site you want to check; it is not sent until the script makes the request.
The script checks the HTTP response, parses JSON, and converts available day counts to integers. It accepts registration fields in the nested structure shown above or at the top level, while treating absent or non-numeric day values as unknown. This makes the application’s decision point explicit: an unknown age is not the same as a new domain.
For production, replace the printed review message with a result written to your signup or enrichment pipeline. Keep the raw response only if your data-retention policy permits it, and avoid logging the authorization header. Handle timeout, HTTP, and parsing failures as failed lookups rather than silently assigning a default age.
Operate the lookup in a domain pipeline
Normalize and deduplicate inputs before scheduling requests. For a domain-level cache, use a consistent domain key and retain the original submitted URL separately if your application needs it for audit. Take care not to merge distinct hosts unless that matches your business rules.
Cache successful registration results per domain with a fetch timestamp and a refresh policy appropriate to your workflow. Expiration data deserves particular attention because a domain can be renewed. If you display a cached day count, label it with its retrieval time rather than presenting it as an always-current value.
For large input sets, put lookups in a queue and control concurrency instead of issuing an unbounded burst. Check the applicable plan and current documentation for rate limits; this integration does not assume a batch endpoint or a specific request allowance. Retry transient failures with backoff, and send persistent failures to an operational review queue.
Unknown and newly encountered domains need an explicit path. A missing field, unreachable call, or unsuccessful response means the lookup did not provide enough information for that field; it does not establish an age of zero. You can retry later, request human review, or continue with other signals according to your organization’s risk tolerance.
If your pipeline also uses Klazify categorization, maintain a versioned mapping from returned category names or IAB values to your own labels. Preserve the original category and confidence alongside the mapped label for audit, and route unmapped categories for review. A category decision and an age decision should remain independently explainable: one describes content, while the other describes registration timing.
Klazify lists Starter at $39.99 per month with a seven-day trial. Failed or unreachable calls are not billed, but you should still monitor failures: repeated errors delay enrichment and can leave your review queue without the data it needs.
FAQ
Does domain age tell me when a company was founded?
No. The registration date describes the domain, not necessarily the company or the age of its website content. Use it as domain context rather than a company founding date.
Can I block a signup solely because its domain is new?
You can define that policy in your application, but age alone is not evidence of abuse. A review or additional verification step avoids treating every new registration as a threat.
What should I do if a day count is missing?
Store it as unknown and keep it out of numeric comparisons. Retry or route the record for review according to your workflow; do not replace a missing value with zero.
How often should I refresh cached results?
Choose a refresh interval based on the consequence of stale data and your request volume. Record the fetch time, and refresh before decisions that require current expiration information.
To try the integration, Register for a free account and create your API key. If you are also exploring tool-based workflows, see Klazify’s MCP page.
Ready to use Klazify?
Start classifying websites, enriching company data, and exploring web intelligence.
Get Started Free