How to Generate a QR Code in Python

QR Codes have integrated themselves as a major part of commercial sales and user interfacing, particularly as businesses have needed to switch to a touchless information sharing format for documents like menus and maps. The following API will allow you to generate a QR code as a PNG file for any kind of information storage and sharing you might require. The input for the function should be the QR code text that you want converted into your barcode. When not used to hold pricing data, the text is often a URL or other transitional piece of text that will lead to a separate, formatted document.

Image for post
Image for post

To run the API, you can use this command to install the SDK:

pip install cloudmersive-barcode-api-client

Then, you can call the function:

from __future__ import print_function
import time
import cloudmersive_barcode_api_client
from cloudmersive_barcode_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_barcode_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# 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
try:
# Generate a QR code barcode as PNG file
api_response = api_instance.generate_barcode_qr_code(value)
pprint(api_response)
except ApiException as e:
print("Exception when calling GenerateBarcodeApi->generate_barcode_qr_code: %s\n" % e)

The API Key for this function can be retrieved at no cost and with no commitment on the Cloudmersive website. This will give you access to 800 monthly calls across our entire API library.

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