Mapping¶
Overview¶
The mapping module provides bidirectional attribute translation between
developer-friendly snake_case names and native MQSC parameter names. The
mapper is used internally by MQRESTSession and is not typically called
directly.
See Mapping Pipeline for a conceptual overview of how mapping works.
Mapping functions¶
The module exposes three public functions that perform the actual translation.
These are called internally by MQRESTSession during command execution:
-
map_request_attributes()— Translates request parameters fromsnake_caseto MQSC before sending to the REST API. Performs key mapping, value mapping, and key-value mapping in sequence. -
map_response_attributes()— Translates a single response dict from MQSC tosnake_caseafter receiving from the REST API. -
map_response_list()— Translates a list of response dicts (the common return type for DISPLAY commands).
The mapper performs three types of translation in each direction:
- Key mapping: Attribute name translation (e.g.
current_queue_depth↔CURDEPTH) - Value mapping: Enumerated value translation (e.g.
"yes"↔"YES","server_connection"↔"SVRCONN") - Key-value mapping: Combined name+value translation for cases where both
key and value change together (e.g.
channel_type="server_connection"→CHLTYPE("SVRCONN"))
Mapping data¶
The mapping tables are loaded from the JSON resource file at:
The data is organized by qualifier (e.g. queue, channel, qmgr) with
separate maps for request and response directions. Each qualifier contains:
request_key_map—snake_case→ MQSC key mapping for requestsrequest_value_map— value translations for request attributesrequest_key_value_map— combined key+value translations for requestsresponse_key_map— MQSC →snake_casekey mapping for responsesresponse_value_map— value translations for response attributes
The mapping data was originally bootstrapped from IBM MQ 9.4 documentation and covers all standard MQSC attributes across 42 qualifiers.
Diagnostics¶
MappingIssue¶
Tracks mapping problems encountered during translation:
- Unknown attribute names (not found in key map)
- Unknown attribute values (not found in value map)
- Ambiguous mappings
In strict mode, any MappingIssue causes a MappingError. In lenient
mode, issues are collected but the unmapped values pass through unchanged.
MappingError¶
Raised when attribute mapping fails in strict mode. Contains the list of
MappingIssue instances that caused the failure.
try:
session.display_queue("MY.QUEUE",
response_parameters=["invalid_attribute_name"])
except MappingError as e:
# e describes the unmappable attributes
print(e)
API reference¶
Map request attributes from snake_case into MQSC parameter names.
Translates Python-friendly attribute names and values into the native MQSC forms expected by the MQ REST API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qualifier
|
str
|
The mapping qualifier (e.g. |
required |
attributes
|
Mapping[str, object]
|
Request attributes keyed by |
required |
strict
|
bool
|
When |
True
|
mapping_data
|
Mapping[str, object] | None
|
Optional mapping data to use instead of the
built-in :data: |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
A new dict with MQSC parameter names as keys. |
Raises:
| Type | Description |
|---|---|
MappingError
|
If strict is |
Source code in src/pymqrest/mapping.py
Map response attributes from MQSC parameter names to snake_case.
Translates native MQSC attribute names and values returned by the
MQ REST API into Python-friendly snake_case forms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qualifier
|
str
|
The mapping qualifier (e.g. |
required |
attributes
|
Mapping[str, object]
|
Response attributes keyed by MQSC parameter names. |
required |
strict
|
bool
|
When |
True
|
mapping_data
|
Mapping[str, object] | None
|
Optional mapping data to use instead of the
built-in :data: |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, object]
|
A new dict with |
Raises:
| Type | Description |
|---|---|
MappingError
|
If strict is |
Source code in src/pymqrest/mapping.py
Map a list of response objects from MQSC names to snake_case.
This is the batch equivalent of :func:map_response_attributes.
Each object in the list is mapped independently, and issue tracking
includes the object_index so problems can be traced to a
specific item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qualifier
|
str
|
The mapping qualifier (e.g. |
required |
objects
|
Sequence[Mapping[str, object]]
|
Sequence of response attribute dicts to map. |
required |
strict
|
bool
|
When |
True
|
mapping_data
|
Mapping[str, object] | None
|
Optional mapping data to use instead of the
built-in :data: |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, object]]
|
A list of dicts with |
Raises:
| Type | Description |
|---|---|
MappingError
|
If strict is |
Source code in src/pymqrest/mapping.py
Single mapping issue recorded during attribute translation.
Each issue describes one attribute that could not be fully mapped (unknown key, unknown value, or unknown qualifier).
Attributes:
| Name | Type | Description |
|---|---|---|
direction |
MappingDirection
|
Whether the issue occurred during |
reason |
MappingReason
|
Category of the mapping failure — |
attribute_name |
str
|
The attribute name that triggered the issue. |
attribute_value |
object | None
|
The attribute value, if relevant to the issue. |
object_index |
int | None
|
Zero-based index within a response list, or
|
qualifier |
str | None
|
The qualifier that was being mapped, or |
Source code in src/pymqrest/mapping.py
to_payload()
¶
Return the issue as a JSON-serialisable dict.
Returns:
| Type | Description |
|---|---|
dict[str, object | None]
|
A dict with keys |
dict[str, object | None]
|
|
dict[str, object | None]
|
and |
Source code in src/pymqrest/mapping.py
Bases: Exception
Raised when attribute mapping fails in strict mode.
Contains one or more :class:MappingIssue instances describing
exactly which attributes could not be mapped and why.
Attributes:
| Name | Type | Description |
|---|---|---|
issues |
Tuple of :class: |
Source code in src/pymqrest/mapping.py
issues = tuple(issues)
instance-attribute
¶
__init__(issues, message=None)
¶
Initialize a mapping error with the captured issues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
issues
|
Sequence[MappingIssue]
|
One or more mapping issues that caused the failure. |
required |
message
|
str | None
|
Optional override message. When |
None
|
Source code in src/pymqrest/mapping.py
_build_message()
¶
Source code in src/pymqrest/mapping.py
to_payload()
¶
Return mapping issues as JSON-serialisable dicts.
Returns:
| Type | Description |
|---|---|
list[dict[str, object | None]]
|
A list of dicts, one per issue (see |
list[dict[str, object | None]]
|
meth: |