Piloterr

Enrich a list of prospects

Find the email of each prospect and write the results to a CSV file.

Find the email of each prospect and write the results to a CSV file. A failed call is recorded in the error column and the loop moves on.

import csv
import os
import time
import requests

API_KEY = os.environ["PILOTERR_API_KEY"]

prospects = [
    {"name": "Patrick Collison", "company_domain": "stripe.com"},
    {"name": "Sam Altman",       "company_domain": "openai.com"},
    {"name": "Tobi Lutke",       "company_domain": "shopify.com"},
]

def find_email(name: str, company_domain: str) -> dict:
    r = requests.get(
        "https://api.piloterr.com/v2/email/finder",
        headers={"x-api-key": API_KEY},
        params={"query": name, "company_domain": company_domain},
    )
    if r.status_code != 200:
        return {"error": f"{r.status_code} {r.text}"}
    return r.json()

with open("prospects_enriched.csv", "w", newline="") as f:
    writer = csv.DictWriter(f, fieldnames=["name", "company_domain", "email", "status", "error"])
    writer.writeheader()

    for p in prospects:
        result = find_email(p["name"], p["company_domain"])
        writer.writerow({
            **p,
            "email":  result.get("email") or "",
            "status": result.get("status") or "",
            "error":  result.get("error") or "",
        })
        time.sleep(0.5)

print("Done! Results saved to prospects_enriched.csv")