PyQRCode
PyQRCode is a pure Python library for generating QR codes. It supports various output formats including SVG, EPS, PNG (with the optional `pypng` dependency), XBM, and plain text for terminal display. It aims to simplify QR code creation while offering granular control over properties like error correction level, version, and encoding mode. The library automates most of the QR code building process, making it easy to generate codes with just a few lines of code. The current version is 1.2.1, with the last significant update in June 2018, suggesting a maintenance-only release cadence.
Warnings
- gotcha To generate PNG images, the `pypng` library must be installed separately (`pip install pypng`). Without it, calls to `qr_code.png()` will result in an error.
- deprecated The library has not seen significant updates since 2018 (version 1.2.1). While functional, it may lack modern features, performance optimizations, or compatibility with very recent Python versions compared to more actively maintained QR code libraries.
- gotcha By default, `pyqrcode.create()` uses the highest error correction level ('H'). While this makes the QR code more robust to damage, it significantly reduces the data capacity. If you need to encode more data, you might need to manually set a lower error correction level (e.g., 'L', 'M', or 'Q') using the `error` parameter.
- gotcha Naming a Python file or variable `pyqrcode.py` or `pyqrcode` can lead to import conflicts (module shadowing), where Python tries to import your local file/variable instead of the installed `pyqrcode` library.
Install
-
pip install pyqrcode -
pip install pypng
Imports
- pyqrcode
import pyqrcode
- create
from pyqrcode import create
Quickstart
import pyqrcode
import sys
# Create a QR code for a URL
qr_code_url = pyqrcode.create('https://example.com')
# Save as SVG file
qr_code_url.svg('example-url.svg', scale=8)
print("QR code saved as example-url.svg")
# Print to terminal (requires a compatible terminal)
print("\nQR code in terminal:")
print(qr_code_url.terminal(quiet_zone=1))