Python teams adopt IBM MQ when integration scripts must put audit events on enterprise queues, ML pipelines must consume mainframe-sourced work items, or DevOps automation must drain test queues after deployments. pymqi exposes the Message Queue Interface to Python 3 with objects like QueueManager and Queue wrapping MQCONN and MQOPEN. Underneath it is still the C client and SVRCONN—your pip install fails on a laptop without IBM MQ client libraries, and your script gets 2035 if operations never granted MCAUSER on the target queue. This tutorial explains pymqi installation constraints, connect patterns with host and channel, put and get with bytes and strings, using CCDT via environment variables, transactional puts with pymqi CMIT and BACK, pairing with Pandas and Celery architectures, container deployment, and troubleshooting import errors versus MQ reason codes.
pip install pymqi triggers build against installed cmqc.h and libmqm. On Windows install IBM MQ client first and set MQ_FILE_PATH. On Linux use supported distributions or IBM container base. CI pipelines install client tarball before pip step. Virtualenv does not remove native dependency—document in README for data scientists cloning the repo. Pin pymqi version in requirements.txt with tested MQ client version comment.
| pymqi | MQI equivalent | Role |
|---|---|---|
| QueueManager | MQCONN | Connection |
| Queue | MQOPEN | Object handle |
| put | MQPUT | Send message |
| get | MQGET | Receive message |
| CMIT | MQCMIT | Commit UOW |
123456789101112131415import pymqi conn_info = "QM_PROD" channel = "ORDERS.API" host = "mq-prod.corp" port = "1414" qmgr = pymqi.QueueManager(None) qmgr.connect(conn_info, channel, f"{host}({port})") queue = pymqi.Queue(qmgr) queue.open("ORDERS.IN", pymqi.CMQC.MQOO_OUTPUT) queue.put(b"payload bytes") queue.close() qmgr.disconnect()
connect first argument is queue manager name. Channel and conn_info string follow pymqi signature for your version—verify against current pymqi docs because APIs evolved. Use bytes for binary payloads; decode explicitly when mainframe sends EBCDIC. Catch pymqi.MQMIError and read comp, reason, and mqrc attributes for logging.
12345with pymqi.QueueManager(None) as qmgr: qmgr.connect("QM_PROD", "ORDERS.API", "mq-prod.corp(1414)") with pymqi.Queue(qmgr, "ORDERS.IN") as q: q.open(pymqi.CMQC.MQOO_OUTPUT) q.put(b"event data")
Context managers help scripts that crash on exceptions still disconnect—reduces orphaned SVRCONN instances on servers when analysts run ad hoc notebooks repeatedly.
Open with MQOO_INPUT_AS_Q_DEF and MQGMO_WAIT with suitable wait interval. Loop get until empty or shutdown flag. Process message; commit or backout syncpoint if in transactional mode. Poison messages hitting backout need alignment with BOQNAME on server. Use signal handlers in long-running workers for graceful exit calling disconnect.
os.environ["MQCHLLIB"] = "/var/mqm/ccdt" and MQCHLTAB before connect allows channel-only connect strings per pymqi CCDT support patterns. Alternatively pass full connection tuple in connect. Ansible templates push env vars to batch hosts running Python ETL.
pymqi lets Python wear gloves to handle MQ—the hands doing the work are still the C client underneath.
Python asks pymqi to mail a message to MQ, and pymqi knows how to speak the post office language.
Write a script that puts one persistent message and logs MQMIError reason on failure.
Add MQCHLLIB to a script and explain when ops prefers that over hardcoded host.
Design idempotent consumer pseudocode for at-least-once delivery.
1. Python MQ library is commonly:
2. pymqi needs:
3. with QueueManager helps:
4. 2035 in Python means: