QR Codes generation With Python

Ngenge Senior
2 min readFeb 3, 2019

--

QR image link to this post

QR code stands for Quick Response Code and it is used in many scenarios these days. It first appeared in Japan in 1994.QR codes can thus be used to encode

  1. Contact details
  2. Facebook,Instagram,Twitter , WhatsApp ids and more
  3. Event Details
  4. Youtube links
  5. Product details and the list goes on.

It can save you the stress of typing a Youtube link,product details etc

The advantages of QR codes are many but we are here to know how we can generate QR codes in Python

Requirements

We will be generating PNG images with the said library and so our requirements are

  • Pyqrcode module for generating the codes
  • Pypng module for generating png images

Create a virtual environment called qrenve and install the two modules with the following commands

python3 -m venv qrenve
pip install pyqrcode
pip install pypng

With these in place, let us write the function that generates the QR code which is a link to this post.

We create a QRCode instance by calling pyqrcode.create() and write the png file by calling QRCode.png(). The function generates an image url.png

We could also generate an svg image by calling url.svg(‘file_name.svg’)

That is all about the generation and we now have an image with a link to this post. If you have any QRCode scanner app , you can scan the header image for this post and you will find out that it is actually a link to this post.

To know more about , pyqrcode library, check the docs at https://pythonhosted.org/PyQRCode/

Conclusions

With the pyqrcode library, maybe you can create you own QR generator web app with Python and Flask or Django.

Here is a link to the code and image generated on Github https://github.com/ngengesenior/QRCodes

--

--