{"id":2178,"library":"pamqp","title":"pamqp: AMQP 0-9-1 Low-Level Library","description":"pamqp is a low-level Python library for marshaling and unmarshaling AMQP 0-9-1 protocol frames. It provides programmatic access to AMQP commands, headers, and body frames, allowing users to build clients, servers, or proxies that interact directly with the AMQP protocol, notably for RabbitMQ. The current version is 4.0.0, with stable releases typically occurring to address Python compatibility or critical bug fixes.","status":"active","version":"4.0.0","language":"en","source_language":"en","source_url":"https://github.com/gmr/pamqp","tags":["amqp","rabbitmq","protocol","low-level","serialization","async"],"install":[{"cmd":"pip install pamqp","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Requires Python 3.11 or newer.","package":"python","optional":false}],"imports":[{"symbol":"Frame","correct":"from pamqp.frame import Frame"},{"note":"AMQP command classes moved from pamqp.specification to pamqp.commands submodules in v3.x.","wrong":"from pamqp.specification import Basic.Publish","symbol":"Publish","correct":"from pamqp.commands.basic import Publish"},{"symbol":"ContentHeader","correct":"from pamqp.header import ContentHeader"},{"symbol":"ContentBody","correct":"from pamqp.body import ContentBody"},{"note":"Exceptions moved from pamqp.specification to pamqp.exceptions in v3.x.","wrong":"from pamqp.specification import AMQPConnectionError","symbol":"AMQPConnectionError","correct":"from pamqp.exceptions import AMQPConnectionError"}],"quickstart":{"code":"import pamqp.frame\nimport pamqp.commands.basic\nimport pamqp.header\nimport pamqp.body\n\n# Example: Prepare a Basic.Publish command and marshal it into frames\nchannel_id = 1\nexchange = 'my_exchange'\nrouting_key = 'my_key'\npayload = b'Hello, pamqp!'\n\n# 1. Create the Basic.Publish command object\npublish_cmd = pamqp.commands.basic.Publish(\n    exchange=exchange,\n    routing_key=routing_key,\n    mandatory=False,\n    immediate=False\n)\n\n# 2. Create ContentHeader for the message properties\nheader = pamqp.header.ContentHeader(\n    class_id=publish_cmd.name_id, # class_id comes from the command\n    body_size=len(payload),\n    properties={} # Basic properties for this example\n)\n\n# 3. Create ContentBody for the actual message payload\nbody = pamqp.body.ContentBody(value=payload)\n\n# 4. Marshal the command into an AMQP frame\ncommand_frame_bytes = pamqp.frame.Frame.marshal(publish_cmd, channel_id)\n\n# 5. Marshal the content header into an AMQP frame\nheader_frame_bytes = pamqp.frame.Frame.marshal(header, channel_id)\n\n# 6. Marshal the content body into an AMQP frame\nbody_frame_bytes = pamqp.frame.Frame.marshal(body, channel_id)\n\nprint(f\"Marshalled command frame: {command_frame_bytes.hex()}\")\nprint(f\"Marshalled header frame: {header_frame_bytes.hex()}\")\nprint(f\"Marshalled body frame: {body_frame_bytes.hex()}\")\n\n# To demonstrate unmarshalling a single frame (e.g., a command frame)\nunmarshalled_cmd_frame = pamqp.frame.Frame.unmarshal(command_frame_bytes)\nprint(f\"\\nUnmarshalled frame type: {unmarshalled_cmd_frame.frame_type_id}\")\nprint(f\"Unmarshalled channel ID: {unmarshalled_cmd_frame.channel_id}\")\nprint(f\"Unmarshalled command: {unmarshalled_cmd_frame.value.__class__.__name__}\")\n","lang":"python","description":"This quickstart demonstrates how to create AMQP command, header, and body objects, and then marshal them into raw AMQP frames using `pamqp.frame.Frame.marshal`. It also shows a simple unmarshal operation for a single frame. Note that `pamqp` only handles serialization; managing network I/O and sequencing of frames into complete messages is left to the user."},"warnings":[{"fix":"Upgrade Python environment to 3.11+ or pin pamqp to <4.0.0 if unable to upgrade Python.","message":"Version 4.0.0 and later require Python 3.11 or newer. Previous versions supported Python 3.7+.","severity":"breaking","affected_versions":"4.0.0+"},{"fix":"Rely on standard `inspect.get_annotations()` or `MyCommand.__annotations__` directly which Python manages, instead of expecting an explicitly declared class variable.","message":"In v4.0.0, explicit `__annotations__` class variables were removed from command and base classes. If your code directly introspects `MyCommand.__annotations__`, it may need updating as Python now manages this automatically.","severity":"breaking","affected_versions":"4.0.0+"},{"fix":"Update all import paths. For example, `from pamqp.specification import Basic` becomes `from pamqp.commands.basic import Basic` (or specific command like `Publish`). Refer to the `pamqp.commands` structure.","message":"Major module reorganization occurred in version 3.x. AMQP command classes (e.g., `Basic.Publish`), exceptions, and constants were moved from `pamqp.specification` to dedicated modules like `pamqp.commands.*`, `pamqp.exceptions`, and `pamqp.constants`.","severity":"breaking","affected_versions":"3.0.0+"},{"fix":"Update usage from `Basic.QoS(global_=True)` to `Basic.QoS(globally=True)`.","message":"The `Basic.QoS` command's `global_` argument was renamed to `globally` in version 3.0.0a5.","severity":"breaking","affected_versions":"3.0.0a5+"},{"fix":"Be prepared to write code for socket communication, frame buffering, and state machines if using pamqp directly. For higher-level abstractions, consider libraries like `pika` or `aio-pika` which use pamqp internally or implement similar logic.","message":"pamqp is a low-level AMQP 0-9-1 protocol serialization library. It does not handle network I/O, connection management, threading, or application logic. Users must implement these aspects themselves to build a functional AMQP client or server.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to pamqp 3.0.1+ to ensure `Basic.Reject(requeue=False)` functions correctly. Thoroughly test critical flags for expected behavior.","message":"In `pamqp` versions < 3.0.1, the `Basic.Reject(requeue=False)` command parameter was erroneously coerced to `True`, meaning messages were always requeued. While fixed in 3.0.1 and later (including 4.0.0), this highlights the importance of verifying critical parameter behavior.","severity":"gotcha","affected_versions":"<3.0.1"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}