Generate a UPC-A code barcode as PNG file in Python

2 min readJan 12, 2022


UPC-A barcodes are used widely to help people identify a product & the manufacturer who created it. They’re really useful for retail in particular, and if your business falls into that category, you’ll want a way to generate these Barcodes easily & efficiently. Thankfully, Cloudmersive has an API for that — the /barcode/generate/upc-a iteration of the Barcode API lets you validate and generate a 1D UPC-A barcode as a PNG file with simple, ready-to-run code. Let’s look at how you can take advantage of this in Python.

To start off let’s install the Python SDK with the following command:

pip install cloudmersive-barcode-api-clientfrom __future__ import print_function
import time
import cloudmersive_barcode_api_client
from import ApiException
from pprint import pprint

Once done, you can copy in the API key authorization snippet:

# Configure API key authorization: Apikey
configuration = cloudmersive_barcode_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'

Now all that’s left is to create the API class instance & complete the callback function using the below snippet. It’s just as simple as that.

# create an instance of the API class
api_instance = cloudmersive_barcode_api_client.GenerateBarcodeApi(cloudmersive_barcode_api_client.ApiClient(configuration))
value = 'value_example' # str | UPC-A barcode value to generate from
# Generate a UPC-A code barcode as PNG file
api_response = api_instance.generate_barcode_upca(value)
except ApiException as e:
print("Exception when calling GenerateBarcodeApi->generate_barcode_upca: %s\n" % e)




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