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")
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
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
Metadata
Release files for rubar 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rubar-0.3.0.tar.gz | 27.4 kB | Without provenance | Details for rubar-0.3.0.tar.gz |
Built distributions (wheels)
Total release size: 5.3 MB
Release files / rubar-0.3.0.tar.gz
| Download URL | rubar-0.3.0.tar.gz |
|---|---|
| Size | 27.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7e2988f61afde6f2fbdfee45117a6976947111ccfa63db858cbe4d3700a9626d
|
|
BLAKE2b-256 checksum How to use checksums |
f296037dc0c7ede9663487ad8864120e393a3b6babeb5c9bd27feb93def62a5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Release files / rubar-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | rubar-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 608.8 kB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
06fd4b5504e34729b9c5758a370ac17b9cba72386ad1aeec6a04a66eb3a4341c
|
|
BLAKE2b-256 checksum How to use checksums |
c0a1e9650e74fead3a5d359f1cfeddd3b093ccfbf4cbe687dab08fd22185d3c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Release files / rubar-0.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | rubar-0.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 597.4 kB |
| Tags | CPython 3.13 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
eb0bfab227d00acf467ccc276f5c1a21e0ffed8ebe57ed7ab4086689c0083aa1
|
|
BLAKE2b-256 checksum How to use checksums |
bb9c7ddf83ae8ea48c8eb0c1aff422501eac7c955ce9484bd5f448a121a8b3af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Release files / rubar-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | rubar-0.3.0-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 535.2 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
3f0e767b6555defeaca998492a72aa651acebcafe0f797070e3d91aa71a8a928
|
|
BLAKE2b-256 checksum How to use checksums |
a1c7239fdfa735a58ec353709ad577a0fe7c28e67ca4ea332a9cfdd31ac70c9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Release files / rubar-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | rubar-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 608.7 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
f6e9eb7ae27c1ac74b6778a808e0180a1c259bc045e555f8a554f3d5528e260d
|
|
BLAKE2b-256 checksum How to use checksums |
dc85bcc2e94f8cd0605e442fd9b656f119aa7b86049fa3a711be96f993748865
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Release files / rubar-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | rubar-0.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 597.3 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
0d079b684217d4a31af257d06b70643159be97f0b81f43c38ad4efe6eeea34d2
|
|
BLAKE2b-256 checksum How to use checksums |
420129a75dbf2dc54a307dbb586a281294f9f4948832a6c5217a1b4555531d46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Release files / rubar-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | rubar-0.3.0-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 535.0 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ef8dc7f1fae6009bb99ab6c1fc050502ae231c5a81c7f0abb14b8819b13fdf9a
|
|
BLAKE2b-256 checksum How to use checksums |
ccbfcd91d90037f2cd32fef775b42183936e485f92da37630616ff3557a2c637
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Release files / rubar-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | rubar-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 612.2 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
70e8cc81e79d4d420b087cb23f4ab3fd7c27fc909c1b1308902d255f010b2203
|
|
BLAKE2b-256 checksum How to use checksums |
a831da06fc47c3c8d4b65358d8d5e57cf9725f60ebe8c5795bd031bc53f9a756
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Release files / rubar-0.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | rubar-0.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 599.5 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
0309e13e0ba6759100266666335549cdbeb962164267a8312eefe77616922f2c
|
|
BLAKE2b-256 checksum How to use checksums |
d64490b085c3a0f9b200bea8cd785865c70860a7a35eebe12bab5163302cc1fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Release files / rubar-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | rubar-0.3.0-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 536.5 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
65b345aa2b30f4b8b8a7c84534ec869367595c5d669fd52cd9f72dd7bf085b6a
|
|
BLAKE2b-256 checksum How to use checksums |
20d87547fdb9a86c1231753452a358c120fb6d431b5531db3996074bd13fbcfa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.13
|
Security for rubar 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.