pybarcodes
pybarcodes generates EAN-13, EAN-8, EAN-14, JAN, and CODE39 barcodes as Pillow images, image bytes, or normalized text.
Quick start
Create a barcode from the payload without the check digit. The instance stores the normalized value, including the calculated check digit.
from pybarcodes import EAN13
barcode = EAN13("590123412345")
assert barcode.code == "5901234123457"
barcode.save("ean13.png")
Validation and normalization
Use the class methods when you want to validate user input before creating an instance, or when you only need the normalized text.
from pybarcodes import CODE39, EAN13
EAN13.validate("590123412345")
ean13_value = EAN13.normalize("590123412345")
code39_value = CODE39.normalize("HELLO-123")
Rendering controls
Prefer barcode-aware rendering options over resizing the final bitmap. They keep bar widths, quiet zones, and text placement predictable.
from pybarcodes import EAN13
barcode = EAN13("590123412345")
image = barcode.render(
module_width=3,
bar_height=180,
quiet_zone=24,
font_size=28,
)
image.save("ean13-large.png")
barcode.save("ean13-bars-only.png", draw_text=False)
Bytes output
Use text bytes when you need the normalized barcode value, or image bytes when you need an encoded image for storage, APIs, or web responses.
from pybarcodes import EAN13
barcode = EAN13("590123412345")
text_bytes = barcode.to_text_bytes()
png_bytes = barcode.to_image_bytes(format="PNG")
Type hints
pybarcodes includes inline type annotations and ships a py.typed marker so
type checkers can use the public API types from installed packages.
Contents: