How to generate a UPC-E barcode as a PNG file in Python

Barcodes have an important place in many businesses, but handling them in Python can be a bit tricky. Responding to this, we have a solution for you in the form of an API that can generate UPC-E barcodes (among others). Let’s get started on the setup process.

First is our client installation, using this command for pip install:

pip install cloudmersive-barcode-api-client

Now for our function call for generate_barcode_upce:

from __future__ import print_functionimport timeimport cloudmersive_barcode_api_clientfrom import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = 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 classapi_instance = cloudmersive_barcode_api_client.GenerateBarcodeApi(cloudmersive_barcode_api_client.ApiClient(configuration))value = 'value_example' # str | UPC-E barcode value to generate fromtry:# Validates and generate a UPC-E barcode as a PNG file, a type of 1D barcodeapi_response = api_instance.generate_barcode_upce(value)pprint(api_response)except ApiException as e:print("Exception when calling GenerateBarcodeApi->generate_barcode_upce: %s\n" % e)

Now we just feed our desired value into generate_barcode_upce and the API will handle all the rest on its end. What a snap!

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