qrcode

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 11 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README ¶

🔳 qrcode — QR codes for Starlark

Go Reference codecov binary footprint

Generate QR codes from Starlark in four output forms — half-block ASCII, pure ASCII, SVG, and a 1-bit BMP — built on boombuler/barcode.

Overview

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 as ascii, pure_ascii, svg, or bmp.
  • Format templates — template() fills the standard mailto: / 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 with encoding/binary (≈16 KiB), avoiding image/png (+249 KiB) and lossy JPEG (whose ringing artifacts hurt scannability).
  • Bounded by default — every render is size-checked against max_output_bytes before allocating, so an unbounded scale / module_size / quiet_zone cannot 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.

Installation

go get github.com/starpkg/qrcode

Quickstart

load("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 file

A Wi-Fi QR your phone can join, built from a template:

load("qrcode", "template")

print(template("wifi", ssid="Cafe", password="latte123", security="WPA2").ascii())

Starlark API at a glance

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.

Configuration

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.

License

MIT

Documentation ¶

Overview ¶

Package qrcode provides a Starlark module for generating QR codes in four output forms — half-block ASCII, pure ASCII, SVG, and a hand-written 1-bit BMP — with no image/* dependencies (the BMP is emitted with encoding/binary).

encode() runs the QR encoder once (boombuler/barcode) and returns a QR value whose methods render the shared module matrix the four ways.

Index ¶

Constants ¶

View Source
const ModuleName = "qrcode"

ModuleName is the name used in Starlark's load() for this module.

Variables ¶

This section is empty.

Functions ¶

This section is empty.

Types ¶

type Module ¶

type Module struct {
	// contains filtered or unexported fields
}

Module wraps a ConfigurableModule with QR functions.

func NewModule ¶

func NewModule() *Module

NewModule creates a new Module with default configuration.

func (*Module) LoadModule ¶

func (m *Module) LoadModule() starlet.ModuleLoader

LoadModule returns the Starlark module loader.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL