Barcode Scanner Examples

Test the open-source QR Code & Barcode Scanner library before writing any integration code. Launch a browser demo or Python notebook online, scan the sample image and inspect the barcode string.

Browser example

An interactive web page that decodes images locally in your browser. Launches directly in StackBlitz with no account.

Open in StackBlitz

Python notebook

A Jupyter notebook that installs the Python package and prints every scan result. Opens on Binder without signing in.

Launch on Binder

Source code

Full source and setup steps for both examples in the scanner’s public GitHub repository.

View examples on GitHub

Barcode Scanner examples: quick summary

  • Published packages, pinned

    WASM + Python

  • Hosted demos & notebooks

    StackBlitz, Binder, Colab

  • Codes in the sample image

    Code 128 + QR code

  • Open-source licence

    MIT

Pick a barcode scanner example

Explore hosted browser demos, standalone Vite or Jupyter starters, or the ready-made examples bundled with the browser SDK and CLI.

What it shows
Install the wheel, verify package metadata, scan the sample across all three profiles (fast, frame and full, representing three analysis depths), then inspect the symbology, text, payload kind (plain text or URL) and coordinates of each code.
Package
qrcode-barcode-scanner on PyPI
Run it online
Start a temporary Binder session with no sign-up (boot takes a few minutes and shuts down after around ten minutes of idle time), or run the same notebook in Google Colab using a Google account.
Launch notebook on Binder

What it shows
One page decodes a selected image file inside a module Worker. A second page reads live camera frames using the package’s camera controller, tracker and overlay.
Run it
Install the npm package and serve its folder via any static file server, with no bundler or frontend framework required.
Read package examples

What it shows
Decode an image file and read the JSON scan report. Exit codes clearly distinguish a detection, an empty scan and invalid input.
Runs on
macOS, Linux and Windows.
Open CLI guide

Links verified on 27 November 2026. The StackBlitz, Binder and Google Colab links target a pinned release tag in the scanner repository so they continue running identical files; the GitHub Pages demo and Hugging Face Space track the published release.

Run the barcode examples locally

Both the browser demo and Python notebook start from a fresh clone of the scanner repository. If you already have a local copy, omit git clone and run the notebook steps from the repo root. Each starter installs an exact pinned package version.

Launch the browser example

Requires Node.js 20.19+ or 22.12+. The folder is self-contained: npm ci installs exact lockfile dependencies and npm run dev starts the local server. Open the URL Vite prints in your browser.

Shell
git clone https://github.com/qrcode-ai-com/qrcode-barcode-scanner-rust.git
cd qrcode-barcode-scanner-rust/examples/web-vite
npm ci
npm run dev

Run npm run build to output static assets into dist/, and npm run preview to test the built folder.

Launch the Python notebook

Requires Python 3 with the venv module. The first install step enforces file hashes for every package, so JupyterLab is installed in a separate command. Once open, pick Run All inside the notebook.

Shell
git clone https://github.com/qrcode-ai-com/qrcode-barcode-scanner-rust.git
cd qrcode-barcode-scanner-rust
python3 -m venv .venv
.venv/bin/python -m pip install -r binder/requirements.txt
.venv/bin/python -m pip install jupyterlab
.venv/bin/jupyter lab examples/notebooks/scan-images.ipynb

On Windows, look for the executables inside .venv\Scripts\.

Core scanning calls

These snippets are extracted directly from the two starters. In JavaScript, a module Worker initialises the scanner once and invokes scan_image on the chosen image bytes. In Python, scan receives the image bytes plus a profile controlling analysis depth. Both set the time budget to 0 so every scan runs to completion.

// A module worker that owns one scanner. The page posts { id, type: 'load' } once, then
// { id, type: 'scan', bytes, profile } for each image, and gets one reply with the same id:
//   { id, ok: true, version, variant }             after 'load'
//   { id, ok: true, report, ms }                   after 'scan'
//   { id, ok: false, phase, error }                phase: 'load' or 'scan'
// Scanning in a worker keeps the page responsive while an image is decoded.
import { createScannerLoader } from '@qrcode-ai-com/qrcode-barcode-scanner-wasm/auto';

