"Build a lead enrichment pipeline in Python in 15 minutes"
"A complete, production-sane starter: batch enrichment from CSV, exponential backoff, quota politeness, and local caching so you never pay twice for the same domain."
Most enrichment tutorials stop at one curl command. Real pipelines need retries, rate politeness, and caching. Here is a complete starter you can run today with only httpx installed.
The client with backoff
import csv, time, sqlite3, httpx
API = "https://scrapeeg.org/v1/contact/search"
KEY = "YOUR_API_KEY"
def enrich(domain: str, tries: int = 3):
for attempt in range(tries):
r = httpx.post(
API,
json={"url": f"https://{domain}/"},
headers={"X-Api-Key": KEY},
timeout=10,
)
if r.status_code == 200:
return r.json()
if r.status_code == 429: # rate limited: back off exponentially
time.sleep(2 ** attempt)
continue
r.raise_for_status()
return None
Three rules encoded here: retry only on 429/5xx-class failures, sleep exponentially, and never retry a 422 (bad input) — fix your data instead.
Cache so you never pay twice
Before calling the API, check a local SQLite cache keyed by domain. Enrichment results for a domain rarely change within a day, and re-billing yourself for repeats is the most common pipeline waste we see.
cache = sqlite3.connect("enrich_cache.db")
cache.execute("CREATE TABLE IF NOT EXISTS c(domain TEXT PRIMARY KEY, json TEXT, ts REAL)")
Store the raw JSON response with a timestamp; treat entries older than your freshness policy as misses.
The batch loop
with open("leads.csv") as fh, open("leads_enriched.csv", "w", newline="") as out:
rows = csv.DictReader(fh)
w = csv.DictWriter(out, fieldnames=["domain", "email", "phone"])
w.writeheader()
for row in rows:
domain = row["domain"].strip().lower()
data = enrich(domain)
if not data:
continue
w.writerow({
"domain": data["domain"],
"email": (data["emails"] or [""])[0],
"phone": (data["phones"] or [""])[0],
})
time.sleep(0.2) # politeness: protect your quota and the target
Three production notes
- Masked emails mean trial tier. If an email contains
***, you are on a trial key. Upgrade before routing records to senders. - Log
credits_charged. Sum it per run; that number is your true cost per batch. - Never send unverified. Filter on verification status before any outreach. See how to measure enrichment quality for the metrics to track after launch.
Full endpoint reference lives in the docs. If you're wondering whether you should own this infrastructure at all, read build vs. buy first.
Put this into production
Get 250 free enrichment credits — no credit card required.
Get your API keyRelated reading
"Anatomy of a good enrichment API response: schemas, errors, versioning"
"What we look for when consuming someone else's data API — and the design rules we hold our own /v1 endpoints to."
"Lead routing that doesn't rot: ownership, SLAs, and enrichment triggers"
"Unrouted leads die in 48 hours. The ownership rules, SLA clocks, and automation triggers that keep enriched records moving."