A guest arrives at 11 pm and hands over a passport. The night receptionist types an unfamiliar name with a letter that is not on the keyboard, a foreign date format, a nationality, a document number, then searches the booking list for a spelling that does not exist. This tutorial pre-fills the hotel registration card from a passport scan in Python, finds the booking even when spellings differ, and tells the desk whether a police form is needed.
It uses the ID Document OCR API. The hotel is in France. Every output below comes from live calls on 2 December 2026 on public specimens: a French ID card (front and back), a Norwegian passport, a Luxembourg ID card and a South Korean passport.
What the desk has to fill
In France, every guest of foreign nationality fills an individual police form, EU citizens included: surname and first names, date and place of birth, nationality, usual home, mobile phone and email, arrival and expected departure dates. The hotel keeps it for 6 months. Spain asks for more under Royal Decree 933/2021 (document type and number, sex, nationality, birth date, address), sent through SES.HOSPEDAJES.
The document gives the identity half. Address, phone, email and dates come from the booking or the guest. The goal: a card where the hard fields are already right and the receptionist checks only what the code flags.
The script
Save this as guest_card.py, set RAPIDAPI_KEY and install requests.
import os
import re
import sys
import unicodedata
from datetime import date
import requests
URL = "https://id-document-ocr-verification.p.rapidapi.com/parse-id"
HEADERS = {
"x-rapidapi-key": os.environ["RAPIDAPI_KEY"],
"x-rapidapi-host": "id-document-ocr-verification.p.rapidapi.com",
}
HOTEL_COUNTRY = "FRA"
# ICAO 9303 writes these letters with two Latin letters in the MRZ
ICAO = {"Å": "AA", "Ä": "AE", "Æ": "AE", "Ö": "OE", "Ø": "OE", "Ü": "UE", "ß": "SS", "Þ": "TH"}
# How guests type the same letters on a booking site
PLAIN = {"Æ": "AE", "Ø": "O", "Œ": "OE", "ß": "SS", "Þ": "TH", "Ð": "D", "Ł": "L"}
TRUSTED = ("mrz_confirmed", "mrz_only")
def parse(paths):
files = [("images", (os.path.basename(p), open(p, "rb"))) for p in paths]
r = requests.post(URL, headers=HEADERS, files=files, timeout=60)
r.raise_for_status()
return r.json()["result"]
def letters(text, icao=False):
table = ICAO if icao else PLAIN
text = "".join(table.get(c, c) for c in text.upper())
text = unicodedata.normalize("NFKD", text)
return "".join(c for c in text if c.isalpha() and c.isascii())
def tidy(text):
text = re.sub(r"\s*-\s*", "-", text.replace(",", " "))
return re.sub(r"\s+", " ", text).strip()
def name(field):
"""Printed spelling for the card when it matches the MRZ, MRZ spelling otherwise."""
value, printed = field.get("value"), field.get("visual_value")
if not value:
return None, "ask guest"
if printed and letters(printed, icao=True) == letters(value):
return tidy(printed), "ok"
if field["status"] == "mrz_only":
return value, "MRZ spelling, check accents on the document"
return value, "ok" if field["status"] == "mrz_confirmed" else "compare with the document"
def matches_booking(result, booking_name):
"""Guests type bookings without accents: Ø can be O (booking) or OE (MRZ)."""
last = result["fields"]["last_name"]
spellings = {letters(last["value"] or "")}
if last.get("visual_value"):
spellings |= {letters(last["visual_value"]), letters(last["visual_value"], icao=True)}
return letters(booking_name.split()[-1]) in spellings
def registration_card(result, booking_name, arrival):
f = result["fields"]
v = result["verdict"]
get = lambda k: (f.get(k) or {}).get("value")
card, notes = {}, []
card["last_name"], s1 = name(f["last_name"])
card["first_names"], s2 = name(f["first_name"])
card["birth_date"] = get("birth_date")
card["birth_place"] = get("birth_place")
card["nationality"] = get("nationality")
card["document"] = f"{result['document_type']} {result['country']} {get('document_number')}"
card["arrival"] = arrival.isoformat()
if not v["mrz_present"]:
notes.append("no MRZ read: compare every field with the document")
else:
for label, status in [("last_name", s1), ("first_names", s2)]:
if status != "ok":
notes.append(f"{label}: {status}")
for k in ("birth_date", "nationality", "document_number"):
if (f.get(k) or {}).get("status") not in TRUSTED:
notes.append(f"{k}: compare with the document")
if not card["birth_place"]:
notes.append("birth_place: guest completes")
if v["is_expired"] or (get("expiry_date") or "9999") < arrival.isoformat():
action = "ask for a valid document"
elif v["missing_critical_fields"]:
action = "rescan: " + ", ".join(v["missing_critical_fields"]) + " not read"
elif not matches_booking(result, booking_name):
action = f"name differs from booking '{booking_name}', check at desk"
else:
action = "pre-filled"
police_form = card["nationality"] != HOTEL_COUNTRY
return card, notes, action, police_form
if __name__ == "__main__":
booking, *paths = sys.argv[1:]
result = parse(paths)
card, notes, action, police_form = registration_card(result, booking, date(2026, 12, 2))
for k, val in card.items():
print(f"{k:12} {val or '-'}")
print("police form:", "yes" if police_form else "no")
for n in notes:
print("note:", n)
print("action:", action)
Guest 1: a French card, no police form
$ python guest_card.py "Maelys Martin" front.jpg back.jpg
last_name MARTIN
first_names Maëlys-Gaëlle Marie
birth_date 1990-07-13
birth_place PARIS
nationality FRA
document id_card FRA X4RTBPFW4
arrival 2026-12-02
police form: no
action: pre-filled
Both sides in one call, so every identity field is confirmed by the MRZ on the back. The MRZ has no accents, so name takes the printed value when its letters match the MRZ. French guest, French hotel: no police form.
Guest 2: Ø in the name, plain O in the booking
$ python guest_card.py "Asamund Ostenbyen" passport_no.jpg
last_name ØSTENBYEN
first_names AASAMUND SPECIMEN
birth_date 1956-04-23
birth_place -
nationality NOR
document passport NOR CCC002251
arrival 2026-12-02
police form: yes
note: first_names: MRZ spelling, check accents on the document
note: birth_place: guest completes
action: pre-filled
The printed surname is ØSTENBYEN. ICAO 9303 writes Ø as OE in the MRZ: OESTENBYEN. The guest booked as "Ostenbyen". matches_booking accepts the booking if it matches the printed spelling or the MRZ spelling, each folded the way it would be typed. For the first names the MRZ spelling went on the card, so the code asks to check the accents (ÅSAMUND). Norway is not France: police form yes.
Same passport, booking under another name:
$ python guest_card.py "Anna Hansen" passport_no.jpg
last_name ØSTENBYEN
first_names AASAMUND SPECIMEN
birth_date 1956-04-23
birth_place -
nationality NOR
document passport NOR CCC002251
arrival 2026-12-02
police form: yes
note: first_names: MRZ spelling, check accents on the document
note: birth_place: guest completes
action: name differs from booking 'Anna Hansen', check at desk
Guest 3: an EU card without its back
$ python guest_card.py "Jeanne Specimen" id_lu_front.jpg
last_name Spécimen
first_names Jeanne
birth_date 1983-08-19
birth_place -
nationality LUX
document id_card LUX SPEC07347
arrival 2026-12-02
police form: yes
note: no MRZ read: compare every field with the document
note: birth_place: guest completes
action: pre-filled
Only the front: every field read from the print, accent in Spécimen included, but nothing to cross-check, so one note: compare with the document. Luxembourg is in the EU but is not France: police form yes. EU guests are the case most often missed.
Guest 4: an expired passport
$ python guest_card.py "Suyeon Lee" passport_kr.jpg
last_name LEE
first_names SUYEON
birth_date 1985-07-02
birth_place -
nationality KOR
document passport KOR M70689098
arrival 2026-12-02
police form: yes
note: birth_place: guest completes
action: ask for a valid document
The API flags is_expired and the script also compares the expiry with the arrival date. Whether to accept it is house policy; the script makes sure nobody misses it.
Production tips
- One photo of the passport data page is enough. For ID cards take both sides: the MRZ on the back confirms the front.
- Pre-fill, then let the guest complete address, phone and email on a tablet.
-
Children under 15 can go on an accompanying adult's police form in France: compute the age from
birth_date. - Do not keep the scan. The ID Document OCR API does not store the images you send.
Full tutorial with sources: Hotel Check-In Passport Scan on ai-engine.net. For self check-in with a selfie, see the guest ID verification guide.
Next step
Get a key on the ID Document OCR API page, save
guest_card.pyand run it on the Norwegian specimen with the booking name "Asamund Ostenbyen".

Top comments (0)