Python · Programming · Automation
Pyra
Three messy files, one reliable list.
Pyra is a small data-processing tool written in Python with zero dependencies. The scenario is fictional; the code is real: it lives in this site's repository, and the output shown below comes from an actual run.
- Status
- Personal concept — 2026
- Role
- Design, architecture, development
- Nature
- Personal concept — never deployed or used commercially
- Language
- Python 3, standard library only
- Source
- tools/pyra/pyra.py — about 160 lines
A small business receives appointments from three sources: the website form, a calendar tool and a hand-kept spreadsheet. Three delimiters, three date formats, duplicates, typos.
01 — Approach
Separate what varies from what doesn't.
What changes between sources — delimiter, column names, date format — is described in a configuration table, one “adapter” per source. The rest of the pipeline only knows a single data model.
Adding a fourth source means adding one entry to that table, without touching the logic.
adapter()normalize_*()validatededupe(email, date)02 — Model
One booking, one format.
@dataclass(frozen=True)
class Booking:
name: str
email: str
phone: str
date: str # ISO 8601 (AAAA-MM-JJ)
service: str
source: str03 — Adapters
Configuration instead of conditionals.
SOURCES = {
"site": {"delimiter": ",", "date_formats": ["%Y-%m-%d"], ...},
"agenda": {"delimiter": ";", "date_formats": ["%d.%m.%Y"], ...},
"tableur": {"delimiter": ",", "date_formats": ["%d/%m/%Y", "%d/%m/%y"], ...},
}04 — Normalisation
Five ways to write a number, one way to store it.
def normalize_phone(raw: str) -> str:
"""Ramène un numéro suisse au format +41 XX XXX XX XX."""
digits = re.sub(r"\D", "", raw)
if digits.startswith("0041"):
digits = digits[4:]
elif digits.startswith("41") and len(digits) == 11:
digits = digits[2:]
elif digits.startswith("0"):
digits = digits[1:]
if len(digits) != 9:
raise ValueError(f"téléphone invalide « {raw} »")
return f"+41 {digits[0:2]} {digits[2:5]} {digits[5:7]} {digits[7:9]}"05 — Validation & duplicates
Reject with a reason, merge with a rule.
for line, row in enumerate(csv.DictReader(handle, delimiter=spec["delimiter"]), start=2):
report.read += 1
try:
booking = parse_row(row, source)
except (ValueError, KeyError) as error:
report.rejected.append({"source": source, "line": line, "reason": str(error)})
continue
key = (booking.email, booking.date) # même personne, même jour = doublon
if key in seen:
report.duplicates += 1
continue
seen.add(key)
bookings.append(booking)$ python3 pyra.py samples --out output pyra · 3 sources · 12 lignes lues ✓ 7 réservations conservées ⧉ 2 doublons fusionnés ✕ 3 lignes rejetées site:4 e-mail invalide « ines.ferraz@exemple » agenda:4 téléphone invalide « 079 88 41 » tableur:4 date illisible « 31/02/2026 » → output/reservations.csv
06 — Challenges
The real problems are in the details.
- 01
Ambiguous dates
Is “7/3/26” the 7th of March or the 3rd of July? Pyra only tries the formats declared for each source, in order. February 31st is rejected, not corrected.
- 02
The duplicate key
Same email, same day: simple and explainable. But two appointments on the same day for one person would be wrongly merged.
- 03
Never guess
Doubtful data is flagged rather than silently repaired. An automation tool has to be predictable before being clever.
07 — Limitations
What Pyra doesn't do yet.
- 01
No automated tests
Next step: unit tests for every normalisation function.
- 02
No fuzzy matching
“Marc Aubry” and “Marc Aubri” would be two people.
- 03
Command-line interface
Fine for a developer, not for the end user.
08 — What I take away
42 taught me rigour, Python taught me readability.
- 01
Handle every error case
A habit from writing C at 42: every invalid input has its path.
- 02
Write to be re-read
Explicit names and one responsibility per function.
- 03
Design helps code too
Treat the error report as an interface: clear, actionable, honest.