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 qrcodeVerified import paths — ran on the pinned version, not inferred.
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.
Install `qrcode` with the `pil` extra: `pip install "qrcode[pil]"`.
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.
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.
pip install qrcode
pip install Pillow
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.
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')
```