Generate a EAN-13 code barcode as PNG file in Python

Cloudmersive
2 min readJan 11, 2022

If you’re selling a product online or in-store in Europe, chances are high that you’ve run into EAN-13 barcodes before. They’re a standard barcode for most commercial products in Europe, so if you’re selling products there, you’ll likely need to generate a LOT of them. Cloudmersive’s Barcode API allows you to validate and generate EAN-13 barcodes as a PNG file, making this administrative process easy and efficient for your business.

To get started, you’ll first need to install the Python SDK, which can be done using the below code:

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

After that, you can go ahead and copy in the rest of the callback function — starting with API key authorization:

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

Followed by API class instance creation:

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

--

--

Cloudmersive

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