Tutorial

Hotel Check-In: Pre-Fill the Guest Card From a Passport Scan in Python

Scan a guest's passport or ID card at the front desk and pre-fill the registration card in Python: printed spelling for the card, MRZ spelling to find the booking, police form flag for foreign guests, and a clear action for expired documents.

Norwegian sample passport scanned at a hotel desk and turned into a guest registration card: last name ØSTENBYEN as printed, MRZ spelling OESTENBYEN, booking matched, police form yes

This tutorial uses the id-document-ocr API. See the docs, live demo, and pricing.

A guest arrives at 11 pm after a delayed flight and hands over a passport. The night receptionist types an unfamiliar name with a letter that is not on the keyboard, a date of birth in a foreign 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 the spellings differ, and tells the desk whether a police form is needed.

It uses the ID Document OCR API. The hotel in our example is in France. Every output below comes from live calls made on 2 December 2026 on public specimens: a French ID card (front and back photos), 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, European Union citizens included. It asks for surname and first names, date and place of birth, nationality, usual home, mobile phone and email, and the 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, date of birth and address, sent to the authorities through SES.HOSPEDAJES. Most hotels also keep their own registration card for every guest.

The document gives you the identity half of that list. The other half (address, phone, email, stay dates) comes from the booking or the guest. So the goal is not a fully automatic form, it is a form where the hard fields are already right and the receptionist only checks what the code flags.

The Script

Save this as guest_card.py. parse sends the photos, name picks the spelling for the card, matches_booking finds the reservation, and registration_card builds the card, the notes for the desk and the next action. Set RAPIDAPI_KEY in your environment and install requests.

python
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)

Run it with the name on the booking, then the photos of the document:

bash
python guest_card.py "Asamund Ostenbyen" passport.jpg

Guest 1: A French Card, No Police Form

text
$ 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 went in one call, so every identity field was confirmed by the machine-readable zone (MRZ) on the back. The MRZ writes MAELYS GAELLE MARIE, without accents. The card should carry the name as printed, so name takes the printed value when its letters match the MRZ, and turns the commas between French first names into spaces. The guest is French, the hotel is in France: no police form. This card also prints the place of birth, so birth_place is filled too.

Guest 2: Ø in the Name, Plain O in the Booking

text
$ 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. The MRZ cannot hold Ø, and ICAO 9303 writes it as OE: OESTENBYEN. The guest booked online as "Ostenbyen". Three spellings, one person. letters folds each one the way it would be typed, and matches_booking accepts the booking if it matches the printed spelling or the MRZ spelling. A plain string comparison would have sent the receptionist hunting through the list.

For the first names the MRZ spelling went on the card (AASAMUND, where the passport prints ÅSAMUND), so the code adds a note to check the accents. Dates and the document number come from the MRZ with valid check digits, so there is nothing to check there. Norway is not France: police form: yes.

The same passport with a booking under another name:

text
$ 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

The card is still filled, but the action changes. A wrong match is the desk's call (a spouse who booked, a company booking), not the script's.

Guest 3: An EU Card Without Its Back

text
$ 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

The guest showed only the front of a Luxembourg ID card. Every field was read from the printed text, the accent in Spécimen included, but on this card the MRZ is on the back, so nothing could be cross-checked. The code adds one note instead of five: compare with the document. And 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

text
$ 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 passport expired on 15 April 2024. The API flags it with is_expired, and the script also compares the expiry date with the arrival date. The card is pre-filled anyway, so if the guest produces another document the receptionist scans it and the card is replaced. Whether an expired document is acceptable is your house policy; the script only makes sure nobody misses it.

Four guests at a hotel in France: French ID card pre-filled with no police form, Norwegian passport and Luxembourg ID card pre-filled with a police form, South Korean passport expired with ask for a valid document

Production Tips

  • Scan at the desk with a phone or a document scanner. 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. Show the card on a tablet with the document fields filled and the rest (address, phone, email) empty. The guest signs a card that is already right.
  • Children under 15. In France their details can go on an accompanying adult's police form. Compute the age from birth_date and the arrival date and attach the child to the adult's card.
  • Do not keep the scan. Store the card and delete the image. The ID Document OCR API does not store the images you send.
  • Same code, other countries. Change HOTEL_COUNTRY and the list of fields on the card. For Spain, add sex and document_number to what you send to SES.HOSPEDAJES.

Next Step

Get a key on the ID Document OCR API page, save guest_card.py and run it on the Norwegian specimen with the booking name "Asamund Ostenbyen". For self check-in where the guest also takes a selfie, see the guest ID verification guide for vacation rentals. To take good photos of both sides of a card from a phone, read the phone photo tutorial, and for the check digits behind the MRZ, the passport MRZ tutorial.

Sources

Frequently Asked Questions

How do I pre-fill a hotel registration card from a passport?
Send a photo or scan of the passport data page to the ID Document OCR API and map the returned fields to your card: last_name, first_name, birth_date, nationality and document_number, plus birth_place when the document carries it. Address, phone, email and stay dates still come from the guest or the booking.
Which hotel guests need a police form in France?
Every guest of foreign nationality, European Union citizens included, fills an individual police form (fiche individuelle de police) under article R814-1 of the French immigration code. It holds surname and first names, date and place of birth, nationality, usual home, mobile phone and email, and the arrival and expected departure dates. A child under 15 can go on an accompanying adult's form, and the hotel keeps the forms for 6 months.
Why does the passport name not match the booking?
The machine-readable zone has no accents: ICAO 9303 writes Ø as OE and Å as AA, so ØSTENBYEN becomes OESTENBYEN. A guest typing the booking usually writes Ostenbyen. Compare the booking name with both the printed spelling and the MRZ spelling, after removing accents, before flagging a mismatch.
Should the hotel keep a copy of the passport?
Keep only the fields your registration card or the law requires, and delete the scan. The ID Document OCR API does not store the images you send, so the only copy is the one your own system keeps.

Ready to Try id-document-ocr?

Check out the full API documentation, live demos, and code samples on the id-document-ocr spotlight page.

Related Articles

Continue learning with these related guides and tutorials.