Advanced QR code generation plugin for Segno with custom shapes, styling, and interactivity
Project description
SegnoMMS
⚠️ Beta Software Notice: SegnoMMS is currently in beta. While the core functionality is stable and extensively tested, APIs may change between minor versions. We recommend pinning to specific versions for production use and reviewing the CHANGELOG before upgrading.
Advanced QR code generation plugin for Segno with custom shapes, styling, interactivity, and comprehensive Pydantic integration for type-safe configuration management. Powers the QR code generation at qrcodemms.com.
Features
- 🔧 Pydantic-Powered Configuration: Complete type safety with automatic validation, JSON Schema generation, and structured data models throughout the entire codebase
- 🎨 Custom Shapes: Multiple shape options for QR modules (dots, rounded, squares, diamonds, squircles, etc.)
- ⚡ Interactive Elements: CSS classes for hover effects, tooltips, and click handling
- 🔗 Connected Modules: Smart shape connection for adjacent modules (pill shapes, flowing designs)
- 🎯 Per-Component Styling: Different shapes for different QR components (finder patterns, data modules, etc.)
- 🎨 CSS Variables: Dynamic styling through CSS custom properties
- ♿ Comprehensive Accessibility: WCAG compliance, ARIA labels, stable IDs, pattern-specific labeling, and screen reader optimization
- 🛡️ Type Safety: Full type checking, constraint validation, and IDE support for all parameters
- 📊 Structured Data: Rich data models instead of dictionaries with computed properties and validation
- 🔌 API Integration: JSON Schema generation perfect for FastAPI, OpenAPI, and external tools
Installation
Using pip
pip install segnomms
For Development (Recommended: Using uv)
SegnoMMS uses uv for ultra-fast dependency management:
# Install uv (if not already installed)
pip install uv
# Clone and setup
git clone https://github.com/systmms/segnomms.git
cd segnomms
# Install with uv (10-100x faster than pip!)
uv sync
uv pip install -e .
# Or use the Makefile
make setup
Traditional pip development setup:
git clone https://github.com/systmms/segnomms.git
cd segnomms
pip install -e .
Usage
import segno
from segnomms import write
# Create QR code
qr = segno.make('Hello World')
# Generate interactive SVG with custom shapes
write(qr, 'output.svg',
scale=10,
shape='rounded',
data_shape='dot',
finder_shape='rounded',
finder_inner_shape='square',
merge='soft', # Connect adjacent modules
interactive=True
)
Accessibility Features
import segno
from segnomms import write
from segnomms.a11y.accessibility import AccessibilityConfig, create_enhanced_accessibility
# Generate QR code with comprehensive accessibility
qr = segno.make('Accessible QR Code')
accessibility_config = create_enhanced_accessibility()
write(qr, 'accessible.svg',
scale=10,
shape='rounded',
accessibility=accessibility_config
)
# Custom accessibility configuration
from segnomms.a11y.accessibility import AccessibilityConfig, AccessibilityLevel
custom_a11y = AccessibilityConfig(
id_prefix="qr",
target_compliance=AccessibilityLevel.AAA,
enable_aria=True,
include_pattern_labels=True,
enable_keyboard_navigation=True,
root_label="Interactive QR Code"
)
write(qr, 'custom-accessible.svg', accessibility=custom_a11y)
Shape Options
Basic Shapes
square- Classic square modulescircle- Circular dotsrounded- Rounded squaresdot- Small dots with gapsdiamond- Diamond shapeshexagon- Hexagonal modulesstar- Star shapesplus- Plus/cross shapes
Connection Styles
none- No connection between modulespill- Connect horizontal/vertical neighbors into pillsflow- Smooth flowing connectionsmerge- Fully merge connected regions
Interactive Features
- Hover highlighting
- Click handlers via data attributes
- Tooltips showing module information
- Custom CSS classes per module type
Requirements
- Python >= 3.10 (tested through Python 3.14)
- Segno >= 1.5.2 (tested with 1.5.2, 1.6.0, and 1.6.6)
- Pydantic >= 2.7,<3 (for configuration validation and JSON Schema)
Optional Dependencies
- For accessibility features: All included in base installation
- For development: use
make setup(uv) oruv syncto install all development dependencies
Quick Start
import segno
from segnomms import write
# Create a QR code with custom shapes
qr = segno.make("https://example.com")
write(qr, "output.svg", shape="circle", dark="#1a1a2e", scale=10)
Configuration Management
SegnoMMS features comprehensive Pydantic-powered configuration with automatic validation, type safety, and JSON Schema generation throughout the entire codebase:
Type-Safe Configuration with Full Validation
from segnomms.config.models.core import RenderingConfig
from segnomms.validation.models import CompositionValidatorConfig
from segnomms.algorithms.models import ClusteringConfig
from pydantic import ValidationError
# Main configuration with automatic validation
config = RenderingConfig.from_kwargs(
shape='squircle',
corner_radius=0.3,
connectivity='8-way',
merge='soft'
)
# Component-specific validation models
validator_config = CompositionValidatorConfig(
qr_version=7,
error_level='M',
matrix_size=45
)
clustering_config = ClusteringConfig(
min_cluster_size=5,
density_threshold=0.7,
connectivity_mode='8-way'
)
# Invalid values raise clear validation errors with helpful messages
try:
bad_config = RenderingConfig.from_kwargs(shape='invalid', scale=-5)
except ValidationError as e:
for error in e.errors():
print(f"{error['loc']}: {error['msg']}")
Structured Data Models Throughout
from segnomms.core.models import NeighborAnalysis
from segnomms.algorithms.models import ClusterInfo
from segnomms.validation.models import ValidationResult
from segnomms.core.detector import ModuleDetector
from segnomms.config.models.core import RenderingConfig
# Example setup
config = RenderingConfig.from_kwargs()
# Create a minimal QR matrix for version 1 (21x21)
matrix = [[True] * 21 for _ in range(21)]
detector = ModuleDetector(matrix, version=1)
row, col = 10, 10
# Structured returns instead of dictionaries
analysis = detector.get_weighted_neighbor_analysis(row, col)
print(f"Flow direction: {analysis.flow_direction}")
print(f"Connectivity: {analysis.connectivity_strength}")
# Rich cluster information with computed properties
cluster = ClusterInfo(
positions=[(0,0), (0,1), (1,0)],
bounds=(0, 0, 1, 1),
module_count=3,
density=0.75,
aspect_ratio=1.0,
is_rectangular=False
)
print(f"Cluster size: {cluster.width}x{cluster.height}")
print(f"Fill ratio: {cluster.fill_ratio}")
# Comprehensive validation results
from segnomms.validation import CompositionValidator
validator = CompositionValidator(qr_version=1, error_level='M', matrix_size=21)
result = validator.validate_all(config)
print(f"Valid: {result.valid}")
print(f"Issues: {result.total_issues}")
JSON Schema Generation & Integration
from segnomms.config.models.core import RenderingConfig
from segnomms.algorithms.models import ClusteringConfig
# Generate JSON Schema for any configuration
schema = RenderingConfig.model_json_schema()
clustering_schema = ClusteringConfig.model_json_schema()
# Rich schemas with constraints and descriptions
print(schema['properties']['scale'])
# Output: {'type': 'integer', 'minimum': 1, 'maximum': 100, 'description': 'Size of each module in pixels'}
# Perfect for FastAPI integration
try:
from fastapi import FastAPI
app = FastAPI()
@app.post("/qr/generate")
def generate_qr(config: RenderingConfig):
return {"svg": f"<svg>Generated QR with {config.geometry.shape}</svg>"}
@app.get("/qr/schema")
def get_schema():
return RenderingConfig.model_json_schema()
print("FastAPI integration ready")
except ImportError:
print("FastAPI not available - install with: pip install fastapi")
Configuration Serialization & Presets
from segnomms.config.models.core import RenderingConfig
from segnomms.algorithms.models import ClusteringConfig
# Create example configurations
config = RenderingConfig.from_kwargs(shape='squircle', corner_radius=0.4)
clustering_config = ClusteringConfig()
# Serialize any configuration to JSON
json_string = config.model_dump_json()
cluster_json = clustering_config.model_dump_json()
# Restore from JSON with validation
restored_config = RenderingConfig.model_validate_json(json_string)
restored_cluster = ClusteringConfig.model_validate_json(cluster_json)
# Create configuration presets
PRESET_MODERN = RenderingConfig.from_kwargs(
shape='squircle',
corner_radius=0.4,
connectivity='8-way',
merge='soft'
)
PRESET_CLASSIC = RenderingConfig.from_kwargs(
shape='square',
connectivity='4-way',
merge='none'
)
IDE Support & Type Safety
All models provide complete type hints and IDE auto-completion:
from segnomms.config.models.core import RenderingConfig
# Full IDE support with type checking
def process_qr(config: RenderingConfig) -> str:
# IDE knows all available fields and their types
scale: int = config.scale
shape: str = config.geometry.shape
# Automatic validation ensures type safety
return f"<svg>Generated SVG with {shape} at scale {scale}</svg>"
License
SegnoMMS is open source software licensed under the MIT License. See the LICENSE file for details.
Acknowledgments
- Built for Segno - Pure Python QR Code generator by Lars Heuer
- "QR Code" is a registered trademark of DENSO WAVE INCORPORATED
Commercial Use
This plugin is free for both personal and commercial use. You can use it in commercial products, SaaS applications, or any other projects without restrictions.
Development
Setting Up the Development Environment
Recommended: Using uv (fast, no additional setup)
git clone https://github.com/systmms/segnomms.git
cd segnomms
make setup # Uses uv for fast dependency installation
Alternative: Using pip
git clone https://github.com/systmms/segnomms.git
cd segnomms
pip install -e .
Optional: Using Nix for reproducible environments
For advanced users who prefer Nix-based development environments:
- Install Nix and direnv
- Run the setup script:
./repo/setup-dev-env.sh
- The environment will activate automatically when entering the project directory
Note: Nix setup is optional and not required for most development workflows.
Development Commands
Use make help to discover all available commands:
make help # Show all available commands
make test # Run full test suite
make test-quick # Quick unit tests during development
make lint # Run all linting checks
make docs # Build Sphinx documentation
make benchmark # Run performance benchmarks
Key commands organized by category:
- Setup:
make setup,make clean - Testing:
make test,make test-unit,make test-integration,make test-visual - Quality:
make lint,make format - Documentation:
make docs,make docs-serve - Performance:
make benchmark,make benchmark-memory
GitHub Actions Testing
Test GitHub Actions workflows locally using act:
# List available workflows
act -l
# Run all workflows
act
# Run specific workflow
act -W .github/workflows/test.yml
# Lint workflow files
actionlint
The project includes comprehensive GitHub Actions workflows for testing and validation.
Git Hooks (Lefthook)
The project uses Lefthook for git hooks to ensure code quality:
- actionlint: Validates GitHub Actions workflow syntax
- black: Python code formatting
- isort: Python import sorting
- flake8: Python linting
Install hooks:
lefthook install
Hooks run automatically on commit. To run manually:
lefthook run pre-commit
Architecture
Based on the Segno plugin architecture:
- Entry point:
segnomms.plugin:write - Plugin registration via setuptools entry points
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file segnomms-0.2.1.tar.gz.
File metadata
- Download URL: segnomms-0.2.1.tar.gz
- Upload date:
- Size: 4.7 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cc3a226a3a500f8abc9ff17e073c01cab53165ef5c2e1a04d9fd63bab629c09
|
|
| MD5 |
0def20477fcc47111745ccbc464f931d
|
|
| BLAKE2b-256 |
57d1f29b4af4581688673de32298f991692a0ff8024758d33f594e52a21242ec
|
Provenance
The following attestation bundles were made for segnomms-0.2.1.tar.gz:
Publisher:
release-please.yml on systmms/segnomms
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
segnomms-0.2.1.tar.gz -
Subject digest:
0cc3a226a3a500f8abc9ff17e073c01cab53165ef5c2e1a04d9fd63bab629c09 - Sigstore transparency entry: 1558421552
- Sigstore integration time:
-
Permalink:
systmms/segnomms@8647db0a2d463fb61b3d3189270ffca329478a91 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/systmms
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yml@8647db0a2d463fb61b3d3189270ffca329478a91 -
Trigger Event:
push
-
Statement type:
File details
Details for the file segnomms-0.2.1-py3-none-any.whl.
File metadata
- Download URL: segnomms-0.2.1-py3-none-any.whl
- Upload date:
- Size: 202.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c377c6bc907713325443eae889e697ca8bf72d3fd331284e93f9f48ec9db47fa
|
|
| MD5 |
929a0e72dbe8f37bd1e07fe9dd0bba45
|
|
| BLAKE2b-256 |
85d362b3f4fd00f64576519dbb46a0e7569f15751c9cdfd68d3c47f1e0d75a0c
|
Provenance
The following attestation bundles were made for segnomms-0.2.1-py3-none-any.whl:
Publisher:
release-please.yml on systmms/segnomms
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
segnomms-0.2.1-py3-none-any.whl -
Subject digest:
c377c6bc907713325443eae889e697ca8bf72d3fd331284e93f9f48ec9db47fa - Sigstore transparency entry: 1558421775
- Sigstore integration time:
-
Permalink:
systmms/segnomms@8647db0a2d463fb61b3d3189270ffca329478a91 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/systmms
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yml@8647db0a2d463fb61b3d3189270ffca329478a91 -
Trigger Event:
push
-
Statement type: