Generate Barcode using Python

Step 1: Download and Install Python
Step 2: Open CMD prompt and run the following command to install flask and barcode module
>> pip install flask
>> pip install python-barcode
Step 3: Open the new text document and place the following code
import io
from flask import Flask, send_file, request
import barcode
from barcode.writer import ImageWriter
@app.route(‘/search’, methods=[‘GET’])
def search_data():
    query = request.args.get(‘query’, ”)
    ean = barcode.get(‘code128’, query, writer=ImageWriter())  
    ean.default_writer_options[‘module_height’] = 5.0    
    ean.default_writer_options[‘write_text’] = False
    filename =
    with open(filename, ‘rb’) as bites:
        return send_file(
                     attachment_filename= query + ‘.png’,
if __name__ == “__main__”:  
Step 4: Save the file in .py format. (e.g.
Step 5: Deploy this python web app in Restful web service.
  • January 17, 2019 | 99 views
  • Comments