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

Cloudmersive
1 min readApr 28, 2020

--

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 cloudmersive_barcode_api_client.rest 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!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet