url2qr
Zero-dependency QR code generator optimized for URLs. Parallel implementations in Python and Rust, verified to produce bit-exact identical output.
Features
- Byte mode encoding (required for URLs with lowercase letters)
- EC-L error correction (7% recovery, optimized for clean screen display)
- Versions 1-6 (up to 134 characters)
- Fixed mask pattern (no scoring overhead)
- Terminal output with Unicode half-blocks
Installation
Python (pip)
Python (conda)
Rust (cargo)
Or add to your Cargo.toml:
[]
= "0.1"
Usage
Python
# Display in terminal
# Get raw matrix (list of lists, 1=dark, 0=light)
=
Rust
use ;
let matrix = generate_qr.unwrap;
let output = qr_to_terminal.unwrap;
println!;
CLI
# Python
# Rust
Vendoring
The Python module (url2qr.py) is designed to be vendored directly into larger projects. Simply copy the single file into your project. It is licensed under BSD 3-Clause and may be freely vendored into any other BSD 3-Clause software without credit or attribution.
Development
Prerequisites
- Python 3.9+ with pytest and qrcode (test dependency)
- Rust 1.78+ (MSRV)
Setup
# Python
# Rust
&&
Running Tests
# Python tests (validates against qrcode reference package)
# Rust tests (unit + integration with embedded reference matrices)
&&
# Cross-language validation (regenerate vectors and compare)
&&
# Compare the two JSON files
Linting
# Python
# Rust
&& &&
Cross-Language Verification
Both implementations are verified to produce bit-exact identical QR matrices for all test URLs. The test-vectors/ directory contains shared test vectors generated from the Python implementation (which is itself validated against the qrcode reference package). CI runs cross-validation on every push.
Constraints
- Maximum URL length: 134 characters
- Only supports byte mode (URLs with lowercase require this)
- Fixed to EC-L and mask pattern 0
Acknowledgment
This module was developed by Michael Grant from scratch
using Claude. There are quite a few more capable QR code libraries in existence,
most notably the qrcode module used
to drive our unit tests. This module does not fork these other libraries; instead it
was constructed from first principles with significantly reduced functionality in order
to support a particular embedded use case.