Web Demos

BARCODE READER SDK DEMO

Explore the flexibe barcode reading settings to optimize for your specific usage scenario.

WEB TWAIN SDK DEMO

Try the most popular web scanner features: scan images, import local images and PDF files, edit, save to local, upload to database, and etc.

BARCODE READER JAVASCRIPT DEMO

Transform any camera-equipped devices into real-time, browser-based barcode and QR code scanners.

MRZ SCANNER WEB DEMO

Detects the machine-readable zone of a passport, scans the text, and parses into human-readable data.

APP STORE DEMOS

BARCODE READER SDK FOR IOS

BARCODE READER SDK FOR ANDROID

VIEW MORE DEMOS >
Dev Center
Table of contents

Thanks for downloading Dynamsoft Barcode Reader Package!

Your download will start shortly. If your download does not begin, click here to retry.

User Guide for Python

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)1
    • macOS (10.15+)
  • Python Versions:
    • 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 7.2.2.3)

1 On AWS Lambda, DBR Python can only be used with a license 1.0 key. License 2.0 keys and above are currently not supported by DBR Python on AWS Lambda.

Installation

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 DBRPythonSample.py.

Include the Library

Import dbr package in the source file.

   from dbr import *

Initialize a Barcode Reader Instance

  1. Initialize the license key.

    BarcodeReader.init_license("<insert DBR license key here>")
    

    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()
    

Configure the Barcode Scanning Behavior

DBR provides multiple APIs for you to customize the barcode scanning behavior. Here we set the barcode format and barcode 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 = 32
   reader.update_runtime_settings(settings)

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.

Decode and Output Results

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

    try:
       image = r"[INSTALLATION FOLDER]/Images/AllSupportedBarcodeTypes.png"
       text_results = reader.decode_file(image)
       if text_results != None:
          for text_result in text_results:
             print("Barcode Format : " + text_result.barcode_format_string)
             if len(text_result.barcode_format_string) == 0:
                print("Barcode Format : " + text_result.barcode_format_string_2)
             else:
                print("Barcode Format : " + text_result.barcode_format_string)
             print("Barcode Text : " + text_result.barcode_text)
    except BarcodeReaderError as bre:
       print(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.

del reader

Build and Run the Project

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

You can download the entire source code of this simple sample here.

Find more Dynamsoft Barcode Reader Python samples in the Github repository.

This page is compatible for:

Version 7.5.0

Is this page helpful?

YesYes NoNo

In this article:

latest version

  • Latest version
  • Version 9.0.0
  • 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.6.0
  • Version 7.5.0
Change +
© 2003–2022 Dynamsoft. All rights reserved.
Privacy Statement / Site Map / Home / Purchase / Support