{"library":"qrcode","title":"QR Code Generator","description":"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.","status":"active","version":"8.2","language":"en","source_language":"en","source_url":"https://github.com/lincolnloop/python-qrcode","tags":["qrcode","image generation","utility","barcode"],"install":[{"cmd":"pip install qrcode","lang":"bash","label":"Basic installation"},{"cmd":"pip install \"qrcode[pil]\"","lang":"bash","label":"Recommended for image generation (installs Pillow)"}],"dependencies":[{"reason":"Required for generating and saving QR codes as image files (e.g., PNG, JPEG). While `qrcode` can generate the QR code data structure independently, Pillow is essential for rendering it into a visual image.","package":"Pillow","optional":true}],"imports":[{"symbol":"qrcode","correct":"import qrcode"},{"symbol":"QRCode","correct":"from qrcode import QRCode"},{"symbol":"constants","correct":"from qrcode import constants"}],"quickstart":{"code":"import qrcode\nimport os\n\n# Data to encode\ndata = \"https://checklist.day/\"\n\n# --- Simple QR code generation (shortcut) ---\nimg_simple = qrcode.make(data)\nimg_simple.save(\"simple_qrcode.png\")\nprint(\"Simple QR code saved as simple_qrcode.png\")\n\n# --- Advanced QR code generation (QRCode class for more control) ---\nqr = qrcode.QRCode(\n    version=1, # Controls the size (1-40), None for automatic (fits data)\n    error_correction=qrcode.constants.ERROR_CORRECT_L, # Error correction level (L, M, Q, H)\n    box_size=10, # Number of pixels per 'box' or module\n    border=4, # Number of boxes thick the border should be (minimum 4)\n)\nqr.add_data(data)\nqr.make(fit=True) # Ensures the entire data fits into the QR code\n\nimg_advanced = qr.make_image(fill_color=\"black\", back_color=\"white\")\nimg_advanced.save(\"advanced_qrcode.png\")\nprint(\"Advanced QR code saved as advanced_qrcode.png\")\n\n# To display in a notebook (requires Pillow and an interactive environment)\n# img_advanced.show()","lang":"python","description":"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."},"warnings":[{"fix":"Install `qrcode` with the `pil` extra: `pip install \"qrcode[pil]\"`.","message":"To save QR codes as image files (e.g., PNG, JPEG), the Pillow library is required. Installing `qrcode` without the `[pil]` extra will not install Pillow, leading to errors when calling image-related methods like `make_image()` or `save()` if a pure Python PNG encoder (like `pypng`) is not implicitly used or insufficient.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For consistent QR code sizing, explicitly set the `version` parameter (an integer from 1 to 40) in the `QRCode` constructor and potentially set `fit=False` if you want to ensure a specific version is used, handling potential `DataOverflowError` if data doesn't fit. You can also adjust `box_size` for pixel density.","message":"The QR code's visual size and density can vary significantly based on the `version` and `fit` parameters. If `version` is set to `None` (default for `QRCode` class) and `fit` is `True`, `qrcode` will automatically determine the smallest version that fits the data, potentially resulting in different sizes for slightly varied input data. This can be problematic for consistent sizing in layouts.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Carefully select the error correction level based on your use case: `L` (7%), `M` (15%), `Q` (25%), or `H` (30%). Consider the environment where the QR code will be used and the acceptable physical size/density.","message":"Choosing the correct `error_correction` level (L, M, Q, H) is crucial. Higher error correction allows the QR code to be scanned even if partially damaged, but it increases the data density, making the QR code physically larger and potentially harder to print or scan in some scenarios. The default is `ERROR_CORRECT_M`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-05T00:00:00.000Z","next_check":"2026-07-04T00:00:00.000Z"}