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
| Symbology | Type | Check Digit | Options Class |
|---|---|---|---|
| Code 128 | 1D | Built-in | Code128Options |
| Code 39 | 1D | Optional | Code39Options |
| EAN-13 | 1D | Automatic | Ean13Options |
| EAN-8 | 1D | Automatic | Ean8Options |
| QR Code | 2D | Built-in | QrOptions |
| UPC-A | 1D | Automatic | UpcaOptions |
| UPC-E | 1D | Automatic | UpceOptions |
Output formats:
| Format | Extension | Export |
|---|---|---|
| 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.