1. Products
  2.   Aspose.BarCode
  3.   Aspose.BarCode FOSS for Python

Aspose.BarCode FOSS for Python

Open-source Python library for generating standards-compliant 1D and 2D barcodes. MIT licensed, pure Python, renders to SVG and PNG.

Open-Source Python Library for Barcode Generation

Aspose.BarCode FOSS for Python is a free, open-source library for generating standards-compliant barcodes in pure Python. Install it with pip install aspose-barcode-foss and start creating Code 128, Code 39, EAN-13, EAN-8, QR Code, UPC-A, and UPC-E barcodes. Each barcode renders directly to SVG or PNG with no native dependencies.

The library exposes a high-level generate() function and per-symbology helpers such as barcode.code128(), barcode.qr(), and barcode.ean13(). Every call returns a Barcode object with .to_svg() and .to_png() methods for immediate output. Rendering options including scale, DPI, module dimensions, colors, quiet zone, and human-readable text visibility are controlled through RenderOptions.

Because the library is pure Python with no native Office or imaging dependencies, it runs identically on Windows, Linux, and macOS, including Docker containers and CI runners. The codebase is MIT-licensed and hosted on GitHub. For enterprise features and support, see Aspose.BarCode for Python — Enterprise Product.

Barcode Generation

  • Seven symbologies: Code 128, Code 39, EAN-13, EAN-8, QR Code, UPC-A, and UPC-E.
  • High-level API: Call barcode.generate("code128", "data") to create any supported barcode by name.
  • Dedicated helpers: Use barcode.code128(), barcode.qr(), barcode.ean13(), barcode.ean8(), barcode.upca(), and barcode.upce() for type-safe generation.
  • Encoding options: Control encode mode, check digits, error correction level, and GS1 via Code128Options, Code39Options, QrOptions, and symbology-specific option classes.
  • Automatic check digits: EAN-13, EAN-8, UPC-A, and UPC-E compute check digits automatically from the data string.

Where Aspose.BarCode FOSS Can Be Used

  • Product labeling: Generate EAN-13 and UPC-A barcodes for retail packaging.
  • Inventory management: Create Code 128 labels for warehouse and logistics workflows.
  • QR code campaigns: Produce QR codes for marketing materials, event tickets, and mobile links.
  • Shipping and logistics: Generate Code 39 and Code 128 barcodes for shipment tracking labels.

Rendering and Output

  • SVG output: Call barcode.to_svg() to get a standards-compliant SVG string.
  • PNG output: Call barcode.to_png() to get PNG image bytes.
  • RenderOptions: Control scale, dpi, module_width, module_height, quiet_zone, foreground_color, background_color, transparent_background, show_text, font_family, and font_size.
  • Human-readable text: Symbology-specific TextLayoutPolicy implementations handle text placement below each barcode type.
  • Renderer architecture: PngRenderer and SvgRenderer implement the Renderer interface for extensible output.

Developer Experience

Aspose.BarCode FOSS is installable with pip install aspose-barcode-foss. There are no native libraries or system packages to install. The library requires Python 3.12 or later.

The API is built around Barcode, EncodeOptions, RenderOptions, and SymbologyRegistry, covering the full generation-to-rendering pipeline. Each symbology is defined by a SymbologyDefinition that bundles a parser, encoder, profile, and text layout policy. The codebase is MIT-licensed, hosted on GitHub, and accepts contributions.

Symbology Configuration

  • Code 128 modes: Select AUTO, CODE_A, CODE_B, CODE_C, or mixed-set modes via Code128EncodeMode.
  • Code 39 modes: Choose BASE or FULL_ASCII encoding with optional check digit via Code39Options.
  • QR options: Set error_correction_level (L, M, Q, H), version, mask, and encoding_mode (AUTO, NUMERIC, ALPHANUMERIC, BYTE, KANJI) via QrOptions.
  • Registry system: SymbologyRegistry stores all definitions and resolves symbologies by canonical name or alias.
  • Profile metadata: Each symbology’s SymbologyProfile provides defaults, capabilities, spec references, and known limitations.

Error Handling

  • Typed exceptions: BarcodeError is the base, with EncodingError, RenderingError, InvalidInputError, SymbologyNotFoundError, UnsupportedFeatureError, and UnsupportedCapabilityError.
  • Input validation: Each InputParser validates data before encoding, catching invalid characters and format violations early.
  • Capability checks: Unsupported features (e.g., binary input for Code 39) raise UnsupportedCapabilityError with a descriptive message.

Generate a Code 128 Barcode

Create a Code 128 barcode with the high-level generate() function and render it to SVG.

import aspose_barcode_foss as barcode
bc = barcode.generate("code128", "Hello World")
svg_string = bc.to_svg()
print(svg_string[:80])

Create a QR Code with Custom Options

Generate a QR Code with specific error correction and render to PNG bytes.

import aspose_barcode_foss as barcode
from aspose_barcode_foss import QrOptions, QrErrorCorrectionLevel
bc = barcode.qr("https://example.com", options=QrOptions(
    error_correction_level=QrErrorCorrectionLevel.H
))
png_bytes = bc.to_png()
with open("qr.png", "wb") as f:
    f.write(png_bytes)

Render with Custom Appearance

Use RenderOptions to control scale, colors, and quiet zone for any barcode.

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

Frequently Asked Questions

What license does Aspose.BarCode FOSS for Python use?

The library is released under the MIT License. You can use, modify, and redistribute it in both open-source and commercial projects without royalties.

Which barcode symbologies are supported?

The library supports seven symbologies — Code 128, Code 39, EAN-13, EAN-8, QR Code, UPC-A, and UPC-E.

What output formats are available?

Barcodes render to SVG via to_svg() and PNG via to_png(). The to_pdf() method exists in the API but raises NotImplementedError in the current release.

How do I install Aspose.BarCode FOSS for Python?

Run pip install aspose-barcode-foss. The library requires Python 3.12 or later. It is pure Python with no native dependencies.

Can I control the visual appearance of the barcode?

Yes. Pass a RenderOptions object to to_svg() or to_png() to control scale, DPI, module dimensions, colors, quiet zone, and human-readable text.

What Python versions are supported?

Aspose.BarCode FOSS requires Python 3.12 or later. It is pure Python with no native or C-extension dependencies.

Can I generate barcodes in batch?

Yes. Create a single BarcodeService instance and call generate() in a loop for each data value. Each call returns a Barcode object that you render independently with to_svg() or to_png().

How do I configure per-symbology encoding options?

Pass a symbology-specific options object (e.g. Code128Options, QrOptions, Ean13Options) as the encode parameter to BarcodeService.generate(). Each options class exposes properties specific to that symbology, such as encode_mode for Code 128 or error_correction_level for QR Code.

  

Support and Learning Resources

 English