Skip to content
IveriumPublic

About

Tiny dependency-free QR code encoder in pure Python, with SVG and PNG output

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

tinyqr

A tiny QR code encoder in one file of pure Python. It outputs SVG and PNG, needs no dependencies (not even Pillow) and runs on Python 3.8+.

It was written for the review-link poster on iverium.nl/google-reviewlink-maken, which runs on a server with a plain Python install.

  • Byte mode (UTF-8), error correction M or Q, versions 1-15 (up to 412 bytes at level M, 292 at Q)
  • Automatic version and mask selection with the standard penalty rules
  • SVG output with one path and crisp edges, so it scales to any size; PNG output via zlib only
  • Verified module-for-module against python-qrcode for every mask, and decoded back with zxing-cpp. Both checks run in CI.

Install

pip install git+https://github.com/Iverium/tinyqr

Or just copy tinyqr/qr.py into your project.

Use

tinyqr "https://www.iverium.nl"              # print it in the terminal
tinyqr "https://www.iverium.nl" -o code.svg
tinyqr "https://www.iverium.nl" -o code.png --scale 10 --ecl M
import tinyqr

tinyqr.svg("https://www.iverium.nl")             # '<svg xmlns=... viewBox="0 0 37 37" ...>'
tinyqr.png("https://www.iverium.nl", scale=10)   # PNG bytes
tinyqr.encode("hello", ecl="Q")                  # list of rows of bools (True = dark), no quiet zone

svg() takes ecl, border (quiet zone, default 4) and css_class. png() takes ecl, border and scale (pixels per module). Text that doesn't fit in version 15 raises ValueError.

Why another QR library?

You often need a QR code in a place where installing packages is a hassle: a small web app on an old server, a script or a serverless function. tinyqr is about 300 lines with no imports beyond struct and zlib. Its structure follows Project Nayuki's well-known reference implementation. For numeric/alphanumeric modes, kanji or versions above 15, use segno or python-qrcode.

Nederlands

tinyqr maakt QR-codes als SVG of PNG met alleen de Python-standaardbibliotheek. Wij gebruiken het voor de gratis Google-reviewlink en QR-poster. Combineer het met google-reviewlink om in één stap een QR-code naar uw Google-reviews te maken.

License

MIT. Made by Iverium Software, web development in Groningen and Drenthe (NL).

About

Tiny dependency-free QR code encoder in pure Python, with SVG and PNG output

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages