Skip to main content

Python wrapper for the IBM MQ REST API

Project description

pymqrest

Python wrapper for the IBM MQ administrative REST API.

pymqrest provides typed Python methods for every MQSC command exposed by the IBM MQ 9.4 runCommandJSON REST endpoint. Attribute names are automatically translated between Python snake_case and native MQSC parameter names, so you work with Pythonic identifiers throughout.

Table of Contents

Installation

pip install pymqrest

Requires Python 3.12+.

Quick start

from pymqrest import MQRESTSession, LTPAAuth

session = MQRESTSession(
    rest_base_url="https://localhost:9443/ibmmq/rest/v2",
    qmgr_name="QM1",
    credentials=LTPAAuth("mqadmin", "mqadmin"),
    verify_tls=False,
)

# Query the queue manager
qmgr = session.display_qmgr()
print(qmgr["queue_manager_name"])

# List all local queues
queues = session.display_qlocal(name="*")
for q in queues:
    print(q["queue_name"], q.get("current_queue_depth", 0))

# Idempotent object management
result = session.ensure_qlocal(
    name="APP.REQUESTS",
    request_parameters={"max_queue_depth": "50000"},
)
print(result.action)  # EnsureAction.CREATED, UPDATED, or UNCHANGED

API overview

Session

MQRESTSession manages authentication, connection settings, and attribute mapping. All command methods are called directly on the session object.

MQRESTSession(
    rest_base_url="https://host:9443/ibmmq/rest/v2",
    qmgr_name="QM1",
    credentials=LTPAAuth("user", "pass"),  # or CertificateAuth / BasicAuth
    map_attributes=True,      # snake_case <-> MQSC translation (default)
    mapping_strict=True,      # raise on unknown attributes (default)
    verify_tls=True,          # TLS certificate verification (default)
    timeout_seconds=30.0,     # HTTP request timeout (default)
)

Commands

Over 130 generated methods cover the MQSC command set:

Verb Methods Returns Example
display_* 44 list[dict] or dict | None session.display_qlocal(name="*")
define_* 19 None session.define_qlocal(name="Q1")
alter_* 17 None session.alter_qlocal(name="Q1", ...)
delete_* 16 None session.delete_qlocal(name="Q1")
Other 41 None start_channel, stop_listener, clear_qlocal, ...

All methods accept optional request_parameters and response_parameters dicts. DISPLAY commands default to returning all attributes.

Ensure methods

Idempotent ensure_* methods implement a declarative upsert pattern for 15 object types (queues, channels, topics, listeners, and more):

  • DEFINE when the object does not exist
  • ALTER only the attributes that differ
  • No-op when all specified attributes already match

Returns an EnsureResult whose action attribute is EnsureAction.CREATED, UPDATED, or UNCHANGED. When the action is UPDATED, result.changed contains the attribute names that differed.

Attribute mapping

When map_attributes=True (the default), attribute names and values are translated automatically:

Direction From To Example
Request max_queue_depth MAXDEPTH snake_case to MQSC
Response MAXDEPTH max_queue_depth MQSC to snake_case

Disable per-session (map_attributes=False) or per-call for raw MQSC parameter access.

Authentication

Three credential types are supported:

  • CertificateAuth(cert_path, key_path) — mutual TLS client certificates
  • LTPAAuth(username, password) — LTPA token login (automatic at session creation)
  • BasicAuth(username, password) — HTTP Basic authentication

Documentation

Full documentation: https://wphillipmoore.github.io/mq-rest-admin-python/

Development

uv sync --group dev
uv run python3 scripts/dev/validate_local.py

License

GPL-3.0-or-later. See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymqrest-1.1.4.tar.gz (55.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymqrest-1.1.4-py3-none-any.whl (56.3 kB view details)

Uploaded Python 3

File details

Details for the file pymqrest-1.1.4.tar.gz.

File metadata

  • Download URL: pymqrest-1.1.4.tar.gz
  • Upload date:
  • Size: 55.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pymqrest-1.1.4.tar.gz
Algorithm Hash digest
SHA256 a6ff548f1c4f0556994b8cc1efd1e7c0bd5ad969e3529bfe8f1327ebb39fe184
MD5 3e967f8c2074c44da1d0d7fc8ba05dcf
BLAKE2b-256 c0845fbc8fc88510a72c50692cc4b30b2c1b0b1f6a8bee7b37acf5c9c65656eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymqrest-1.1.4.tar.gz:

Publisher: publish.yml on wphillipmoore/mq-rest-admin-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pymqrest-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: pymqrest-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 56.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pymqrest-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 77fda06968e06833cc73575c276648fe604506cb96b7748e7aed1e4b6977fd3e
MD5 94fb1f01b87216690adf3add7b27190f
BLAKE2b-256 a8b7db4d816d502fee998d5812cba4a53946e4b219264349f5d67360579c3652

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymqrest-1.1.4-py3-none-any.whl:

Publisher: publish.yml on wphillipmoore/mq-rest-admin-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page