zuke.tools.qr

← Python API reference

@zuke/qr 1.2.0: @zuke/qr — QR codes for any data, from a Zuke build, with no dependency.

Symbols

#

QrSettings

class
class QrSettings(Settings)

Configuration for encoding and rendering a QR code, set through a lambda passed to a QrTasks method. Every setter returns this so calls chain.

  • error_correction(level: Literal['L', 'M', 'Q', 'H']) -> Self

    Set the error-correction level: "L" (~7%), "M" (~15%), "Q" (~25%) or "H" (~30%).

  • boost_error_correction(enabled: bool | None=None) -> Self

    Whether to raise the error-correction level when a higher one fits the same version. On by default; turn it off to get exactly the level asked for.

  • quiet_zone(modules: float) -> Self

    Set the width of the light border around the symbol, in modules (0 to MAX_QUIET_ZONE).

  • invert(enabled: bool | None=None) -> Self

    Swap the colours: light modules become blocks and dark ones spaces. Use it on a terminal whose text is light on dark, where the default rendering shows the code with dark and light exchanged.

  • compact(enabled: bool | None=None) -> Self

    Whether to draw two module rows per line with ▀/▄/█ (the default, which keeps a version-3 code under 20 lines) or one row per line with a two-character ██ cell per module.

#

QrTasks

class
class QrTasks

Task-shaped QR code operations. Each method takes the text to encode (a URL, usually) and an optional settings lambda:

``ts import { QrTasks } from "@zuke/qr";

QrTasks.print("https://zuke.build", (s) => s.errorCorrection("Q")); ``

  • static async encode(ctx: ServiceContext, text: str, configure: Callable[[QrSettings], QrSettings] | None=None) -> object

    Encode text (as UTF-8, byte mode) into a QrCode matrix.

  • static async render_lines(ctx: ServiceContext, text: str, configure: Callable[[QrSettings], QrSettings] | None=None) -> object

    Encode text and render it as terminal lines (see QrSettings.compact).

  • static async render(ctx: ServiceContext, text: str, configure: Callable[[QrSettings], QrSettings] | None=None) -> object

    Encode text and render it as one newline-joined string.