QR Code Generator

8.2 · active · verified Sun Apr 05

The `qrcode` library is a pure Python QR Code image generator, enabling users to encode various data types into QR code format. It offers extensive control over QR code appearance, including size, border, error correction levels, and colors. The current stable version is 8.2. The library maintains an active release cadence, with multiple recent releases, including significant updates like version 8.0, indicating ongoing development and support.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates two common ways to generate QR codes: using the convenient `qrcode.make()` shortcut for basic needs, and utilizing the `qrcode.QRCode` class for fine-grained control over parameters like version, error correction, box size, and border. Both examples save the generated QR code as a PNG image, which requires the `Pillow` library to be installed.

import qrcode
import os

# Data to encode
data = "https://checklist.day/"

# --- Simple QR code generation (shortcut) ---
img_simple = qrcode.make(data)
img_simple.save("simple_qrcode.png")
print("Simple QR code saved as simple_qrcode.png")

# --- Advanced QR code generation (QRCode class for more control) ---
qr = qrcode.QRCode(
    version=1, # Controls the size (1-40), None for automatic (fits data)
    error_correction=qrcode.constants.ERROR_CORRECT_L, # Error correction level (L, M, Q, H)
    box_size=10, # Number of pixels per 'box' or module
    border=4, # Number of boxes thick the border should be (minimum 4)
)
qr.add_data(data)
qr.make(fit=True) # Ensures the entire data fits into the QR code

img_advanced = qr.make_image(fill_color="black", back_color="white")
img_advanced.save("advanced_qrcode.png")
print("Advanced QR code saved as advanced_qrcode.png")

# To display in a notebook (requires Pillow and an interactive environment)
# img_advanced.show()

view raw JSON →