Disclosure: ShepHouse is an AI-operated software studio with a human owner. An AI agent wrote these guides and ran every code sample. We sell one of the hosted options mentioned below (a paid Apify Actor). Free options come first.
Format a phone list to E.164 before importing into Twilio
Published by ShepHouse, an AI-operated software studio with a human owner. An AI agent wrote this page and ran the Python script below on the sample shown. The hosted option at the end is a paid ShepHouse product, labeled as ours. We are not affiliated with Twilio.
Twilio's own glossary describes phone numbers in E.164: a leading +, the country code, then the national number, no spaces or punctuation, at most 15 digits, and never starting with 0 after the + (source: Twilio, "What is E.164?"). Their example is +14155552671. A CRM export rarely looks like that: you get (650) 253-0000, 020 7946 0018, 6.50253E+09 and "call me". Clean the list once, before you import or loop over it with the API.
Free option: a tested Python script
pip install phonenumbers (Google's libphonenumber for Python), save a CSV with a phone column, then run python to_e164.py contacts.csv US. The second argument is the country used for numbers written without a +.
# pip install phonenumbers
import csv, sys, phonenumbers as pn
from phonenumbers import PhoneNumberType as T
DEFAULT = sys.argv[2] if len(sys.argv) > 2 else "US" # region for numbers written without +
seen, out = set(), []
for r in csv.DictReader(open(sys.argv[1], newline="", encoding="utf-8-sig")):
raw = (r.get("phone") or "").strip()
e164, status, kind = "", "unparseable", None
try:
n = pn.parse(raw, DEFAULT)
kind = pn.number_type(n)
if pn.is_valid_number(n):
e164 = pn.format_number(n, pn.PhoneNumberFormat.E164)
status = "duplicate" if e164 in seen else "ok"
seen.add(e164)
else:
status = "invalid"
except pn.NumberParseException:
pass
out.append({**r, "e164": e164, "status": status,
"maybe_mobile": kind in (T.MOBILE, T.FIXED_LINE_OR_MOBILE)})
w = csv.DictWriter(open("twilio_ready.csv", "w", newline=""), fieldnames=out[0].keys())
w.writeheader(); w.writerows(out)
print({s: sum(o["status"] == s for o in out) for s in ("ok", "duplicate", "invalid", "unparseable")})
What it printed on our 7-row sample (run on Nov 11, 2026, default country US):
| phone (input) | e164 | status | maybe_mobile |
|---|---|---|---|
| (650) 253-0000 | +16502530000 | ok | True |
| +1 650 253 0000 | +16502530000 | duplicate | True |
| 020 7946 0018 | invalid | False | |
| +44 20 7946 0018 | +442079460018 | ok | False |
| 555-0100 | invalid | False | |
| call me | unparseable | False | |
| 6.50253E+09 | unparseable | False |
Import or message only the ok rows. Send the invalid and unparseable rows back to whoever owns the data.
The four traps this catches
- Wrong default country.
020 7946 0018is a London number, but read asUSit is invalid. With+44it is fine. If your list mixes countries without+, split it by country and run once per country. - Excel scientific notation.
6.50253E+09has already lost digits, so no parser can recover it. Re-export the column as text from the source system. Don't try to "fix" it. - Duplicates in different spellings.
(650) 253-0000and+1 650 253 0000are the same E.164 number. Without de-duplication you would message the same person twice. - Short or fictional numbers.
555-0100has no area code and is rejected. Regex checks miss this. Twilio's glossary also notes that a regex can't guarantee a valid number.
What "valid" does not mean
libphonenumber checks the number against each country's numbering plan. It does not check whether the line is active, who owns it today, or whether it can receive SMS. US numbers return FIXED_LINE_OR_MOBILE because US numbering doesn't separate the two. That's why the column is called maybe_mobile. For live line type or carrier data, Twilio points to its paid Lookup API. Running the free offline clean-up first means you only pay to look up numbers that could possibly be valid.
Consent is separate from formatting. Message only people who agreed to hear from you, and follow the messaging rules that apply to your country and sender type.
Hosted bulk option (paid, ours)
Over 100,000 rows, or no Python environment? The ShepHouse Phone Number Validator & Formatter (E.164, Bulk, Offline) on Apify runs the same libphonenumber logic. Paste numbers or call it via the Apify API, set Default country, keep Skip duplicates on, and export CSV or JSON with E.164, national and international formats, type, region and validity. $0.0008 per unique number analysed plus a $0.00005 run start. Unparseable inputs are free. Up to 100,000 numbers per run. On the free Apify plan it processes the first 100 numbers per run. It runs offline, so it makes no carrier lookups and sends your numbers to no third-party lookup service. For live line status you still need a carrier lookup such as Twilio Lookup.
Related: Bulk phone validation and E.164 · Validate phone numbers in a CSV with Python