// One loader for the life of this worker. It fetches and compiles the WebAssembly module once.
const load = createScannerLoader();

// 0 removes the time budget: every scan runs to its end.
const BUDGET_MS = 0;

function describe(error) {
  const message = error && error.message !== undefined ? String(error.message) : String(error);
  const qrs = /\[(QRS-\d{3})\]/.exec(message);
  return {
    name: error && error.name ? String(error.name) : 'Error',
    message,
    // A loading failure carries a stable code; a refused input ends with [QRS-xxx].
    code: error && typeof error.code === 'string' ? error.code : null,
    qrs: qrs ? qrs[1] : null,
  };
}

self.onmessage = async ({ data }) => {
  const { id, type } = data;
  let phase = 'load';
  try {
    const scanner = await load();
    if (type === 'load') {
      self.postMessage({ id, ok: true, version: scanner.version(), variant: scanner.variant });
      return;
    }
    phase = 'scan';
    const started = performance.now();
    const report = scanner.scan_image(new Uint8Array(data.bytes), data.profile, undefined,
      undefined, BUDGET_MS);
    self.postMessage({ id, ok: true, report, ms: performance.now() - started });
  } catch (error) {
    self.postMessage({ id, ok: false, phase, error: describe(error) });
  }
};

The Python excerpt forms a single notebook cell. Previous cells import qrcode_barcode_scanner as scanner and read the sample image bytes into sample.

Sample notebook output

Trigger Run All to execute every cell. The seven lines below come from the notebook’s output. The opening three lines list detections across fast, frame and full profiles, each finding the same two codes (sorted by type so code128 appears before qr_code). The fourth line shows the 0 to 100 scannability score computed under full for the first code in the report, here the QR code because QR detections sort first.

Additional cells print environment checks beforehand: Python version, OS platform, installed package version, SHA-256 hash of the module and the PyPI wheel filename. After the score, another cell prints four detail lines per code: for the barcode, its symbology (code128), decoded string (STOCK-4827), payload kind (text, denoting plain text) and “measured as segment” with two endpoints along the scan line.

Text
fast  code128: STOCK-4827 · qr_code: https://qrc-ai.com/76xMa
frame code128: STOCK-4827 · qr_code: https://qrc-ai.com/76xMa
full  code128: STOCK-4827 · qr_code: https://qrc-ai.com/76xMa
Scannability of the first code: 100 out of 100, excellent
White image: no code found, and the scan finished.
Not an image: unsupported or corrupt image: The image format could not be determined [QRS-001]
Set MY_IMAGE to the path of an image, then run this cell again.

The final three lines correspond to the blank image, the non-image file and the last cell waiting for your custom image path.

How the browser demo decodes a barcode

A dedicated Worker runs the scanner. The web page transfers the chosen image bytes to a module Worker, which initialises the library once via createScannerLoader from the /auto entrypoint and calls scan_image.

Smooth UI and local processing. Because decoding executes inside the Worker, the page stays responsive throughout the scan and image data never leaves your device.

Required Vite options. Listing the package under optimizeDeps.exclude ensures its modules locate the adjacent .wasm binary correctly, while worker.format set to es satisfies the /auto loader.

What a barcode scan outputs

