Python and Segno - Generating QR codes in bulk

As you know, QR code is a graphic or an image having some information hidden within it. This information has some limits in size but mostly allows to store data related communication. QR code can be scanned by a scanner and information gets transferred to that device. It's a very easy and efficient way to quickly transfer information in the device and the device can take appropriate action after scanning is done.

 

Now, to generate QR codes, there are many paid and free tools available online and offline. There are many libraries or frameworks as well where you can embed this capability into your project.

Here is one of my favourite libraries Segno, which is a python-based module and can be used to build your own QR generator tool. 

 

Herein is a simple example that takes data from CSV and generates bulk QR codes.

import csv

import segno

# read the CSV file
with open('file.csv', 'r') as f:
    reader = csv.reader(f)
    your_list = list(reader)
    # iterate over the list
    for i in your_list:
        codefromcsv = i[0]
        # trim string and remove spaces
        codefromcsv = codefromcsv.replace("\ufeff", "")
        # convert string to int
        codefromcsv = int(codefromcsv)
        print(codefromcsv)  # print the list
        qrcode = segno.make(codefromcsv, micro=False, mode='numeric')
        qrcode.save("./output/" + str(codefromcsv) + '.pdf', scale=10)

 

Tags