Read And Generate QR Code With 5 Lines Of Python Code
Introduction
QR Code is the most popular 2 dimensional barcodes that widely used for document management, track and trace in supply chain and logistics industry, mobile payment, and even the “touchless” health declaration and contact tracing during the COVID-19 pandemic. Comparing to 1D barcode, QR code can be very small in size but hold more information, and also easier for scanning as you can scan it from any direction.
In this article, I would be sharing with you how to use some pure Python packages to generate QR code and read QR code from images.
Generate QR code with Python
To generate QR code, we will use a Python package called qrcode. Below is the pip command to install this package:
#install qrcode together with pillow
pip install qrcode[pil] #or install qrcode if you already have pillow installed
pip install qrcode
As it has dependency to Pillow package, you will need to have this package installed as well. Once you have these packages ready, let’s import the modules at the beginning of our code:
import qrcode
from PIL import Image
Generating a QR code with this qrcode library can be easily done with 1 line of…