Skip to main content

Python SDK for the EmailKind API — classify emails by provider and type

Project description

EmailKind Python SDK

Official Python SDK for the EmailKind API. Classify email addresses by provider (Gmail, Outlook, Google Workspace, etc.) and type (business, personal, disposable, education).

Installation

pip install emailkind

Quick Start

from emailkind import EmailKind

client = EmailKind("sk_live_your_api_key")

result = client.classify(email="jane@company.com")
print(result.provider.name)              # "Google Workspace"
print(result.classification.is_business) # True
print(result.confidence)                 # 0.98

Authentication

Pass your API key directly or set the EMAILKIND_API_KEY environment variable:

# Explicit
client = EmailKind("sk_live_xxx")

# From environment
import os
os.environ["EMAILKIND_API_KEY"] = "sk_live_xxx"
client = EmailKind()

# Custom base URL
client = EmailKind("sk_live_xxx", base_url="https://custom.endpoint.com")

# Custom timeout (default: 30s)
client = EmailKind("sk_live_xxx", timeout=10)

Classify

Classify a single email address or domain:

# By email
result = client.classify(email="user@gmail.com")

# By domain
result = client.classify(domain="gmail.com")

# With company enrichment
result = client.classify(email="ceo@startup.io", enrich=True)
print(result.company.name)   # "Startup Inc."
print(result.company.source) # "website"

ClassifyResult fields

Field Type Description
success bool Whether the request succeeded
request_id str Unique request identifier
email str Input email (if provided)
domain str Domain that was classified
provider Provider Provider info (id, name, type)
classification Classification Flags (is_business, is_free, etc.)
mx list[str] MX records found
confidence float Confidence score (0.0 to 1.0)
cached bool Whether the result was served from cache
company `Company None`

Batch Classify

Classify multiple emails and/or domains in one request:

batch = client.classify_batch(
    emails=["user@gmail.com", "ceo@company.com"],
    enrich=True,
)

print(batch.count)  # 2
for item in batch.results:
    print(item.input, item.provider.name, item.classification.is_business)

You can also pass domains:

batch = client.classify_batch(domains=["gmail.com", "outlook.com"])

Custom Rules

Manage custom classification rules that override default provider detection:

# List rules
rules = client.list_rules()

# Create a rule
rule = client.create_rule(
    match_type="domain",
    match_value="internal.company.com",
    provider_name="Internal Mail",
    provider_type="business",
)
print(rule.id)

# Delete a rule
client.delete_rule(rule.id)

Bulk Processing

Upload a CSV file for asynchronous bulk classification:

# Upload a file (accepts file path or file object)
job = client.bulk_upload("contacts.csv", enrich=True)
print(job.id)      # "job_xxx"
print(job.status)  # "pending"

# Check status
job = client.bulk_status(job.id)
print(job.status)     # "completed"
print(job.processed)  # 1500

# Download results as CSV bytes
csv_data = client.bulk_results(job.id)
with open("results.csv", "wb") as f:
    f.write(csv_data)

# List all bulk jobs
jobs = client.bulk_list()
for j in jobs:
    print(j.id, j.status, j.processed, "/", j.total)

You can also pass a file object:

with open("contacts.csv", "rb") as f:
    job = client.bulk_upload(f)

Error Handling

The SDK raises typed exceptions for different error conditions:

from emailkind import (
    EmailKind,
    EmailKindError,
    AuthenticationError,
    RateLimitError,
    ValidationError,
    ForbiddenError,
    NotFoundError,
)

client = EmailKind("sk_live_xxx")

try:
    result = client.classify(email="test@example.com")
except AuthenticationError as e:
    # Invalid or missing API key (401)
    print("Auth failed:", e.message)
except RateLimitError as e:
    # Too many requests (429)
    print("Rate limited, retry after:", e.retry_after, "seconds")
except ValidationError as e:
    # Bad request parameters (400)
    print("Invalid input:", e.message)
except ForbiddenError as e:
    # Insufficient permissions (403)
    print("Forbidden:", e.message)
except NotFoundError as e:
    # Resource not found (404)
    print("Not found:", e.message)
except EmailKindError as e:
    # Any other API error
    print("Error:", e.code, e.message, e.request_id)

All exceptions inherit from EmailKindError and include:

Attribute Type Description
message str Human-readable error message
code `str None`
request_id `str None`
status_code `int None`

RateLimitError also includes retry_after (seconds to wait before retrying).

Requirements

  • Python 3.8+
  • requests >= 2.20

License

MIT

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

emailkind-0.1.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

emailkind-0.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file emailkind-0.1.0.tar.gz.

File metadata

  • Download URL: emailkind-0.1.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for emailkind-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e55aa84186eeb57aa3951afa7f510e14e8737436a5a2d4b89e385da23615f520
MD5 780a645c778a80bc11f29c36b99cf5e9
BLAKE2b-256 7bcc3005c9a6136a5235809ed8744bf9a1b057afc305715956f325238dff2af2

See more details on using hashes here.

File details

Details for the file emailkind-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: emailkind-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for emailkind-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff7b55e38667e0589421216bbc380c258280f4dedfa33c4d3921adae4d3baf0f
MD5 689f87f100955238fb89590cabebe504
BLAKE2b-256 9e48dfedf1283215cf01ff18bfdbe58c20a4ac05acb50cecfe4d7f06bd4deba9

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