How to generate a EAN-8 barcode as a PNG in Python

It is quite a process to set up EAN-8 barcode generation from the ground up. So why waste your time when an API can just do it for you? Here I will be showing you how to set up and run just such an API. Let’s dive in.

We need to install our client first. Let’s use pip install for this task.

pip install cloudmersive-barcode-api-client

We will be using generate_barcode_ean8, and its function call code is laid out below.

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 | Barcode value to generate fromtry:# Validates and generate a EAN-8 barcode as a PNG file, a type of 1D barcodeapi_response = api_instance.generate_barcode_ean8(value)pprint(api_response)except ApiException as e:print("Exception when calling GenerateBarcodeApi->generate_barcode_ean8: %s\n" % e)

Now we pass in our value, which will be used to generate our barcode. Our return will be the PNG file for that barcode, simple as that. For more barcode functions like this, check out what else this API can do in the documentation.

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