Registry / serialization / pyqrcode

pyqrcode

JSON →
library1.2.1pypypi✓ verified 87d ago

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.

pip install pyqrcode
INSTALL
IMPORT
SIG · PYQRCODE
P
pyqrcode
serializationpythonv1.2.1
Install
2.0s avg
Import
8ms
Disk
65MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.1 · 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.940 runs
installs and imports cleanly · install 0.0s · import 0.007s · 65.8MB
glibc
py 3.103.940 runs
installs and imports cleanly · install 2.0s · import 0.007s · 20MB
65MB installed
● package 65MB
Code
Verified usage

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

pyqrcode
import pyqrcode
create
from pyqrcode import create
import pyqrcode.create
The `create` function is directly available in the `pyqrcode` module, not as a submodule. Alternatively, call `pyqrcode.create()` after `import pyqrcode`.

This quickstart generates a QR code for a given URL, saves it as an SVG file, and displays it directly in a compatible terminal. For PNG output, ensure 'pypng' is installed.

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))
pyqrcode --version
Debug
Known issues
gotchaTo 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.
fix
Install `pypng`: `pip install pypng`.
affects: All versions
deprecatedThe 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.
fix
Consider alternatives like `qrcode` for ongoing development or if advanced features and active maintenance are crucial.
affects: 1.2.1 and potentially earlier
gotchaBy 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.
fix
Specify the `error` parameter: `pyqrcode.create('data', error='L')`.
affects: All versions
gotchaNaming 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.
fix
Avoid naming your scripts or variables `pyqrcode`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pyqrcode'
The pyqrcode library is not installed in the current Python environment.
fix
pip install pyqrcode
pyqrcode.errors.PyQRCodereError: PNG output requires PyPNG to be installed.
The optional pypng library, which is necessary for generating PNG images, has not been installed.
fix
pip install pypng
AttributeError: module 'pyqrcode' has no attribute 'write_png'
The 'write_png' method (or similar output methods) was incorrectly called directly on the pyqrcode module instead of on an instance of a QRCode object.
fix
First create a QRCode object, then call 'write_png' on that object. Example: qr = pyqrcode.create('Your data'); qr.write_png('your_code.png')
TypeError: QR code data must be bytes or unicode.
The pyqrcode.create() function was passed a non-string/non-bytes object (e.g., an integer or a list) as the data for the QR code.
fix
Ensure the data passed to pyqrcode.create() is a string or bytes object. Example: qr = pyqrcode.create('123')
Upgrade
Version history
1.2.1latest on PyPI · released Jun 20, 2016
Audit
Dependencies
pypngoptionalRequired for saving QR codes as PNG image files.
Agent activity
11 hits · last 30 days
node
10
Resources
pyqrcode — pip install pyqrcode · libregistry