How to Generate a UPC-A Barcode using Python
After acquiring UPC-A barcode numbers for your retail products, your next step is to generate barcode images with those numbers. The below API solution makes that step easy, automatically generating 1D PNG Barcodes from valid UPC-A (12-digit) inputs. This API will make it super easy to complete your barcode workflow with minimal code, and it’s free to use (with a limit of 800 API calls per month) with a free-tier Cloudmersive API key.
To take advantage of this API, first run this command to install the Python SDK:
pip install cloudmersive-barcode-api-client
Next, copy in the imports and 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 | UPC-A barcode value to generate from
try:
# Generate a UPC-A code barcode as PNG file
api_response = api_instance.generate_barcode_upca(value)
pprint(api_response)
except ApiException as e:
print("Exception when calling GenerateBarcodeApi->generate_barcode_upca: %s\n" % e)
It’s just that easy — only a few lines of code and you’re set up to generate barcodes at will. To get your free-tier API key, visit our website and register a free account.