Skip to main content

Official Python SDK for Kawaa Email Verification API

Project description

Kawaa Python SDK

Python SDK source for Kawaa Email Verification API.

Features

  • Verify single emails or batch lists
  • Automatic retry with exponential backoff
  • Both sync and async clients
  • Full type hints for IDE support
  • Webhook signature verification
  • Framework integrations (Flask, FastAPI)

Local Development

Package registry availability is not guaranteed until the SDK publish process is verified.

python3 -m pip install -e .

Quick Start

from kawaa import Kawaa

# Create client with your API key
client = Kawaa("your-api-key")

# Verify a single email
result = client.verify("john@example.com")
print(f"Status: {result.status}")  # valid, invalid, risky, unknown, spam_trap, disposable, role, catch_all (or pending on sync timeout)
print(f"Score: {result.score}")     # 0-100 quality score

if result.is_valid:
    print("Email is valid!")

if result.flags.disposable:
    print("Warning: disposable email")

Single Email Verification

from kawaa import Kawaa

client = Kawaa("your-api-key")

# Basic verification
result = client.verify("user@example.com")

# Access results
print(f"Email: {result.email}")
print(f"Status: {result.status}")      # VerificationStatus enum
print(f"Score: {result.score}")        # 0-100
print(f"Disposable: {result.flags.disposable}")
print(f"Role account: {result.flags.role}")
print(f"Free provider: {result.flags.free_provider}")
print(f"Catch-all: {result.flags.catch_all}")

# AI-suggested correction (if typo detected)
if result.suggestion:
    print(f"Did you mean: {result.suggestion}")

# Customize verification options (the real API options)
result = client.verify(
    "user@example.com",
    deep_verify=True,     # Deep (SMTP-level) verification
    include_ai=True,      # AI typo detection / catch-all confidence
    enrich=False,         # Opt-in data enrichment (name, gender, country)
    timeout_ms=24000,     # Server-side verification/poll budget (ms)
    skip_cache=False,     # Bypass the verification cache
)

Batch Verification

For verifying many emails at once:

from kawaa import Kawaa

client = Kawaa("your-api-key")

emails = [
    "john@example.com",
    "jane@example.com",
    "invalid@",
    "john@example.com",  # duplicate - will be removed
]

# Start batch job
job = client.verify_batch(emails)
print(f"Job ID: {job.job_id}")
print(f"Duplicates removed: {job.duplicates_removed}")
print(f"Credits used: {job.credits_used}")

# Poll for completion
result = client.wait_for_job(job.job_id, timeout=300)
print(f"Valid: {result.valid_count}")
print(f"Invalid: {result.invalid_count}")
print(f"Risky: {result.risky_count}")

# Access individual results
for r in result.results:
    print(f"{r.email}: {r.status} (score: {r.score})")

One-liner with wait

# Start job and wait for completion in one call
result = client.verify_batch_and_wait(
    emails,
    poll_interval=2.0,  # Check every 2 seconds
    timeout=600,        # Wait up to 10 minutes
)

Using webhooks

# Get notified when job completes
job = client.verify_batch(
    emails,
    webhook_url="https://your-server.com/webhook",
    webhook_secret="your-secret",  # Optional, for signature verification
)

Download Results

# Download as JSON
results = client.download_results(job_id)
for r in results.results:
    print(f"{r.email}: {r.status}")

# Download as CSV
csv_data = client.download_results(job_id, format="csv")
print(csv_data)  # CSV string

# For large result sets, you'll get a presigned URL
if results.download_url:
    print(f"Download from: {results.download_url}")

Async Client

For async/await support:

import asyncio
from kawaa import AsyncKawaa

async def main():
    async with AsyncKawaa("your-api-key") as client:
        # Single verification
        result = await client.verify("user@example.com")
        print(f"Status: {result.status}")

        # Batch verification
        job = await client.verify_batch(emails)
        result = await client.wait_for_job(job.job_id)
        print(f"Valid: {result.valid_count}")

asyncio.run(main())

Webhook Handling

Verify webhook signatures and parse events:

from kawaa.webhooks import parse_webhook, verify_signature

# Verify signature
is_valid = verify_signature(
    payload=request.body,
    signature=request.headers["X-Kawaa-Signature"],
    secret="your-webhook-secret",
)

# Parse webhook event
event = parse_webhook(
    payload=request.body,
    signature=request.headers.get("X-Kawaa-Signature"),
    secret="your-webhook-secret",  # Optional
)

print(f"Job {event.job_id} completed!")
print(f"Valid: {event.valid}, Invalid: {event.invalid}")
print(f"Download: {event.download_url}")

Flask Integration

from flask import Flask
from kawaa.webhooks import flask_webhook_handler

app = Flask(__name__)

@app.route("/webhook", methods=["POST"])
@flask_webhook_handler("your-webhook-secret")
def handle_webhook(event):
    print(f"Job {event.job_id} completed!")
    return "", 200

FastAPI Integration

from fastapi import FastAPI, Depends
from kawaa.webhooks import fastapi_webhook_handler, WebhookEvent

app = FastAPI()
get_event = fastapi_webhook_handler("your-webhook-secret")

@app.post("/webhook")
async def handle_webhook(event: WebhookEvent = Depends(get_event)):
    print(f"Job {event.job_id} completed!")
    return {"status": "ok"}

Account Information

account = client.get_account()
print(f"Credits remaining: {account.credits_remaining}")
print(f"Plan: {account.plan}")

Error Handling

from kawaa import Kawaa
from kawaa import (
    KawaaError,
    AuthenticationError,
    RateLimitError,
    InsufficientCreditsError,
    ValidationError,
    NotFoundError,
    TimeoutError,
)

client = Kawaa("your-api-key")

try:
    result = client.verify("user@example.com")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except InsufficientCreditsError:
    print("Not enough credits")
except ValidationError as e:
    print(f"Invalid request: {e.message}")
except TimeoutError:
    print("Request timed out")
except KawaaError as e:
    print(f"API error: {e.message}")

Configuration

client = Kawaa(
    api_key="your-api-key",
    base_url="https://api.kawaa.com",  # Custom API URL
    timeout=30.0,                       # Request timeout in seconds
    max_retries=3,                      # Max retry attempts
)

Context Manager

The client can be used as a context manager for automatic cleanup:

with Kawaa("your-api-key") as client:
    result = client.verify("user@example.com")
# Connection closed automatically

Models Reference

VerificationResult

Field Type Description
email str The verified email
status VerificationStatus valid, invalid, risky, unknown, spam_trap, disposable, role, catch_all, pending
score int Quality score 0-100
flags VerificationFlags Email characteristics
suggestion str AI-suggested correction
verification VerificationDetails Technical details

VerificationFlags

Field Type Description
disposable bool Temporary email service
role bool Role account (info@, support@)
free_provider bool Free email provider
catch_all bool Domain accepts all emails

JobStatusResult

Field Type Description
job_id str Unique job identifier
status JobStatus pending, processing, completed, failed
total_emails int Total emails in job
processed_emails int Emails processed so far
valid_count int Valid email count
invalid_count int Invalid email count
risky_count int Risky email count
progress_percent float Completion percentage
results List[VerificationResult] Individual results

License

MIT License - see LICENSE for details.

Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kawaa-0.1.1.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kawaa-0.1.1-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file kawaa-0.1.1.tar.gz.

File metadata

  • Download URL: kawaa-0.1.1.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for kawaa-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f80e7d407851614c32ff158f5d1f6ddf6bbaf73e0ff6f9285aa0b39305ae4c3a
MD5 7cf936eb10132a14070b5f2dac056fd5
BLAKE2b-256 9dd07c216307c0eecd773de5e185dafb0a26974cec141b53022da3b3a2365959

See more details on using hashes here.

File details

Details for the file kawaa-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: kawaa-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for kawaa-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 38103f7c47b0622b10ad6ff596b37cc5b3b3a7427dd4348697cc662b72ea42a2
MD5 9fd0e93b9292223a36b7513f4ecca6fb
BLAKE2b-256 ba62a2ada47a864a6d32364a8cd2525c47cccaa9f934c85f6eb406c272b6a48a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page