EAN-13 and Code 128 barcodes as SVG — zero dependencies.
Encode retail EAN-13 product codes and general-purpose Code 128 (ASCII) into a module bitmap and a crisp SVG, with correct check digits and the standard patterns. No image library. Pairs naturally with larzqr when you need 2D codes too.
pip install larzbarcodefrom larzbarcode import ean13, code128, ean13_check_digit
ean13("400638133393").to_svg("product.svg") # 12 digits -> check digit appended
ean13("4006381333931") # or pass 13 (verified)
code128("SHIP-42").to_svg("label.svg")
ean13_check_digit("978014300723") # 4
ean13("4006381333931").modules # the 0/1 bar pattern (95 modules)- EAN-13 check digits are verified against known real codes, and the output
is the fixed 95-module structure with correct guard bars (
101 … 01010 … 101). - Code 128 uses the standard 107-pattern table (validated internally — every pattern's bar/space widths sum to 11, the stop to 13) with the weighted mod-103 checksum.
python -m unittest discover -s tests -v # 16 testsOne of 60+ pure-Python, zero-dependency libraries at github.com/larz-scripter. The 1D companion to larzqr (QR codes).
MIT (c) larz-scripter