Skip to main content

rubar

A Rust library for barcode encoding and rendering with Python bindings.

Code 128 Example

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

Code sets are chosen to minimise the symbol count. Digit runs pack two-per-symbol into Code Set C, so Data("12345678901234") is 7 symbols rather than 14 — which matters because a barcode is normally sized from its symbol count.

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

# GS1-128: Application Identifier (01) + GTIN-14
barcode = Code128([
    FNC1(),             # FNC1 indicates GS1 format
    Data("01"),         # AI: GTIN
    Data("12345678901234"),
])

svg = barcode.render_svg()

Planning spans the whole symbol list, so a digit run split across several Data entries still packs as one run.

A StartA(), StartB() or StartC() symbol pins the initial code set and planning continues from there. It is rarely needed — the planner already picks Code Set C for numeric payloads like the one above.

QR Code

QR Code Example

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, FNC1FNC4, 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rubar-0.3.0.tar.gz (27.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rubar-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (608.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

rubar-0.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (597.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

rubar-0.3.0-cp313-cp313-macosx_11_0_arm64.whl (535.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

rubar-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (608.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

rubar-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (597.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

rubar-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (535.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

rubar-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (612.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

rubar-0.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (599.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

rubar-0.3.0-cp311-cp311-macosx_11_0_arm64.whl (536.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file rubar-0.3.0.tar.gz.

File metadata

  • Download URL: rubar-0.3.0.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for rubar-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7e2988f61afde6f2fbdfee45117a6976947111ccfa63db858cbe4d3700a9626d
MD5 e222fe25ee8507796884b776976f3352
BLAKE2b-256 f296037dc0c7ede9663487ad8864120e393a3b6babeb5c9bd27feb93def62a5f

See more details on using hashes here.

File details

Details for the file rubar-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rubar-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 06fd4b5504e34729b9c5758a370ac17b9cba72386ad1aeec6a04a66eb3a4341c
MD5 603628231b2be1c8fb4db0e46658351f
BLAKE2b-256 c0a1e9650e74fead3a5d359f1cfeddd3b093ccfbf4cbe687dab08fd22185d3c5

See more details on using hashes here.

File details

Details for the file rubar-0.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rubar-0.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 eb0bfab227d00acf467ccc276f5c1a21e0ffed8ebe57ed7ab4086689c0083aa1
MD5 61632f8f55379295b6381f37ede440ac
BLAKE2b-256 bb9c7ddf83ae8ea48c8eb0c1aff422501eac7c955ce9484bd5f448a121a8b3af

See more details on using hashes here.

File details

Details for the file rubar-0.3.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rubar-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3f0e767b6555defeaca998492a72aa651acebcafe0f797070e3d91aa71a8a928
MD5 27c621cdc9b48f2aeeed12085e3abf1c
BLAKE2b-256 a1c7239fdfa735a58ec353709ad577a0fe7c28e67ca4ea332a9cfdd31ac70c9e

See more details on using hashes here.

File details

Details for the file rubar-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rubar-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f6e9eb7ae27c1ac74b6778a808e0180a1c259bc045e555f8a554f3d5528e260d
MD5 c2fc1f43cea506fa37bfd98843156d78
BLAKE2b-256 dc85bcc2e94f8cd0605e442fd9b656f119aa7b86049fa3a711be96f993748865

See more details on using hashes here.

File details

Details for the file rubar-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rubar-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0d079b684217d4a31af257d06b70643159be97f0b81f43c38ad4efe6eeea34d2
MD5 a7cb54e6b52e60e77c6ee962730a06e3
BLAKE2b-256 420129a75dbf2dc54a307dbb586a281294f9f4948832a6c5217a1b4555531d46

See more details on using hashes here.

File details

Details for the file rubar-0.3.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rubar-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ef8dc7f1fae6009bb99ab6c1fc050502ae231c5a81c7f0abb14b8819b13fdf9a
MD5 509c9a5972d3eae9dfcad1ac21442103
BLAKE2b-256 ccbfcd91d90037f2cd32fef775b42183936e485f92da37630616ff3557a2c637

See more details on using hashes here.

File details

Details for the file rubar-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rubar-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 70e8cc81e79d4d420b087cb23f4ab3fd7c27fc909c1b1308902d255f010b2203
MD5 419f749239e444cd02ef749c281152fe
BLAKE2b-256 a831da06fc47c3c8d4b65358d8d5e57cf9725f60ebe8c5795bd031bc53f9a756

See more details on using hashes here.

File details

Details for the file rubar-0.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rubar-0.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0309e13e0ba6759100266666335549cdbeb962164267a8312eefe77616922f2c
MD5 2a3d61d28f6c6644dfc88524af01ef16
BLAKE2b-256 d64490b085c3a0f9b200bea8cd785865c70860a7a35eebe12bab5163302cc1fc

See more details on using hashes here.

File details

Details for the file rubar-0.3.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rubar-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 65b345aa2b30f4b8b8a7c84534ec869367595c5d669fd52cd9f72dd7bf085b6a
MD5 46db4beb7874fb4fb3da71b721ae7868
BLAKE2b-256 20d87547fdb9a86c1231753452a358c120fb6d431b5531db3996074bd13fbcfa

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.0 This release

10 files

0.2.0

5 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page