Skip to main content

larzqr

QR codes from scratch — real Reed-Solomon error correction, all eight masks, zero dependencies.

Most "pure Python" QR libraries stop at drawing squares. larzqr implements the actual standard: Reed-Solomon ECC over GF(256), the finder / timing / alignment patterns, BCH-coded format and version information, and penalty-based mask selection — so the codes it emits are genuinely scannable. No numpy, no pillow, no C extension. Just the standard library.

It covers QR versions 1 through 10 in byte mode (up to ~270 bytes at EC level L), which comfortably fits URLs, Wi-Fi configs, and TOTP provisioning URIs from larztotp.

Install

pip install larzqr

Use

from larzqr import QR

qr = QR("https://example.com")
print(qr.to_text())              # scannable straight from a terminal

qr = QR("otpauth://totp/App:alice?secret=JBSWY3DPEHPK3PXP&issuer=App",
        error_correction="M")    # L, M, Q, or H
qr.to_svg("login.svg", scale=10) # crisp vector output
qr.matrix                        # the raw list-of-lists 0/1 module grid
qr.version, qr.mask              # picked automatically

Why it's correct, not just plausible

QR generators are easy to get almost right and impossible to eyeball. larzqr is anchored to published constants at every layer:

  • Reed-Solomon is checked against the standard's worked v1-M example — data codewords in, the exact ECC bytes [196, 35, 39, 119, 235, 215, 231, 226, 93, 23] out.
  • Format information matches the spec table (M/mask0 = 0x5412, L/mask0 = 0x77C4); version information matches the version-7 constant.
  • GF(256) products are verified against hand-computed values (2 · 128 = 0x1d).
  • Finder patterns, timing patterns, the dark module, and mask selection are all tested as structural invariants.

Tests

python -m unittest discover -s tests -v   # 29 tests

The Larz stack

One of 60+ pure-Python, zero-dependency libraries at github.com/larz-scripter. Pairs naturally with larztotp (turn a provisioning URI into a scannable enrollment code) and larzhtml (drop the SVG straight into a page).

License

MIT (c) larz-scripter

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

larzqr-0.1.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

larzqr-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file larzqr-0.1.0.tar.gz.

File metadata

  • Download URL: larzqr-0.1.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzqr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7e180b62705d96b2126b6a76516e3063e309ad51dcd7496f2938aa88c44f0f76
MD5 1c49418990ce90719737150ff967afad
BLAKE2b-256 2ca80d65fdcf4ab14f0872d7618d15d1588720211e6c21afcbab9b307f16e6b7

See more details on using hashes here.

File details

Details for the file larzqr-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: larzqr-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for larzqr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13c7471ce6f216afeadb17538858d8395a8ad59ca7a3ae21071519076a066d25
MD5 221ca9b78bae7c16aa257d7f5a3eaa7c
BLAKE2b-256 1179689cacdc71e684a1fc489f18bf74a2de202676bdf217fe4011cf714e3ead

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page