Combined sample payload. The test image holds one Code 128 barcode (STOCK-4827) alongside one QR code (https://qrc-ai.com/76xMa). Each detection carries symbology and content.text; keep leading zeros intact and handle product lookups separately.

Symbology mapping and scoring. The symbology field names the printed standard (GS1-128 maps to code128, ITF-14 to itf and ISBN to ean13). Frame skips scoring, whereas fast and full score the first code without certifying label print quality.

Empty scans and invalid files. An image containing no symbol returns an empty array instead of throwing. Non-image inputs raise QRS-001 (Error in JavaScript and ValueError in Python).

Moving from demo to barcode scanning in your codebase

Verify the sample image first, test one of your own files, then drop the scanning snippet into your project.

  1. Step 1

    Decode the sample image

    Launch a demo online or locally and run the sample file. Confirm that it returns STOCK-4827 with symbology Code 128.

  2. Step 2

    Test with your own image

    Upload a file in the Vite page or update the path in the final notebook cell. Inspect the returned text and payload kind.

  3. Step 3

    Integrate the call in your app

    Reuse the Worker setup or Python scan lines, keep the dependency pinned in your lockfile and open your language SDK guide.

Barcode Scanner APIs and licence

These documentation links track the main branch of the scanner repository.

Barcode Scanner examples questions

Online demos, sample output, custom files, empty scans and code reuse.

The Barcode Scanner examples are self-contained starter projects built on the official packages of QR Code & Barcode Scanner, QR Code AI’s open-source MIT library: a Vite web app (available on StackBlitz, GitHub Pages and Hugging Face Spaces) and a Python Jupyter notebook (available on Binder and Google Colab). Every project installs a pinned published release and decodes a sample image so you can verify output before writing code. Both also run locally from the examples folder in the public repository.

No sign-up is needed for StackBlitz, GitHub Pages, Hugging Face Spaces or Binder. StackBlitz boots the Vite project inside your browser, GitHub Pages hosts the static build directly and Binder spins up an ephemeral Python environment (taking a couple of minutes to start and timing out after roughly ten minutes of inactivity). Google Colab runs the exact same notebook but requires signing in with a Google account.

Pick the browser demo first if you are building a website or web app: it demonstrates Worker-based WebAssembly decoding where images stay strictly on the user’s device. Pick the Python notebook if you work in Python or prefer inspecting results cell by cell. For shell scripts or CI pipelines, go straight to the Barcode Scanner CLI.

The bundled sample image contains one Code 128 barcode and one QR code. Scanning returns both detections: the Code 128 barcode holding STOCK-4827 and the QR code carrying https://qrc-ai.com/76xMa. All three profiles (fast, frame and full) detect the exact same pair, and each entry includes its symbology so your code can filter barcodes cleanly.

Every symbology supported by the engine works in the demos. That spans retail codes (EAN-13, EAN-8, UPC-A, UPC-E), linear codes (Code 128, Code 39, Code 93, Codabar, ITF, Telepen), GS1 DataBar and GS1 DataBar Expanded, plus 2D formats (Data Matrix, PDF417, Aztec and MaxiCode). The sample image covers Code 128; upload your own file in the browser app or point to it in the notebook to test other formats.

Not in the browser demo: the decoder runs locally via WebAssembly inside a browser Worker, so your image never leaves your device. The notebook likewise decodes inside its Python process without forwarding images elsewhere. Locally, that process stays on your computer; on Binder or Google Colab, the session runs on remote servers, so only upload test files you are comfortable sharing with those hosts.

Scanning returns every code detected, or an empty list when nothing is found. An empty list is a normal valid result rather than an exception, and the browser demo displays a no-code message. If an image contains only a QR code, that QR entry is returned, so inspect each detection’s symbology before treating it as a barcode. Non-image files behave differently: the engine rejects them with QRS-001 and Python raises ValueError. Both starters include empty and invalid inputs for testing.

Yes. Both the example projects and current scanner packages ship under the MIT licence, letting you copy, customise and deploy them inside open-source or commercial software as long as you retain copyright and licence notices. Check the licensing guide for included third-party notices.

No. Decoding an existing image is completely independent of the QR Code AI creation service and its generation API. The creation service has free creation limits, a seven-day Premium trial triggered when you create your first dynamic QR code or Smart Link, and Premium requirements for ongoing use of affected features. Reading a code does not start that trial, and directly encoded content stays unchanged in the symbol. The scanner itself is open source under the MIT licence.