Fast barcode encoding and rendering with exact module-level geometry
Project description
rubar
A Rust library for barcode encoding and rendering with Python bindings.
Why rubar?
Most barcode libraries make decisions for you: automatic encoding selection, implicit quiet zones, magic checksum handling. This is convenient until you need precise control—especially for GS1-128 barcodes where FNC1 placement matters, or when you need exact geometry for document layout.
rubar takes a different approach:
- Exact geometry — You get module-level bar positions, not opaque images
- Explicit control — FNC1, code set selection, quiet zones are all explicit parameters
- Zero magic — No automatic anything; you specify exactly what you want
What rubar does NOT do
- Layout — No text labels, no human-readable digits below barcodes
- Decoding — Encoding only; use a scanner library for reading
- Implicit quiet zones — Add them explicitly if you need them
Installation
pip install rubar
Usage
Code 128
from rubar import Code128, Data
barcode = Code128([Data("HELLO-123")])
# Get the geometry (module positions)
geom = barcode.geometry()
print(f"Total width: {geom.total_modules} modules")
print(f"Number of bars: {len(geom.bars)}")
# Render to SVG (unitless, scales to any size)
svg = barcode.render_svg()
# Render to PNG (exact pixel dimensions)
png = barcode.render_png(400, 100, unit="px")
GS1-128 with FNC1
GS1-128 barcodes require FNC1 immediately after the start symbol. With rubar, this is explicit:
from rubar import Code128, Data, FNC1, StartC
# GS1-128: Application Identifier (01) + GTIN-14
barcode = Code128([
StartC(), # Start in Code Set C (numeric pairs)
FNC1(), # FNC1 indicates GS1 format
Data("01"), # AI: GTIN
Data("12345678901234"),
])
svg = barcode.render_svg()
QR Code
from rubar import QrCode
qr = QrCode("https://example.com")
# QR geometry is a 2D module grid
geom = qr.geometry()
print(f"QR size: {geom.size}x{geom.size} modules")
svg = qr.render_svg()
png = qr.render_png(200, 200, unit="px")
Other Symbologies
from rubar import Code39, UpcA, Ean8, Itf
code39 = Code39("HELLO")
upc = UpcA("012345678905") # 12 digits with check digit
ean8 = Ean8("12345670") # 8 digits with check digit
itf14 = Itf("00012345678905") # Even-length numeric
Rendering
SVG: Pure Geometry
render_svg() produces a scalable SVG with only a viewBox—no width or height attributes. The viewBox uses module coordinates, so a 95-module barcode has viewBox="0 0 95 1".
svg = barcode.render_svg()
# Embed in HTML/CSS and control size there
PNG: Exact Pixels
render_png() requires explicit dimensions. Three unit modes:
# Pixels (direct)
png = barcode.render_png(400, 100, unit="px")
# Inches (requires dpi)
png = barcode.render_png(2.0, 0.5, unit="in", dpi=300)
# Millimeters (requires dpi)
png = barcode.render_png(50.0, 12.0, unit="mm", dpi=300)
Quiet Zones
Quiet zones (empty space around the barcode) are not added by default. Add them explicitly:
svg = barcode.render_svg(quiet_zone_modules=10)
png = barcode.render_png(400, 100, unit="px", quiet_zone_modules=10)
Integration with rupdf
rubar is the barcode engine for rupdf, a PDF generation library. While designed for that integration, rubar is fully usable as a standalone library for any barcode generation needs.
Supported Symbologies
| Symbology | Class | Input |
|---|---|---|
| Code 128 | Code128 |
List of Data, FNC1–FNC4, StartA/StartB/StartC |
| Code 39 | Code39 |
String (A-Z, 0-9, space, -.$/%+) |
| UPC-A | UpcA |
11 or 12 digit string |
| EAN-8 | Ean8 |
7 or 8 digit string |
| ITF | Itf |
Even-length numeric string |
| QR Code | QrCode |
Any string |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rubar-0.2.0.tar.gz.
File metadata
- Download URL: rubar-0.2.0.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81aad90c05d27a778c6ed18b5354982e86888a994bc09f3d8a0ac603412ef54e
|
|
| MD5 |
25a862eb45472d8d5c668b4ad6462d05
|
|
| BLAKE2b-256 |
4cf1f1d98e639d33111dce10228c7b99a3b14c1519df3d98f8576a867c386372
|
File details
Details for the file rubar-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: rubar-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 606.3 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82766cdb895890526583bc626829243029fc98c0c55fdd99f3fdc04e4cb841a0
|
|
| MD5 |
ab88756a4abcb794b430cd28e9b2fdf6
|
|
| BLAKE2b-256 |
d7a23d0deeba5d8f571d922a1d7464305d47071f41043269e79a6f006c5f1785
|
File details
Details for the file rubar-0.2.0-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: rubar-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 532.2 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e2488a71551ef3a37ddb28f9358c95aa8484c546aa04d44bc81391f2a89e633
|
|
| MD5 |
c9bdba7c2cb9b7d70fc0d020d66a5938
|
|
| BLAKE2b-256 |
b2be6b80a88b845744fecf797bfe40581ab04d7e71c29246a169a3eb91b3fb0b
|
File details
Details for the file rubar-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: rubar-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 609.1 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
856acc5a36d7659acdd5b15a75721136e44c0dfff6a20f8827949b234c8487fe
|
|
| MD5 |
b504495c28d8d5346f20057dca3a52cc
|
|
| BLAKE2b-256 |
0f98a2c4c5b41e7dbf20a80f043b6a49b7dacb5b28d006e20ccbbb1b7f85ae1b
|
File details
Details for the file rubar-0.2.0-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: rubar-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 534.1 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0742c32d33f0e323f874c4f0bed84b4592f670783b1c05f1bdd27106b88e970
|
|
| MD5 |
825680f8c11b607c2e88ed34a4de3938
|
|
| BLAKE2b-256 |
935eee432d1d1bd86ce47bbdaaa27733e7a9632068e271b4ac065261d9502bf5
|