Python Examples
Python code examples for integrating the nofakemails email validation API.
Prerequisites
Install the requests library:
pip install requests. Set your API key: export NOFAKEMAILS_API_KEY=your_api_keySingle Email Validation
Validate a single email address with a GET request to the /v1/email/{email} endpoint.
validate_email.py
import requests
import os
response = requests.get(
'https://api.nofakemails.com/v1/email/user@example.com',
headers={'X-API-Key': os.environ['NOFAKEMAILS_API_KEY']}
)
result = response.json()
print(result)Response:
{
"email": "user@example.com",
"valid": true,
"normalized": "user@example.com",
"local_part": "user",
"alias": false,
"ascii": true,
"role": null,
"gibberish": false,
"gibberish_score": 0.12,
"domain": "example.com",
"mx": true,
"disposable": false,
"public": false,
"relay": false,
"typo": false,
"typo_suggestion": null
}See the Response Format page for a full description of every field.
Batch Validation
Validate up to 64 email addresses in a single POST request to the /v1/emails endpoint.
validate_batch.py
import requests
import os
response = requests.post(
'https://api.nofakemails.com/v1/emails',
headers={
'X-API-Key': os.environ['NOFAKEMAILS_API_KEY'],
'Content-Type': 'application/json'
},
json={
'emails': [
'user1@example.com',
'user2@gmail.com',
'test@tempmail.com'
]
}
)
batch = response.json()
# Check for partial results (timeout)
if batch['partial']:
print('Warning: some emails may not have been processed')
print(f"Total: {batch['total']}, Valid: {batch['valid_count']}")
for item in batch['results']:
if item['status'] == 'error':
print(f"{item['email']}: ERROR - {item['error']['message']}")
continue
r = item['result']
print(f"{r['email']}: valid={r['valid']}, disposable={r['disposable']}")Response:
{
"success": true,
"partial": false,
"total": 3,
"valid_count": 3,
"invalid_count": 0,
"error_count": 0,
"usage_points": 3,
"processing_time_ms": 210,
"results": [
{
"email": "user1@example.com",
"status": "success",
"result": {
"email": "user1@example.com",
"valid": true,
"normalized": "user1@example.com",
"local_part": "user1",
"alias": false,
"ascii": true,
"role": null,
"gibberish": false,
"gibberish_score": 0.11,
"domain": "example.com",
"mx": true,
"disposable": false,
"public": false,
"relay": false,
"typo": false,
"typo_suggestion": null
},
"error": null
},
{
"email": "user2@gmail.com",
"status": "success",
"result": {
"email": "user2@gmail.com",
"valid": true,
"normalized": "user2@gmail.com",
"local_part": "user2",
"alias": false,
"ascii": true,
"role": null,
"gibberish": false,
"gibberish_score": 0.10,
"domain": "gmail.com",
"mx": true,
"disposable": false,
"public": true,
"relay": false,
"typo": false,
"typo_suggestion": null
},
"error": null
},
{
"email": "test@tempmail.com",
"status": "success",
"result": {
"email": "test@tempmail.com",
"valid": true,
"normalized": "test@tempmail.com",
"local_part": "test",
"alias": false,
"ascii": true,
"role": null,
"gibberish": false,
"gibberish_score": 0.10,
"domain": "tempmail.com",
"mx": true,
"disposable": true,
"public": false,
"relay": false,
"typo": false,
"typo_suggestion": null
},
"error": null
}
]
}Each item in results contains the full validation result. See the Batch Validation response format for details on the envelope fields and per-email result structure.
Batch Limit
Maximum 64 emails per batch request. Duplicates are automatically deduplicated. See the Error Codes page if you encounter issues.