← Back to list

Generate Barcodes or QR Codes with Python

Free Python solution to effortlessly create QR codes, Code 128, EAN-13, and more — no cost, no complexity!

Andrew Wilson · 2025-07-11 08:08 · 0 claps · 2.4 min read
#python #barcode #qr-code #ean-13 #api
Open on Medium ↗

Generate Barcodes or QR Codes with Python

Barcodes power inventory systems, retail checkouts, document tracking, and mobile apps. Automating their generation saves time and reduces errors

This article will introduce how to use **Free Spire.Barcode for Python** — a free, intuitive library to create professional barcodes with minimal code.

Why Choose Free Spire.Barcode?

Zero Costs: No watermarks and completely free for commercial and personal use.

No External APIs: Generate locally without internet.

Export Flexibility: Save as PNG, JPG, BMP image formats.

Customization: Control size, color, text visibility, and margins.

Install the Library

pip install Spire.Barcode.Free

Barcodes Generating APIs

To generate barcodes using the Free Python library, you’ll primarily use the following classes, properties, and methods:

  • BarcodeSettings: Handles all settings for barcode generation. It supports configuring barcode type, data, background color, width/height, margins, resolution, etc.
  • BarcodeSettings.Type: Sets the barcode type.
  • BarcodeSettings.Data: Sets the barcode data.
  • BarcodeSettings.Data2D: Sets the QR code text.
  • BarcodeGenerator: Responsible for rendering the barcode.
  • BarcodeGenerator.GenerateImage(): Generates the barcode image.

Below are the code examples to generate QR codes, Code 128, EAN-13

Generate a Code128 in Python

Best for: Shipping labels, warehouse management

from spire.barcode import *

def WriteAllBytes(fname: str, data):
    with open(fname, "wb") as fp:
        fp.write(data)
    fp.close()

# Create BarcodeSettings object
barcodeSettings = BarcodeSettings()

# Set the code type to Code128
barcodeSettings.Type = BarCodeType.Code128

# Set barcode data
barcodeSettings.Data = "XD00555"

# Code set for Code128 
barcodeSettings.Code128SetMode = Code128SetMode.Auto

# Create BarCodeGenerator object
barCodeGenerator = BarCodeGenerator(barcodeSettings)

# Generate Code128 image 
barcodeimage = barCodeGenerator.GenerateImage()
WriteAllBytes("Code128.png", barcodeimage)

Output:

Code128

Code128

Generate EAN-13 Code in Python

Best for: Retail products, ISBNs

from spire.barcode import *

def WriteAllBytes(fname: str, data):
    with open(fname, "wb") as fp:
        fp.write(data)
    fp.close()

# Create BarcodeSettings object
barcodeSettings = BarcodeSettings()

# Set the code type to EAN13
barcodeSettings.Type = BarCodeType.EAN13

# Set barcode data
barcodeSettings.Data = "5019632805254"

# Create BarCodeGenerator object
barCodeGenerator = BarCodeGenerator(barcodeSettings)

# Generate EAN13 code image 
barcodeimage = barCodeGenerator.GenerateImage()
WriteAllBytes("EAN13.png", barcodeimage)

Output:

EAN13

EAN13

Generate QR Code in Python

Best for: Mobile marketing, Wi-Fi credentials, contact cards

from spire.barcode import *

def WriteAllBytes(fname:str,data):
    fp = open(fname,"wb")
    fp.write(data)
    fp.close()

# Create BarcodeSettings object
barcodeSettings = BarcodeSettings()

# Set the code type to QR Code
barcodeSettings.Type = BarCodeType.QRCode

# Set background color
barcodeSettings.BackColor = Color.get_WhiteSmoke()

# Set the code mode
barcodeSettings.QRCodeDataMode = QRCodeDataMode.Byte

# Set ECL
barcodeSettings.QRCodeECL = QRCodeECL.M

# Set whether to display text at the bottom 
barcodeSettings.ShowTextOnBottom = True

# Set dpi
barcodeSettings.DpiX = 500
barcodeSettings.DpiY = 500

# Set QR code
barcodeSettings.Data2D = "Hello, World"

#  create BarCodeGenerator object
barCodeGenerator = BarCodeGenerator(barcodeSettings)

# Generate the OR code image
barcodeimage = barCodeGenerator.GenerateImage()
WriteAllBytes("QRCode.png", barcodeimage)

Output:

QR Code

QR Code

Conclusion

Free Spire.Barcode for Python democratizes barcode generation — eliminating complex APIs and licensing fees. Whether you’re building an inventory system, e-commerce tool, or student project, this library scales with your needs.

Get Started Now: 🔗 Download Free Spire.Barcode for Python 📖 Online Documentation


메타데이터
post_id
4bb1519dfc7a
slug
generate-barcodes-or-qr-codes-with-python-4bb1519dfc7a
url
https://medium.com/@andrewwil/generate-barcodes-or-qr-codes-with-python-4bb1519dfc7a
canonical_url
https://medium.com/@andrewwil/generate-barcodes-or-qr-codes-with-python-4bb1519dfc7a
author_url
https://medium.com/@andrewwil
status
ok
fetched_at
2026-07-19 01:25:31