Generate QR Code in python

QR codes have become an increasingly popular way of sharing information, and it’s easy to create one in Python using the qrcode library. In this article, we’ll show you how to generate and save a QR code into an image file, so you can share or use it later.

To get started, you’ll need to install the qrcode library using pip. For more information on the library, visit

Install the qrcode library

pip install qrcode

Next, import the qrcode library and create a QR code instance. Set the version, error correction level, box size, and border as desired.

Then, define the data that you want to store in the QR code, and add it to the instance. Finally, make the QR code, create an image from the instance, and save it as an image file with the extension of your choice.


# Import QR Code library
import qrcode

# Create qr code instance
qr = qrcode.QRCode(
    version = 1,
    error_correction = qrcode.constants.ERROR_CORRECT_H,
    box_size = 10,
    border = 2,

# The data that you want to store
data = "Message that you want to display"

# Add data

# Create an image from the QR Code instance
img = qr.make_image()

# Save it somewhere, change the extension as needed:"image.png")

QR codes can be used for a wide variety of purposes, from sharing URLs and contact information to product details and marketing campaigns. By generating and saving a QR code in Python, you can quickly and easily share information with others or use it yourself.

Customizing the appearance of the QR code is also easy with the qrcode library. You can change the colors, add a logo, or modify the size and shape of the QR code to suit your needs.

In conclusion, creating and saving a QR code in Python is a simple and efficient process. With the qrcode library, you can quickly generate QR codes for a variety of purposes and easily share them with others.

Here you can find the souce code on github repo

Explore More Python Posts

Using Twitter API with Python: Getting Tweets & Insights

Learn how to use the Twitter API with Python to get tweet information and insights. Extract valuable data for businesses and researchers with ease.

Read More
Accessing Facebook Data with Python: Examples for Post Likes, Views, and Profile Details

Learn how to access Facebook data using Python and the Facebook API. Get post likes, views, and comments, and retrieve profile details.

Read More
Python Design Patterns: Examples and Best Practices

Learn about Python design patterns with examples and discover best practices for writing maintainable and scalable code.

Read More
How to Use the YouTube API with Python: A Step-by-Step Guide

Learn how to access and retrieve information from YouTube using Python and the YouTube API. Get code examples and step-by-step instructions for impor…

Read More
Top 3 Python Frameworks for Web Development

Discover the most popular and efficient Python frameworks for building dynamic web applications. Get started today!

Read More
Debugging Made Easy with IPDB - The Python Debugger

Revolutionize the way you debug your Python code with IPdb, the advanced interactive debugger that streamlines your debugging process. Say goodbye to…

Read More