Dev Center
Table of contents

Getting Started with Dynamsoft Barcode Reader Python Edition

In this guide, you will learn step by step on how to build a barcode reading application with Dynamsoft Barcode Reader (DBR) SDK using Python.

System Requirements

  • Operating Systems:
    • Windows x64
    • Linux (x64, ARM32, ARM64)
    • macOS (10.15+)
  • Python Versions:
    • Python 3.12
    • Python 3.11
    • Python 3.10
    • Python 3.9
    • Python 3.8
    • Python 3.7
    • Python 3.6
    • Python 3.5 (for versions below DBR 7.5)
    • Python 2.7 (for versions below DBR

Note: Dynamsoft Barcode Reader provides both online and offline license options. The online license option might not work in an environment that doesn’t have network connection. In such case, you can get an offline trial license key via Customer Portal or by contacting us.


Start terminal or command prompt to run the following command:

pip install dbr

Build Your First Application

Let’s start by creating a console application which demonstrates how to use the minimum code to read barcodes from an image file.

You can download the entire source code here.

Create a New Project

Create a new source file named

Include the Library

Import dbr package in the source file.

   from dbr import *

Initialize a Barcode Reader Instance

  1. Initialize the license key.

    error = BarcodeReader.init_license("<insert DBR license key here>")
    if error[0] != EnumErrorCode.DBR_OK:
       # Add your code for license error processing
       print("License error: "+ error[1])

    Please replace <insert DBR license key here> with a valid DBR license key. You can request a free trial from Customer Portal.

  2. Create an instance of Dynamsoft Barcode Reader.

    reader = BarcodeReader.get_instance()
    if reader != None:
       # Add your code here to call decoding method, process barcode results and so on
       # ...
       # Recycle the instance

Configure the Barcode Scanning Behavior

  1. Set barcode format and count to read.

    settings = reader.get_runtime_settings()
    settings.barcode_format_ids = EnumBarcodeFormat.BF_ALL
    settings.barcode_format_ids_2 = EnumBarcodeFormat_2.BF2_POSTALCODE | EnumBarcodeFormat_2.BF2_DOTCODE
    settings.excepted_barcodes_count = 10

    For better performance, we recommend that you only enable the barcode formats your application requires. Check out Barcode Format Enumeration for fully supported barcode formats.

    If you know exactly the count of barcodes you want to read, specify excepted_barcodes_count to speed up the process and improve the accuracy.

    The Barcode Reader SDK comes with a large array of runtime settings to optimize the performance of the library. To learn about all the runtime settings, please visit the RuntimeSettings API page. To learn more about the cases and situations in which the settings can help, please visit the Explore Features page.

Decode and Output Results

  1. Decode barcodes from an image file.
  2. Get and output barcode results.

       image_path = r"[INSTALLATION FOLDER]/Images/AllSupportedBarcodeTypes.png"
       results = reader.decode_file(image_path)
       if results != None:
          i = 0
          for text_result in results:
             print("Barcode " + str(i))
             print("Barcode Format : " + text_result.barcode_format_string)
             print("Barcode Text : " + text_result.barcode_text)
             i = i+1
    except BarcodeReaderError as bre:

    For the error handling mechanism, the SDK throws BarcodeReaderError for each function. You can add code for exception handling based on your needs.

    The SDK returns multiple barcode information items, including barcode count, barcode format, barcode text, location, barcode raw data, etc. Check out TextResult for fully supported result data.

Release Resource

Destroy the instance to release all resources.

if reader != None:

Build and Run the Project

  1. Start terminal or command prompt and change to the target directory where located in.
  2. Run the sample

You can download the entire source code here.

Next Steps

This page is compatible for:

Version 7.5.0

Is this page helpful?

YesYes NoNo

In this article:

latest version

  • Latest version
  • Version 10.x
    • Version 10.2.0
    • Version 10.0.20
    • Version 10.0.10
    • Version 10.0.0
  • Version 9.x
    • Version 9.6.40
    • Version 9.6.30
    • Version 9.6.20
    • Version 9.6.10
    • Version 9.6.0
    • Version 9.4.0
    • Version 9.2.0
    • Version 9.0.0
  • Version 8.x
    • Version 8.8.0
    • Version 8.6.0
    • Version 8.4.0
    • Version 8.2.0
    • Version 8.1.2
    • Version 8.1.0
    • Version 8.0.0
  • Version 7.x
    • Version 7.6.0
    • Version 7.5.0
Change +