Skip to main content

Python quick start for the Linux Barcode Scanner SDK

Build a lightweight barcode scanner in Python for Linux. The command-line interface accepts a single image path as input, and the Scanbot SDK license key is embedded directly in the source code.

Create the project and install the Scanbot SDK​

1. Install Python and OpenCV​

sudo apt update
sudo apt install -y python3-venv python3-opencv

2. (Optional) Install CUDA + TensorRT for GPU acceleration​

Requires Jetpack 6.1, CUDA 12.6, and TensorRT 10.3

sudo apt install -y nvidia-l4t-cuda libnvinfer10 libnvinfer-plugin10 libnvonnxparsers10

3. Create and activate a virtual environment​

python3 -m venv .env --system-site-packages
source .env/bin/activate
pip install --upgrade pip setuptools wheel

4. Install the Scanbot SDK​

Replace <SCANBOT_SDK_VERSION> with the version number you want to install.

export SCANBOT_SDK_VERSION=<SCANBOT_SDK_VERSION>
pip install https://github.com/doo/scanbot-sdk-example-linux/releases/download/standalone-sdk%2Fv${SCANBOT_SDK_VERSION}/scanbotsdk-${SCANBOT_SDK_VERSION}-py3-none-linux_aarch64.whl

5. Verify installation​

python -c "import scanbotsdk; print('scanbotsdk OK')"

Performance notes (Jetson only)​

To avoid throttling, temporarily max out clocks and fan:

sudo jetson_clocks --store
sudo jetson_clocks
sudo jetson_clocks --restore

Project layout​

Create a minimal project folder with a single entry-point script

mkdir -p barcode-quickstart-python && \
touch barcode-quickstart-python/main.py

Initialize the Scanbot SDK​

Before using any feature of the Scanbot SDK in Python, initialize the SDK.

import scanbotsdk
from scanbotsdk import LicenseStatus

SCANBOT_LICENSE_KEY = "<SCANBOTSDK-LICENSE-KEY>"

def initialize_sdk() -> None:
scanbotsdk.initialize(SCANBOT_LICENSE_KEY)

license_info = scanbotsdk.get_license_info()
print(f"License Status: {license_info.status}")

if license_info.status != LicenseStatus.OKAY:
raise SystemExit("Invalid or expired license. Exiting.")

Create and run the Barcode Scanner​

After successful initialization, create a scanner configuration and run it on an ImageRef.

def run_barcode_scanner(image: ImageRef):
config = BarcodeScannerConfiguration()
scanner = BarcodeScanner(configuration=config)

result = scanner.run(image=image)

if not result.barcodes:
print("No barcodes found.")
return

for idx, barcode in enumerate(result.barcodes, 1):
print(f"{idx}) {barcode.text} [{barcode.format}]")

Complete example​

import sys
import scanbotsdk
from scanbotsdk import (
LicenseStatus,
DeviceSession,
ImageRef,
BarcodeScanner,
BarcodeScannerConfiguration,
)

SCANBOT_LICENSE_KEY = "<SCANBOTSDK-LICENSE-KEY>"

def initialize_sdk() -> None:
scanbotsdk.initialize(SCANBOT_LICENSE_KEY)
license_info = scanbotsdk.get_license_info()
print(f"License Status: {license_info.status}")
if license_info.status != LicenseStatus.OKAY:
raise SystemExit("Invalid or expired license. Exiting.")

def run_barcode_scanner(image: ImageRef) -> None:
config = BarcodeScannerConfiguration()
scanner = BarcodeScanner(configuration=config )
result = scanner.run(image=image)
if not result.barcodes:
print("No barcodes found.")
return
for idx, barcode in enumerate(result.barcodes, 1):
print(f"{idx}) {barcode.text} [{barcode.format}]")

def main():
if len(sys.argv) < 2:
print("Usage: python main.py <image_path>")
return
image_path = sys.argv[1]
initialize_sdk()

image = ImageRef.from_path(image_path)
run_barcode_scanner(image)

if __name__ == "__main__":
main()

Run​

python main.py /path/to/image_with_barcodes.jpg

🚀 That's it! You've built a minimal barcode scanner in Python on Linux.

💡 In this quick start guide, we use the SDK's default scanner settings. However, you can freely customize the configuration, supported barcode types, and performance options.

Get in touch​

If you need further information or are interested in licensing the Scanbot SDK, please get in touch with our solution experts.