Kalebu Jordan

Become a Pro Python Developer

Hello Pythonista, In this article I will share with you how to programmatically generate QRcode in Python, we go do this in less than 5 lines of code.


To follow through with this tutorial you need to have a QRcode python library installed on your computer.


pip install qrcode

Let’s get started

To create a barcode using the QRcode library is straight forward we just use the make ( ) method to do it just as shown in the example below;

>>> import qrcode
>>> img = qrcode.make('Codebook price')
>>> img.save('data.png')


Once you run the above script it will generate an image with a barcode on your project directory with name data.png.

Sample project

Let’s assume you own an electronics store, where you sell various electronics components, and you would like each component in your store to have it’s own QRcode to simplify selling.

You can use the knowledge we just learned above to do this, whereby you gonna create a list of all the products in your store using python list.

Then at last you just iterate over the list consisting of component descriptions and then generate the QRcode accordingly just as shown below

import qrcode 

products = ['Arduino', 'Raspberry Pi', 'Resistor', 'Codebook Manual']
for product in products:

Output :

When the above code is ran, it going to generate images with barcode of all elements present in our products list.

Hope you find it interesting, now don’t be shy share it with fellow developers on how easy its to create QRcode in python.

I recommend to also check these based on your interest;

In case of any suggestion or comment, drop it in the comment box and I will get back to you ASAP.

One thought on “learn how to generate QRcode in Python

Leave a Reply


Enjoy this blog? Please spread the word :)

%d bloggers like this: