Generate QR codes from Starlark in four output forms β half-block ASCII, pure ASCII, SVG, and a 1-bit BMP β built on boombuler/barcode.
qrcode is a starpkg module: starpkg gives Starlark support for necessary
local operations plus simple abstractions over common online services, for ease
of use. QR generation is a purely local capability β no network, no service
credentials β so this module sits firmly on the local side of that line.
- Encode once, render four ways β
encode()runs the encoder a single time; the returned QR renders the shared module matrix asascii,pure_ascii,svg, orbmp. - Format templates β
template()fills the standardmailto:/WIFI:/MECARD:wire formats from simple parameters, so you do not hand-write them. - No
image/*dependency β the raster form is a hand-written 1-bit BMP emitted withencoding/binary(β16 KiB), avoidingimage/png(+249 KiB) and lossy JPEG (whose ringing artifacts hurt scannability). - Bounded by default β every render is size-checked against
max_output_bytesbefore allocating, so an unboundedscale/module_size/quiet_zonecannot amplify a tiny QR into a multi-hundred-megabyte allocation.
For the complete per-builtin reference β signatures, parameters, returns, errors, examples β and the configuration accessors, see docs/API.md.
go get github.com/starpkg/qrcodeload("qrcode", "encode")
qr = encode("https://example.com", level="M")
print(qr.size) # e.g. 25 β module count per side
print(qr.ascii()) # scan it straight from the terminal
print(qr.pure_ascii()) # ASCII-only (# and spaces), two chars per module
svg = qr.svg(module_size=6)
raster = qr.bmp(scale=8) # 1-bit BMP bytes β write to a .bmp fileA Wi-Fi QR your phone can join, built from a template:
load("qrcode", "template")
print(template("wifi", ssid="Cafe", password="latte123", security="WPA2").ascii())Top-level builtins (load("qrcode", β¦)):
encode(content, level?, quiet_zone?)β encode a string/bytes into a QR object.template(kind, level?, quiet_zone?, **params)β build a QR from a named wire format (url,email,wifi,tel,sms,geo,vcard).
QR object (returned by both builtins):
sizeβ attribute: module count per side, excluding the quiet zone.ascii(quiet_zone?)β half-block rendering for terminals; returns a string.pure_ascii(quiet_zone?, on?, off?)β ASCII-only rendering; returns a string.svg(quiet_zone?, module_size?)β scalable vector image; returns a string.bmp(quiet_zone?, scale?)β 1-bit BMP image; returns bytes.
See docs/API.md for the full signatures, return values, errors, template parameters, and examples of every builtin and method above.
The module's options (ec_level, quiet_zone, max_output_bytes) are
configured via environment variables (QRCODE_EC_LEVEL / QRCODE_QUIET_ZONE /
QRCODE_MAX_OUTPUT_BYTES) or per-option get_<key> / set_<key> accessor
builtins, and serve as defaults for encode / template and the render
methods. max_output_bytes is host-only β the memory-DoS cap has a getter
but no set_max_output_bytes, so a script cannot raise it. See the
Configuration section of docs/API.md for the full
option table, defaults, accessors, and the memory-amplification guard.
MIT