How to generate a QR code barcode as a PNG file in Python

Let’s make generating QR codes incredibly easy. First thing’s first: use pip installer to add our barcode API client.

pip install git+

Next, we simply call generate_barcode_qr_code and input the information we wish to encode.

from __future__ import print_function
import time
import cloudmersive_barcode_api_client
from import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_barcode_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['Apikey'] = 'Bearer'
# create an instance of the API class
api_instance = cloudmersive_barcode_api_client.GenerateBarcodeApi(cloudmersive_barcode_api_client.ApiClient(configuration))
value = 'value_example' # str | QR code text to convert into the QR code barcode
# Generate a QR code barcode as a PNG file, a type of 2D barcode which can encode free-form text information
api_response = api_instance.generate_barcode_qr_code(value)
except ApiException as e:
print("Exception when calling GenerateBarcodeApi->generate_barcode_qr_code: %s\n" % e)

For example, we might input this sentence: “Generating QR codes is easy!” and we will get the following image:

Image for post
Image for post

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store