DEV Community

Cover image for Generate QR codes in Python
petercour
petercour

Posted on

Generate QR codes in Python

QR code a type of matrix barcode first designed in 1994 for the automotive industry in Japan. These days it's used in many places like banking, cryptocurrency, advertisements and more.

Did you know you can generate these codes with Python? You should know the Python programming language. But even without to much practice, you can generate them.

Install the qrcode module

pip install qrcode
Enter fullscreen mode Exit fullscreen mode

Then you can load it in Python

#!/usr/bin/python3
import qrcode
img = qrcode.make('hello world')
img.save('test.png')
Enter fullscreen mode Exit fullscreen mode

This will output the QR code as an image (test.png).

So it's that easy. How much data can you store on a QR code?

According to stackoverflow

QR codes have three parameters: 
Datatype, size (number of 'pixels') and error correction level. 
How much information can be stored there also depends on these   
parameters. 
Enter fullscreen mode Exit fullscreen mode
  • Numeric only Max. 7,089 characters
  • Alphanumeric Max. 4,296 characters
  • Binary/byte Max. 2,953 characters (8-bit bytes)

You may be able to zip your data and bypass this limit to some extend.

Related links:

Top comments (1)

Collapse
 
ameek profile image
ameekaziz

Thanks, great for me as a head strat!