
Design Principles
1. Network-Agnostic Core
The core parsing and building logic is network-agnostic. Network-specific handling (VISA, Mastercard, etc.) is layered on top through:CardNetworkenum for network identificationNETWORK_SPECIFIC_FIELDSfor network-specific field definitionsNETWORK_REQUIRED_FIELDSfor network validation rules
2. Performance First
Performance optimizations include:- Optional Cython extensions: 2x speedup for parsing operations
- Object pooling: Reusable message objects for high-throughput scenarios
- Pre-compiled regex patterns: Avoid recompilation overhead
- Cached field lookups: Network and version-specific field caching
3. Optional LLM Integration
LLM features are completely optional:- Core functionality works without any LLM dependencies
- Provider-agnostic design supports Anthropic, OpenAI, Google, Ollama
- Auto-detection of available providers based on installed packages and API keys
Package Structure
Key Components
ISO8583Message
The central data structure representing a parsed or constructed message:ISO8583Parser
Stateful parser that converts raw message strings intoISO8583Message objects:
- Auto-detects card network from PAN prefix
- Supports ISO 8583 versions 1987, 1993, 2003
- Handles primary and secondary bitmaps
- Parses LLVAR/LLLVAR variable-length fields
- Optional Cython acceleration
ISO8583Builder
Constructs raw ISO 8583 message strings fromISO8583Message objects:
- Validates messages before building
- Handles field formatting (padding, length prefixes)
- Builds bitmap from present fields
- Network-aware field formatting
ISO8583Validator
Validates message structure and field content:- MTI validation
- Field type validation (numeric, alpha, alphanumeric, binary)
- Network-specific required field validation
- PAN Luhn check validation
EMV Handling
Field 55 (ICC Data) contains EMV chip card data in TLV format:parse_emv_data(): Parse TLV bytes into tag dictionarybuild_emv_data(): Build TLV bytes from tag dictionary- Support for multi-byte tags (9F26, 9F27, etc.)
Data Flow
See Message Flow for detailed data flow diagrams.Extension Points
Adding New Card Networks
- Add enum value to
CardNetwork - Add field definitions to
NETWORK_SPECIFIC_FIELDS - Add required fields to
NETWORK_REQUIRED_FIELDS - Add validation method to
ISO8583Validator
Adding LLM Providers
- Implement
LLMProviderinterface - Add provider to
_PROVIDERSregistry inproviders/__init__.py - Implement
is_available()function