Core API Reference¶
Auto-generated API documentation for the core module.
iso8583sim.core.types¶
Core data types, enumerations, and field definitions.
types
¶
ISO8583Version
¶
Bases: Enum
ISO 8583 protocol versions
FieldType
¶
Bases: Enum
Field data types in ISO 8583
__str__
¶
__str__() -> str
String representation returns the value
Source code in iso8583sim/core/types.py
28 29 30 | |
CardNetwork
¶
Bases: Enum
Card network identifiers
MessageClass
¶
Bases: Enum
Message class identifiers (position 2 of MTI)
MessageFunction
¶
Bases: Enum
Message function identifiers (position 3 of MTI)
MessageOrigin
¶
Bases: Enum
Message origin identifiers (position 4 of MTI)
FieldDefinition
dataclass
¶
FieldDefinition(field_type: FieldType, max_length: int, description: str, field_number: int | None = None, encoding: str = 'ascii', min_length: int | None = None, padding_char: str | None = None, padding_direction: str = 'left')
Definition of an ISO 8583 field
__post_init__
¶
__post_init__()
Validate field definition attributes after initialization
Source code in iso8583sim/core/types.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
ISO8583Message
dataclass
¶
ISO8583Message(mti: str, fields: dict[int, str], version: ISO8583Version = ISO8583Version.V1987, network: CardNetwork | None = None, raw_message: str | None = None, bitmap: str | None = None)
Represents a complete ISO 8583 message
__post_init__
¶
__post_init__()
Initialize fields after creation
Source code in iso8583sim/core/types.py
138 139 140 141 142 143 144 145 | |
ISO8583Error
¶
Bases: Exception
Base exception for ISO 8583 errors
ParseError
¶
Bases: ISO8583Error
Raised when parsing fails
ValidationError
¶
Bases: ISO8583Error
Raised when validation fails
BuildError
¶
Bases: ISO8583Error
Raised when message building fails
get_field_definition
cached
¶
get_field_definition(field_number: int, network: CardNetwork | None = None, version: ISO8583Version = ISO8583Version.V1987) -> FieldDefinition | None
Get field definition considering network and version specifics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_number
|
int
|
The field number to look up |
required |
network
|
CardNetwork | None
|
Optional card network for network-specific definitions |
None
|
version
|
ISO8583Version
|
ISO8583 version |
V1987
|
Returns:
| Type | Description |
|---|---|
FieldDefinition | None
|
FieldDefinition if found, None otherwise |
Priority order: 1. Network-specific definition 2. Version-specific definition 3. Standard field definition
Note: Results are cached for performance (lru_cache with 512 entries).
Source code in iso8583sim/core/types.py
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 | |
is_valid_mti
¶
is_valid_mti(mti: str) -> bool
Check if MTI is valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mti
|
str
|
Message Type Indicator string |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if MTI is valid, False otherwise |
Validates: - Length is 4 digits - All characters are numeric - Each position contains valid values
Source code in iso8583sim/core/types.py
1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 | |
get_network_required_fields
¶
get_network_required_fields(network: CardNetwork) -> list[int]
Get list of required fields for a specific network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
CardNetwork
|
Card network |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
List of required field numbers |
Source code in iso8583sim/core/types.py
1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 | |
get_field_format_pattern
¶
get_field_format_pattern(network: CardNetwork, field_number: int) -> str | None
Get network-specific field format pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network
|
CardNetwork
|
Card network |
required |
field_number
|
int
|
Field number |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Regex pattern string if exists, None otherwise |
Source code in iso8583sim/core/types.py
1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 | |
is_binary_field
¶
is_binary_field(field_def: FieldDefinition) -> bool
Check if field is binary type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_def
|
FieldDefinition
|
Field definition |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if field is binary, False otherwise |
Source code in iso8583sim/core/types.py
1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 | |
iso8583sim.core.parser¶
ISO 8583 message parsing.
parser
¶
ISO8583Parser
¶
ISO8583Parser(version: ISO8583Version = ISO8583Version.V1987, pool: MessagePool | None = None)
Parser for ISO 8583 messages with network support
Initialize the parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
ISO8583Version
|
ISO8583 version to use |
V1987
|
pool
|
MessagePool | None
|
Optional MessagePool for object reuse in high-throughput scenarios |
None
|
Source code in iso8583sim/core/parser.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
parse
¶
parse(message: str, network: CardNetwork | None = None) -> ISO8583Message
Parse an ISO 8583 message string into an ISO8583Message object
Source code in iso8583sim/core/parser.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
parse_file
¶
parse_file(filename: str) -> list[ISO8583Message]
Parse multiple messages from file
Source code in iso8583sim/core/parser.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
iso8583sim.core.builder¶
ISO 8583 message building.
builder
¶
ISO8583Builder
¶
ISO8583Builder(version: ISO8583Version = ISO8583Version.V1987)
Builder for creating ISO 8583 messages with network support
Source code in iso8583sim/core/builder.py
21 22 23 | |
build
¶
build(message: ISO8583Message) -> str
Build raw ISO 8583 message string from message object
Source code in iso8583sim/core/builder.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
create_message
¶
create_message(mti: str, fields: dict[int, str]) -> ISO8583Message
Create an ISO8583Message object with validation
Source code in iso8583sim/core/builder.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
create_response
¶
create_response(request: ISO8583Message, response_fields: dict[int, str]) -> ISO8583Message
Create a response message based on a request message
Source code in iso8583sim/core/builder.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
create_reversal
¶
create_reversal(original: ISO8583Message, additional_fields: dict[int, str] | None = None) -> ISO8583Message
Create a reversal message
Source code in iso8583sim/core/builder.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
create_network_management_message
¶
create_network_management_message(message_type: str, network: CardNetwork | None = None) -> ISO8583Message
Create a network management message
Source code in iso8583sim/core/builder.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
build_emv_data
¶
build_emv_data(emv_tags: dict[str, str]) -> str
Build EMV data field (field 55) from tags
Source code in iso8583sim/core/builder.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
iso8583sim.core.validator¶
Message validation with network-specific rules.
validator
¶
ISO8583Validator
¶
ISO8583Validator()
Enhanced validator for ISO 8583 messages with network support
Source code in iso8583sim/core/validator.py
28 29 30 31 32 33 34 35 36 | |
validate_field
¶
validate_field(field_number: int, value: str, field_def: FieldDefinition, network: CardNetwork | None = None) -> tuple[bool, str | None]
Validate field value
Source code in iso8583sim/core/validator.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
validate_message
¶
validate_message(message: ISO8583Message) -> list[str]
Validate complete ISO 8583 message
Source code in iso8583sim/core/validator.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
validate_processing_code
staticmethod
¶
validate_processing_code(code: str) -> bool
Validate processing code format
Source code in iso8583sim/core/validator.py
188 189 190 191 192 193 194 195 196 197 198 | |
validate_mti
classmethod
¶
validate_mti(mti: str) -> tuple[bool, str | None]
Validate Message Type Indicator
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mti
|
str
|
4-digit MTI string |
required |
Returns:
| Type | Description |
|---|---|
tuple[bool, str | None]
|
(is_valid, error_message) |
Source code in iso8583sim/core/validator.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
validate_bitmap
classmethod
¶
validate_bitmap(bitmap: str) -> tuple[bool, str | None]
Validate bitmap format and content
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bitmap
|
str
|
Hexadecimal bitmap string |
required |
Returns:
| Type | Description |
|---|---|
tuple[bool, str | None]
|
(is_valid, error_message) |
Source code in iso8583sim/core/validator.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
validate_pan
classmethod
¶
validate_pan(pan: str) -> bool
Validate Primary Account Number using Luhn algorithm
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pan
|
str
|
Card number string |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if valid, False otherwise |
Source code in iso8583sim/core/validator.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
validate_network_compliance
¶
validate_network_compliance(message: ISO8583Message) -> list[str]
Validate network-specific requirements
Source code in iso8583sim/core/validator.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
validate_emv_data
¶
validate_emv_data(emv_data: str) -> list[str]
Validate EMV data format (TLV structure)
Source code in iso8583sim/core/validator.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | |
validate_field_compatibility
¶
validate_field_compatibility(field_number: int, value: str, version: ISO8583Version) -> list[str]
Validate field compatibility with ISO version
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_number
|
int
|
Field number to validate |
required |
value
|
str
|
Field value |
required |
version
|
ISO8583Version
|
ISO8583 version |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of compatibility errors |
Source code in iso8583sim/core/validator.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
iso8583sim.core.emv¶
EMV/ICC chip card data handling.
emv
¶
EMV (Europay, Mastercard, Visa) TLV data handling.
This module provides functions for parsing and building EMV Tag-Length-Value encoded data, commonly found in ISO 8583 Field 55.
parse_emv_data
¶
parse_emv_data(data: str) -> dict[str, str]
Parse EMV TLV data into a dictionary of tags and values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str
|
Hex-encoded EMV TLV data |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary mapping tag strings to value strings (hex-encoded) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If data is malformed |
Source code in iso8583sim/core/emv.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
build_emv_data
¶
build_emv_data(tags: dict[str, str]) -> str
Build EMV TLV data from a dictionary of tags and values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tags
|
dict[str, str]
|
Dictionary mapping tag strings to value strings (hex-encoded) |
required |
Returns:
| Type | Description |
|---|---|
str
|
Hex-encoded EMV TLV data string |
Source code in iso8583sim/core/emv.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
get_tag_name
¶
get_tag_name(tag: str) -> str
Get the description of an EMV tag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
str
|
Tag identifier (hex string) |
required |
Returns:
| Type | Description |
|---|---|
str
|
Description of the tag, or "Unknown" if not found |
Source code in iso8583sim/core/emv.py
233 234 235 236 237 238 239 240 241 242 | |
explain_tvr
¶
explain_tvr(tvr_hex: str) -> list[str]
Explain Terminal Verification Results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tvr_hex
|
str
|
5-byte TVR as hex string (10 characters) |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of issues/flags that are set |
Source code in iso8583sim/core/emv.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
explain_cid
¶
explain_cid(cid_hex: str) -> str
Explain Cryptogram Information Data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cid_hex
|
str
|
CID byte as hex string |
required |
Returns:
| Type | Description |
|---|---|
str
|
Description of the cryptogram type |
Source code in iso8583sim/core/emv.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
iso8583sim.core.pool¶
Object pooling for high-throughput scenarios.
pool
¶
Object pooling for high-throughput ISO8583 message processing.
MessagePool
¶
MessagePool(size: int = 100)
Thread-safe object pool for ISO8583Message instances.
Using a pool reduces object allocation overhead in high-throughput scenarios by reusing message objects instead of creating new ones.
Usage
pool = MessagePool(size=100)
Get a message from the pool¶
msg = pool.acquire("0100", {2: "4111111111111111"})
Process the message...¶
Return it to the pool when done¶
pool.release(msg)
Note: Messages returned to the pool have their fields cleared, so don't hold references to field data after releasing.
Initialize the message pool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Maximum number of messages to keep in the pool |
100
|
Source code in iso8583sim/core/pool.py
34 35 36 37 38 39 40 41 42 43 | |
acquire
¶
acquire(mti: str, fields: dict[int, str], version: ISO8583Version = ISO8583Version.V1987, network: CardNetwork | None = None, raw_message: str | None = None, bitmap: str | None = None) -> ISO8583Message
Get a message from the pool or create a new one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mti
|
str
|
Message Type Indicator |
required |
fields
|
dict[int, str]
|
Message fields dictionary |
required |
version
|
ISO8583Version
|
ISO8583 version |
V1987
|
network
|
CardNetwork | None
|
Card network |
None
|
raw_message
|
str | None
|
Original raw message string |
None
|
bitmap
|
str | None
|
Message bitmap |
None
|
Returns:
| Type | Description |
|---|---|
ISO8583Message
|
An ISO8583Message instance (either recycled or new) |
Source code in iso8583sim/core/pool.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
release
¶
release(msg: ISO8583Message) -> None
Return a message to the pool for reuse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
ISO8583Message
|
The message to return to the pool |
required |
Note: The message's fields are cleared to avoid holding references to old data.
Source code in iso8583sim/core/pool.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
clear
¶
clear() -> None
Clear all messages from the pool.
Source code in iso8583sim/core/pool.py
116 117 118 119 | |
get_default_pool
¶
get_default_pool(size: int = 100) -> MessagePool
Get or create the default global message pool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Pool size (only used on first call) |
100
|
Returns:
| Type | Description |
|---|---|
MessagePool
|
The default MessagePool instance |
Source code in iso8583sim/core/pool.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
reset_default_pool
¶
reset_default_pool() -> None
Reset the default global pool.
Source code in iso8583sim/core/pool.py
153 154 155 156 157 158 | |