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

Cloudmersive
1 min readAug 23, 2019

--

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

pip install git+https://github.com/Cloudmersive/Cloudmersive.APIClient.Python.Barcode.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 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'
# 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
try:
# 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)
pprint(api_response)
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:

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet