SDKs officiels
EmailKind fournit des SDKs officiels pour Python, Node.js et Go. Ils gèrent l'authentification, les erreurs, les limites de taux et offrent des réponses typées.
Python
Installation
pip install emailkind
Démarrage rapide
from emailkind import EmailKind
client = EmailKind("sk_live_VOTRE_CLE")
# Classifier un email
result = client.classify(email="[email protected]")
print(result.provider.name) # "Google Workspace"
print(result.classification.is_business) # True
# Avec enrichissement entreprise
result = client.classify(domain="stripe.com", enrich=True)
print(result.company.name) # "Stripe, Inc"
Classification par lot
batch = client.classify_batch(
emails=["[email protected]", "[email protected]"],
enrich=True
)
for item in batch.results:
print(f"{item.domain}: {item.provider.type}")
Règles personnalisées
# Créer une règle
rule = client.create_rule(
match_type="domain",
match_value="internal.company.com",
provider_name="Mail Interne",
provider_type="business"
)
# Lister les règles
rules = client.list_rules()
# Supprimer une règle
client.delete_rule(rule.id)
Traitement en lot (bulk)
# Importer un CSV
job = client.bulk_upload("emails.csv", enrich=True)
# Vérifier le statut
job = client.bulk_status(job.id)
print(f"{job.processed_items}/{job.total_items}")
# Télécharger les résultats
csv_data = client.bulk_results(job.id)
with open("resultats.csv", "wb") as f:
f.write(csv_data)
Gestion des erreurs
from emailkind import EmailKind, RateLimitError, AuthenticationError
client = EmailKind("sk_live_VOTRE_CLE")
try:
result = client.classify(email="[email protected]")
except AuthenticationError:
print("Clé API invalide")
except RateLimitError as e:
print(f"Limite atteinte. Réessayer dans {e.retry_after}s")
Configuration
# Clé API via variable d'environnement
client = EmailKind() # lit EMAILKIND_API_KEY
# URL personnalisée
client = EmailKind("sk_live_xxx", base_url="https://custom.endpoint.com")
# Timeout personnalisé (secondes)
client = EmailKind("sk_live_xxx", timeout=10)
Node.js
Installation
npm install emailkind
Démarrage rapide
import EmailKind from 'emailkind';
const client = new EmailKind('sk_live_VOTRE_CLE');
// Classifier un email
const result = await client.classify({ email: '[email protected]' });
console.log(result.provider.name); // "Google Workspace"
console.log(result.classification.is_business); // true
// Avec enrichissement
const enriched = await client.classify({ domain: 'stripe.com', enrich: true });
console.log(enriched.company?.name); // "Stripe, Inc"
Classification par lot
const batch = await client.classifyBatch({
emails: ['[email protected]', '[email protected]'],
enrich: true,
});
for (const item of batch.results) {
console.log(`${item.domain}: ${item.provider?.type}`);
}
Règles personnalisées
const rule = await client.createRule({
matchType: 'domain',
matchValue: 'internal.company.com',
providerName: 'Mail Interne',
providerType: 'business',
});
const rules = await client.listRules();
await client.deleteRule(rule.id);
Traitement en lot
const job = await client.bulkUpload('emails.csv', { enrich: true });
const status = await client.bulkStatus(job.id);
const csv = await client.bulkResults(job.id); // Buffer
Gestion des erreurs
import EmailKind, { RateLimitError, AuthenticationError } from 'emailkind';
try {
const result = await client.classify({ email: '[email protected]' });
} catch (err) {
if (err instanceof AuthenticationError) {
console.error('Clé API invalide');
} else if (err instanceof RateLimitError) {
console.error(`Limite atteinte. Réessayer dans ${err.retryAfter}s`);
}
}
Go
Installation
go get github.com/gastonmedia/emailkind-go
Démarrage rapide
package main
import (
"context"
"fmt"
emailkind "github.com/gastonmedia/emailkind-go"
)
func main() {
client := emailkind.NewClient("sk_live_VOTRE_CLE")
ctx := context.Background()
result, err := client.Classify(ctx, &emailkind.ClassifyParams{
Email: "[email protected]",
})
if err != nil {
panic(err)
}
fmt.Println(result.Provider.Name) // "Google Workspace"
fmt.Println(result.Classification.IsBusiness) // true
}
Classification par lot
batch, err := client.ClassifyBatch(ctx, &emailkind.BatchParams{
Emails: []string{"[email protected]", "[email protected]"},
Enrich: true,
})
for _, item := range batch.Results {
fmt.Printf("%s: %s\n", item.Domain, item.Provider.Type)
}
Règles personnalisées
rule, _ := client.CreateRule(ctx, &emailkind.CreateRuleParams{
MatchType: "domain",
MatchValue: "internal.company.com",
ProviderName: "Mail Interne",
ProviderType: "business",
})
rules, _ := client.ListRules(ctx)
client.DeleteRule(ctx, rule.ID)
Traitement en lot
job, _ := client.BulkUpload(ctx, "emails.csv", &emailkind.BulkUploadParams{Enrich: true})
status, _ := client.BulkStatus(ctx, job.ID)
csvData, _ := client.BulkResults(ctx, job.ID)
os.WriteFile("resultats.csv", csvData, 0644)
Gestion des erreurs
result, err := client.Classify(ctx, &emailkind.ClassifyParams{Email: "[email protected]"})
if err != nil {
if emailkind.IsAuthError(err) {
log.Fatal("Clé API invalide")
}
if emailkind.IsRateLimitError(err) {
retryAfter := emailkind.RetryAfter(err)
log.Printf("Limite atteinte. Réessayer dans %ds", retryAfter)
}
}
Comparaison
| Fonctionnalité | Python | Node.js | Go |
|---|---|---|---|
| Classifier | classify() | classify() | Classify() |
| Lot | classify_batch() | classifyBatch() | ClassifyBatch() |
| Règles | list_rules(), create_rule(), delete_rule() | listRules(), createRule(), deleteRule() | ListRules(), CreateRule(), DeleteRule() |
| Bulk upload | bulk_upload() | bulkUpload() | BulkUpload() |
| Réponses typées | Dataclasses | Interfaces TypeScript | Structs |
| Gestion erreurs | Exceptions | Sous-classes Error | Fonctions sentinelles |
| Dépendances | requests | Aucune (fetch natif) | Aucune (stdlib) |
| Version min | Python 3.8+ | Node.js 18+ | Go 1.22+ |