DEV Community

Cover image for Generate QR codes in Python
petercour
petercour

Posted on

16 6

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:

Heroku

Deliver your unique apps, your own way.

Heroku tackles the toil — patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Learn More

Top comments (1)

Collapse
 
ameek profile image
ameekaziz

Thanks, great for me as a head strat!

Jetbrains image

Build Secure, Ship Fast

Discover best practices to secure CI/CD without slowing down your pipeline.

Read more

👋 Kindness is contagious

Explore this insightful post in the vibrant DEV Community. Developers from all walks of life are invited to contribute and elevate our shared know-how.

A simple "thank you" could lift spirits—leave your kudos in the comments!

On DEV, passing on wisdom paves our way and unites us. Enjoyed this piece? A brief note of thanks to the writer goes a long way.

Okay