Look up food ingredients by barcode with SQLite

Connect a scanned barcode to a product name, ingredient declaration and product photo. This walkthrough uses our free dataset sample and a Python script that runs with the standard library, so you can try the lookup before building it into your app.

1. Get the sample and lookup script

Get the free sample pack and extract it into a folder. It contains products.sqlite, the product photos in images/ and documentation. The SQLite file is already a database, so there is no import step for this example.

If you want to start with just the data, download the sample SQLite file from Hugging Face. You can add the images later.

Save barcode_lookup.py in the same folder. You need Python 3.10 or later. The script opens the database read-only and does not send your barcodes anywhere.

2. Look up a product in the sample

Open a terminal in that folder and run:

python3 barcode_lookup.py products.sqlite 689380928472

The October 2026 sample includes this barcode for Gran Caffe Garibaldi Gusto Oro Nespresso Professional Compatible 50 Capsules. The result includes its product ID, name, ingredient declaration and image filename. Its ingredient declaration is Coffee.

The script also reports the expected local image path and whether that file exists. If you downloaded only the SQLite file, image_exists will be false. Extract the sample images to images/ beside the database, or specify their folder:

python3 barcode_lookup.py products.sqlite 689380928472 --images-dir /path/to/images

You can use the returned image path to display the matching product photo in your own interface.

3. Keep the barcode as text

The records store barcodes as 14-digit GTINs. The example UPC, 689380928472, becomes 00689380928472 when padded with leading zeros. The script checks the length and check digit before querying, and supports GTIN-8, UPC-A, EAN-13 and GTIN-14.

Keep barcode columns as text so a spreadsheet or database import does not remove those zeros. If you are querying SQLite directly, the equivalent lookup is:

SELECT id, gtin, name, ingredients, image_name
FROM products
WHERE gtin = '00689380928472';

The script uses a parameterised query, so you can pass a supported scanned barcode as an argument without editing SQL.

4. Use the result in your catalogue

Use the barcode to match a scanned item, id to refer to the dataset record, ingredients to display its ordered declaration and image_name to connect the product photo. You can build this lookup into a product page or enrich matching records in a catalogue you already maintain.

The sample lets you check the schema and integration. A barcode missing from the sample does not establish that it is missing from the full archive. The script returns not_found for an unmatched barcode and leaves missing ingredients or image references as missing values.

Read the dataset documentation for nutrition joins and other formats, or see the published field coverage to understand which information is recorded across the full release.

Run the same lookup on the full dataset

The Complete Archive includes the full product dataset in SQLite, CSV and JSONL, with referenced product images and schema documentation. Once you have your snapshot, point the script at its SQLite file and extracted image folder to use the same lookup across the archive.

View The Complete Archive or tell us which brands and products your project needs.

View the example and usage notes on Hugging Face.

Free sample

Get your free sample

Loading sample details…