These samples use a Python library for the MQI to demonstrate basic messaging operations.
The Python ibmmq library uses the IBM MQ C client libraries through the MQI interface.
The Python library needs to be compiled with a C compiler which you need to have installed in your development
environment. For example, on MacOS we used XCode, on Windows the Desktop development with C++ module inside Visual
Studio and on Ubuntu the gcc GNU Compiler Collection.
The samples use the same configuration file as other language samples in this repository.
Follow Step 1 from this page to install the SDK using brew. None of the other steps on that page are required in order to run these Python samples.
Alternatively you can download the IBM MQ MacOS toolkit from here
The MQ Redistributable Client for Windows can be downloaded from here
The MQ Redistributed Client for Linux x64 can be downloaded from here
For other platforms, you can use the regular MQ images to install, at minimum, the MQ Client and SDK components.
Choose either uv (recommended — fast, lock-file reproducible) or the standard venv workflow.
Install uv once (if you don't already have it):
curl -LsSf https://astral.sh/uv/install.sh | shThen, from the Python/ directory, install dependencies (creates .venv automatically):
cd Python
uv sync # installs the version recorded in uv.lock (reproducible)
uv sync --upgrade # resolves and installs the current latest from PyPIcd Python
python -m venv .venv
# macOS / Linux
source .venv/bin/activate
# Windows
.venv\Scripts\activate
pip install ibmmqAll of the programs read a JSON-formatted configuration file. The name of the file can be given by setting the
JSON_CONFIG environment variable. If that is not set, the env.json file from the parent directory is used. Edit the
configuration to match the configuration of the queue manager you are going to work with.
There are no parameters to any of the programs.
You might need to run setmqenv to create environment variables pointing at your MQ installation libraries.
On MacOS, the DYLD_LIBRARY_PATH will usually need to be set to include the /opt/mqm/lib64 directory:
export DYLD_LIBRARY_PATH=/opt/mqm/lib64
If you are on Linux, you might need set the LD_LIBRARY_PATH to include the /opt/mqm/lib64 directory:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/mqm/lib64
See here for
more information about setmqenv.
On some systems, you might need to explicitly use the python3 command instead of python.
The basicput application places a short string message onto the queue.
uv
uv run basicputvenv (activate first — see above)
python basicput.pyThe basicget application reads all messages from the queue and displays the contents.
uv
uv run basicgetvenv
python basicget.pyRun these samples as a pair.
Start the basicsubscribe program in one window (or in the background) and immediately afterwards start the
basicpublish program in another window.
uv
uv run basicsubscribe # window 1
uv run basicpublish # window 2venv
python basicsubscribe.py # window 1
python basicpublish.py # window 2Run these samples as a pair.
Start the basicresponse program in one window (or in the background) and immediately afterwards start the
basicrequest program in another window.
uv
uv run basicresponse # window 1
uv run basicrequest # window 2venv
python basicresponse.py # window 1
python basicrequest.py # window 2