Registry / serialization / qrcode

qrcode

JSON →
library8.2pypypi✓ verified 27d ago

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.

pip install qrcode
INSTALL
IMPORT
SIG · QRCODE
Q
qrcode
serializationpythonv8.2
Install
1.9s avg
Import
65ms
Disk
36MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v8.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.068s · 37.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.9s · import 0.062s · 39MB
36MB installed
● package 36MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

qrcode
import qrcode
QRCode
from qrcode import QRCode
constants
from qrcode import constants

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()
qr --version
Debug
Known issues
gotchaTo 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.
fix
Install `qrcode` with the `pil` extra: `pip install "qrcode[pil]"`.
affects: All versions
gotchaThe 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.
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.
affects: All versions
gotchaChoosing 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`.
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.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'qrcode'
The 'qrcode' library has not been installed in your Python environment.
fix
pip install qrcode
ModuleNotFoundError: No module named 'PIL'
The 'qrcode' library relies on the 'Pillow' (PIL fork) library for image generation, but 'Pillow' is not installed in your Python environment.
fix
pip install Pillow
ValueError: Data too large to fit in QR Code with current settings.
The amount of data you are trying to encode exceeds the capacity of the currently selected QR code version and error correction level.
fix
Increase the 'version' parameter when creating the QRCode object (e.g., from version=1 to version=5 or higher) or reduce the amount of data.
AttributeError: 'QRCode' object has no attribute 'save'
The `save` method is available on the Pillow 'Image' object returned by `make_image()`, not directly on the `qrcode.QRCode` instance itself.
fix
Call `make_image()` on the `QRCode` object to get the image instance before calling `save()`:

```python
import qrcode
qr = qrcode.QRCode(version=1)
qr.add_data('Some data')
img = qr.make_image(fill_color='black', back_color='white')
img.save('my_qrcode.png')
```
Upgrade
Version history
8.2latest on PyPI · released May 1, 2025
Audit
Dependencies
PillowoptionalRequired 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.
Agent activity
25 hits · last 30 days
node
24
Resources
qrcode — pip install qrcode · libregistry