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'
Available module shapes:
SQUARE- Classic square modulesCIRCLE- Circular dotsROUNDED- Rounded squaresDOT- Small dots with gapsDIAMOND- Diamond shapesSTAR- Star shapesHEXAGON- Hexagonal modulesTRIANGLE- Triangle shapesSQUIRCLE- Superellipse shapesCROSS- Plus/cross shapesCONNECTED- Connected shapes with pill-style mergingCONNECTED_EXTRA_ROUNDED- Extra rounded connected shapesCONNECTED_CLASSY- Classy connected shapesCONNECTED_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'
Available finder pattern shapes:
SQUARE- Square finder patternsROUNDED- Rounded finder patternsCIRCLE- 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).
Test Constants
- segnomms.constants.TEST_COLORS: dict[str, str]
Common colors for examples and testing. Contains predefined colors:
black- #000000white- #FFFFFFred- #FF0000green- #00FF00blue- #0000FFtransparent- transparentbrand_primary- #1a1a2ebrand_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:
simple- “Hello World”url- “https://example.com”url_complex- “https://example.com/path?param1=value1¶m2=value2”email- “mailto:test@example.com”phone- “tel:+1234567890”wifi- WiFi configuration stringunicode- Unicode text examplenumeric- Numeric-only payloadalphanumeric- Alphanumeric payload
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:
- 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:
- 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)