Constants Module

The constants module provides convenient access to commonly used enums, constants, and utilities for working with SegnoMMS configurations.

Enums

ModuleShape

class segnomms.config.enums.ModuleShape(*values)[source]

Base module shape types.

SQUARE

Traditional square modules

CIRCLE

Circular modules (may have gaps)

ROUNDED

Square with rounded corners

DOT

Small circular dots

DIAMOND

45-degree rotated square

STAR

5-pointed star modules

HEXAGON

Hexagonal modules

TRIANGLE

Triangular modules

SQUIRCLE

Superellipse shape (between square and circle)

CROSS

Cross/plus shaped modules

CONNECTED

Basic connected style with rounded corners

CONNECTED_EXTRA_ROUNDED

Extra smooth curves using quadratic beziers

CONNECTED_CLASSY

Boundary-focused styling with strategic rounding

CONNECTED_CLASSY_ROUNDED

Classy style with extra-rounded corners

SQUARE = 'square'
CIRCLE = 'circle'
ROUNDED = 'rounded'
DOT = 'dot'
DIAMOND = 'diamond'
STAR = 'star'
HEXAGON = 'hexagon'
TRIANGLE = 'triangle'
SQUIRCLE = 'squircle'
CROSS = 'cross'
CONNECTED = 'connected'
CONNECTED_EXTRA_ROUNDED = 'connected-extra-rounded'
CONNECTED_CLASSY = 'connected-classy'
CONNECTED_CLASSY_ROUNDED = 'connected-classy-rounded'
__str__()[source]

Return the enum value for string representation.

Return type:

str

Available module shapes:

  • SQUARE - Classic square modules

  • CIRCLE - Circular dots

  • ROUNDED - Rounded squares

  • DOT - Small dots with gaps

  • DIAMOND - Diamond shapes

  • STAR - Star shapes

  • HEXAGON - Hexagonal modules

  • TRIANGLE - Triangle shapes

  • SQUIRCLE - Superellipse shapes

  • CROSS - Plus/cross shapes

  • CONNECTED - Connected shapes with pill-style merging

  • CONNECTED_EXTRA_ROUNDED - Extra rounded connected shapes

  • CONNECTED_CLASSY - Classy connected shapes

  • CONNECTED_CLASSY_ROUNDED - Classy rounded connected shapes

Example:

from segnomms.constants import ModuleShape
from segnomms import write
import segno

qr = segno.make("Hello World")
with open('output.svg', 'w') as f:
    write(qr, f, shape=ModuleShape.CIRCLE.value, scale=10)

FinderShape

class segnomms.config.enums.FinderShape(*values)[source]

Finder pattern shape types.

SQUARE

Traditional square finder patterns

ROUNDED

Rounded square finder patterns

CIRCLE

Circular finder patterns

SQUARE = 'square'
ROUNDED = 'rounded'
CIRCLE = 'circle'
__str__()[source]

Return the enum value for string representation.

Return type:

str

Available finder pattern shapes:

  • SQUARE - Square finder patterns

  • ROUNDED - Rounded finder patterns

  • CIRCLE - Circular finder patterns

Constants

Shape Collections

segnomms.constants.VALID_SHAPES: list[ModuleShape]

List of all valid module shapes available in SegnoMMS.

segnomms.constants.CONNECTED_SHAPES: list[ModuleShape]

List of connected shape variants (CONNECTED, CONNECTED_EXTRA_ROUNDED, CONNECTED_CLASSY, CONNECTED_CLASSY_ROUNDED).

segnomms.constants.BASIC_SHAPES: list[ModuleShape]

List of basic (non-connected) module shapes.

segnomms.constants.FINDER_SHAPES: list[FinderShape]

List of available finder pattern shapes.

Default Values

segnomms.constants.DEFAULT_SCALE: int = 10

Default scale factor for QR code modules (pixels per module).

segnomms.constants.DEFAULT_BORDER: int = 4

Default border size in modules (quiet zone around QR code).

segnomms.constants.DEFAULT_DARK: str = "#000000"

Default dark module color (black).

segnomms.constants.DEFAULT_LIGHT: str = "#FFFFFF"

Default light module color (white).

Test Constants

segnomms.constants.TEST_COLORS: dict[str, str]

Common colors for examples and testing. Contains predefined colors:

  • black - #000000

  • white - #FFFFFF

  • red - #FF0000

  • green - #00FF00

  • blue - #0000FF

  • transparent - transparent

  • brand_primary - #1a1a2e

  • brand_secondary - #f5f5f5

Example:

from segnomms.constants import TEST_COLORS
from segnomms import write
import segno

qr = segno.make("Blue QR Code")
with open('blue.svg', 'w') as f:
    write(qr, f, dark=TEST_COLORS["blue"], scale=10)
segnomms.constants.QR_PAYLOADS: dict[str, str]

Common QR code payloads for examples and testing. Contains:

Example:

from segnomms.constants import QR_PAYLOADS
import segno

# Create QR codes for different payload types
for name, payload in QR_PAYLOADS.items():
    qr = segno.make(payload)
    qr.save(f'{name}.svg')

Utility Functions

segnomms.constants.get_shape_enum(shape_string)[source]

Convert a shape string to ModuleShape enum.

Parameters:

shape_string (str) – Shape name as string

Return type:

ModuleShape

Returns:

ModuleShape enum value

Raises:

ValueError – If shape string is not valid

Example

>>> from segnomms.constants import get_shape_enum
>>> shape = get_shape_enum("circle")
>>> print(shape)
ModuleShape.CIRCLE

Convert a shape string to ModuleShape enum.

Example:

from segnomms.constants import get_shape_enum

shape = get_shape_enum("circle")
print(shape)  # ModuleShape.CIRCLE
segnomms.constants.create_config(**overrides)[source]

Create a configuration dictionary with sensible defaults.

Parameters:

**overrides (Any) – Keyword arguments to override defaults

Return type:

dict[str, Any]

Returns:

Dictionary configuration suitable for write() function

Example

>>> from segnomms.constants import create_config, ModuleShape
>>> config = create_config(
...     shape=ModuleShape.CIRCLE.value,
...     scale=15,
...     dark="#0066cc"
... )
>>> print(config)
{'scale': 15, 'border': 4, 'dark': '#0066cc', 'light': '#FFFFFF', 'shape': 'circle'}

Create a configuration dictionary with sensible defaults.

Example:

from segnomms.constants import create_config, ModuleShape

config = create_config(
    shape=ModuleShape.CIRCLE.value,
    scale=15,
    dark="#0066cc"
)
# Returns: {'scale': 15, 'border': 4, 'dark': '#0066cc',
#           'light': '#FFFFFF', 'shape': 'circle'}

Complete Example

Combining multiple constants for a complete workflow:

from segnomms.constants import (
    ModuleShape,
    TEST_COLORS,
    QR_PAYLOADS,
    DEFAULT_SCALE,
    create_config
)
from segnomms import write
import segno

# Generate QR codes with different shapes and colors
shapes = [ModuleShape.CIRCLE, ModuleShape.ROUNDED, ModuleShape.SQUIRCLE]
colors = ["blue", "red", "brand_primary"]

for shape, color_name in zip(shapes, colors):
    qr = segno.make(QR_PAYLOADS["url"])
    config = create_config(
        shape=shape.value,
        dark=TEST_COLORS[color_name],
        scale=DEFAULT_SCALE
    )

    filename = f'qr_{shape.value}_{color_name}.svg'
    with open(filename, 'w') as f:
        write(qr, f, **config)