Introduction

We are releasing Aspose.BarCode FOSS for Python, a pure-Python library for generating standards-compliant 1D and 2D barcodes. The library is published on PyPI as aspose-barcode-foss, carries an MIT license, and has zero external dependencies.

The library supports seven symbologies: Code 128, Code 39, EAN-13, EAN-8, QR Code, UPC-A, and UPC-E. Each barcode renders directly to SVG or PNG. There are no native extensions, no system packages to install, and no graphics drivers required — pip install aspose-barcode-foss is the complete setup on Windows, Linux, and macOS.


Key Features

High-Level Generation API

The top-level generate() function accepts a symbology name and data string, returning a Barcode object. Dedicated per-symbology helpers — code128(), code39(), ean13(), ean8(), qr(), upca(), and upce() — provide type-safe entry points for each format.

import aspose_barcode_foss as barcode

bc = barcode.generate("code128", "ABC123")
svg = bc.to_svg()

Symbology-Specific Encode Options

Each symbology accepts an options class that controls encoding behavior. Code128Options provides encode_mode (AUTO, CODE_A, CODE_B, CODE_C, CODE_AB, CODE_AC, CODE_BC). Code39Options supports BASE and FULL_ASCII modes. QrOptions exposes error_correction_level (L, M, Q, H), version, mask, and encoding_mode (AUTO, NUMERIC, ALPHANUMERIC, BYTE, KANJI).

import aspose_barcode_foss as barcode
from aspose_barcode_foss import QrOptions, QrErrorCorrectionLevel

bc = barcode.qr(
    "https://example.com",
    encode=QrOptions(error_correction_level=QrErrorCorrectionLevel.H),
)
png_bytes = bc.to_png()

Rendering Controls

RenderOptions controls the visual output: scale, dpi, module_width, module_height, quiet_zone, foreground_color, background_color, transparent_background, show_text, font_family, and font_size. Both to_svg() and to_png() accept an optional RenderOptions parameter.

import aspose_barcode_foss as barcode
from aspose_barcode_foss import RenderOptions

bc = barcode.ean13("590123412345")
svg = bc.to_svg(options=RenderOptions(
    scale=2.0,
    foreground_color="#003366",
    quiet_zone=10.0,
    show_text=True,
))

Automatic Check Digits

EAN-13, EAN-8, UPC-A, and UPC-E compute check digits automatically from the data string. You supply only the payload digits; the library appends the correct check digit during encoding.

Input Validation

Each symbology has a dedicated InputParser that validates data before encoding. Invalid characters, incorrect lengths, and format violations are caught early with typed exceptions: InvalidInputError, EncodingError, SymbologyNotFoundError, and UnsupportedCapabilityError — all inheriting from BarcodeError.


Quick Start

pip install aspose-barcode-foss

Generate a Code 128 barcode and write the SVG to a file:

import aspose_barcode_foss as barcode
from aspose_barcode_foss import RenderOptions

bc = barcode.code128("Hello World")
svg = bc.to_svg(options=RenderOptions(show_text=True))

with open("barcode.svg", "w") as f:
    f.write(svg)

Generate a QR code and save it as PNG:

import aspose_barcode_foss as barcode
from aspose_barcode_foss import QrOptions, QrErrorCorrectionLevel

bc = barcode.qr(
    "https://example.com",
    encode=QrOptions(error_correction_level=QrErrorCorrectionLevel.H),
)

with open("qr.png", "wb") as f:
    f.write(bc.to_png())

The library requires Python 3.12 or later.


Supported Formats

SymbologyTypeCheck DigitOptions Class
Code 1281DBuilt-inCode128Options
Code 391DOptionalCode39Options
EAN-131DAutomaticEan13Options
EAN-81DAutomaticEan8Options
QR Code2DBuilt-inQrOptions
UPC-A1DAutomaticUpcaOptions
UPC-E1DAutomaticUpceOptions

Output formats:

FormatExtensionExport
SVG.svg
PNG.png

Open Source & Licensing

The library is MIT licensed. You can use it in commercial applications, modify it, and redistribute it without restriction. The source is available on GitHub. There are no usage tiers, no token limits, and no telemetry. All processing happens locally.


Getting Started