or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

console-interface.mdconstants.mdcore-generation.mdimage-formats.mdindex.mdstyling.md
tile.json

tessl/pypi-qrcode

QR Code image generator with customizable image formats, error correction levels, and styling options

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/qrcode@7.4.x

To install, run

npx @tessl/cli install tessl/pypi-qrcode@7.4.0

index.mddocs/

QRCode

A comprehensive Python library for generating QR codes with support for multiple image formats, error correction levels, customizable styling, and both command-line and programmatic interfaces. Provides publication-quality QR code images through various backends including PIL, pure Python, and SVG.

Package Information

  • Package Name: qrcode
  • Language: Python
  • Installation: pip install qrcode (basic) or pip install "qrcode[pil]" (with PIL support)

Core Imports

import qrcode

For specific functionality:

from qrcode import QRCode, make
from qrcode import constants
from qrcode import exceptions

Basic Usage

Quick QR Code Generation

import qrcode

# Simple QR code generation
img = qrcode.make('Hello, World!')
img.save('qrcode.png')

# The image type depends on available libraries:
# - PIL available: returns qrcode.image.pil.PilImage
# - PIL not available: returns qrcode.image.pure.PyPNGImage

Advanced QR Code Generation

import qrcode
from qrcode import constants

# Create QRCode instance with custom settings
qr = qrcode.QRCode(
    version=1,                              # Size (1-40, or None for auto)
    error_correction=constants.ERROR_CORRECT_M,  # Error correction level
    box_size=10,                           # Pixels per box
    border=4,                              # Border size in boxes
)

# Add data and generate
qr.add_data('Some data')
qr.make(fit=True)  # Auto-size if version=None

# Create image with custom colors
img = qr.make_image(fill_color="black", back_color="white")
img.save('custom_qrcode.png')

Architecture

QRCode uses a layered architecture that separates QR code logic from image generation:

  • QRCode Class: Core QR generation engine handling data encoding, version calculation, and matrix creation
  • Image Factories: Pluggable image generation backends (PIL, PyPNG, SVG) with consistent interface
  • Module Drawers: Customizable drawing components for individual QR code modules (squares, circles, etc.)
  • Color Masks: Advanced coloring systems for styled QR codes with gradients and patterns
  • Console Interface: Command-line tool supporting all image formats and ASCII terminal output

This design enables flexible output formats while maintaining QR code standard compliance.

Capabilities

Core QR Code Generation

Essential QR code creation functionality including the main QRCode class, quick generation function, version management, and data optimization features.

def make(data=None, **kwargs):
    """Quick QR code generation shortcut function."""

class QRCode:
    """Main QR code generator with full control over all parameters."""
    def __init__(self, version=None, error_correction=constants.ERROR_CORRECT_M, 
                 box_size=10, border=4, image_factory=None, mask_pattern=None): ...
    def add_data(self, data, optimize=20): ...
    def make(self, fit=True): ...
    def make_image(self, image_factory=None, **kwargs): ...

Core QR Code Generation

Image Formats and Factories

Multiple image output formats including PIL-based images, pure Python PNG, and various SVG formats. Each factory provides different capabilities and dependencies.

class PilImage:
    """PIL-based image factory supporting PNG, JPEG, and other PIL formats."""

class PyPNGImage:
    """Pure Python PNG image factory with no external dependencies."""

class SvgImage:
    """Standalone SVG image factory."""

class StyledPilImage:
    """Advanced PIL image factory with custom module drawers and color masks."""

Image Formats

Error Correction and Constants

QR code error correction levels and configuration constants for controlling QR code generation parameters.

ERROR_CORRECT_L = 1    # ~7% error correction
ERROR_CORRECT_M = 0    # ~15% error correction (default)
ERROR_CORRECT_Q = 3    # ~25% error correction
ERROR_CORRECT_H = 2    # ~30% error correction

Constants and Configuration

Console and Output Options

Command-line interface and various output methods including ASCII terminal output, TTY color output, and file generation.

class QRCode:
    def print_ascii(self, out=None, tty=False, invert=False): ...
    def print_tty(self, out=None): ...
    def get_matrix(self): ...

Console Interface

Styling and Customization

Advanced styling capabilities including custom module shapes, color masks, embedded images, and various drawing patterns.

class StyledPilImage:
    """Styled PIL image with custom module drawers and color masks."""

class SquareModuleDrawer:
    """Square module drawer."""

class CircleModuleDrawer:
    """Circular module drawer."""

class QRColorMask:
    """Base class for color masking."""

Styling and Customization

Utility Functions

def run_example(data="http://www.lincolnloop.com", *args, **kwargs):
    """
    Build and display an example QR Code for demonstration purposes.
    
    Parameters:
    - data (str): Data to encode (default: demo URL)
    - *args, **kwargs: Arguments passed to QRCode constructor
    
    Notes:
    - Creates QRCode instance, adds data, generates image, and displays it
    - Mainly for testing and demonstration purposes
    """

Types

class DataOverflowError(Exception):
    """Raised when data exceeds QR code capacity."""

class ActiveWithNeighbors:
    """
    Named tuple containing module state with 3x3 neighborhood information.
    
    Attributes:
    - NW, N, NE: Northwest, North, Northeast neighbors (bool)
    - W, me, E: West, current module, East (bool)  
    - SW, S, SE: Southwest, South, Southeast neighbors (bool)
    
    Notes:
    - Used by advanced module drawers for context-aware rendering
    - Boolean evaluation returns the 'me' attribute value
    """
    NW: bool
    N: bool  
    NE: bool
    W: bool
    me: bool
    E: bool
    SW: bool
    S: bool
    SE: bool

# Type aliases for image factory parameters
from typing import Optional, Type, Union, Any, Dict, List
from qrcode.image.base import BaseImage

# Module matrix type
ModulesType = List[List[Optional[bool]]]