pamqp

pamqp is a low level AMQP 0-9-1 frame encoding and decoding library for Python 3.

pamqp is not a end-user client library for talking to RabbitMQ but rather is used by client libraries for marshaling and unmarshaling AMQP frames.

Package Version BSD

Issues

Please report any issues to the Github repo at https://github.com/gmr/pamqp/issues

Source

pamqp source is available on Github at https://github.com/gmr/pamqp

Installation

pamqp is available from the Python Package Index but should generally be installed as a dependency from a client library.

Documentation

pamqp.base

Base classes for the representation of frames and data structures.

class pamqp.base.Frame[source]

Base Class for AMQ Methods for encoding and decoding

marshal()[source]

Dynamically encode the frame by taking the list of attributes and encode them item by item getting the value form the object attribute and the data type from the class attribute.

Return type

bytes

unmarshal(data)[source]

Dynamically decode the frame data applying the values to the method object by iterating through the attributes in order and decoding them.

Parameters

data (bytes) – The raw AMQP frame data

Return type

None

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError

Return type

None

__contains__(item)

Return if the item is in the attribute list

Parameters

item (str) –

Return type

bool

__eq__()

Return self==value.

__getitem__(item)

Return an attribute as if it were a dict

Parameters

item (str) – The key to use to retrieve the value

Return type

pamqp.common.FieldValue

Raises

KeyError

__iter__()

Iterate the attributes and values as key, value pairs

Return type

(str, pamqp.common.FieldValue)

__len__()

Return the length of the attribute list

Return type

int

classmethod amqp_type(attr)

Return the AMQP data type for an attribute

Parameters

attr (str) – The attribute name

Return type

str

classmethod attributes()

Return the list of attributes

Return type

list

class pamqp.base.BasicProperties[source]

Provide a base object that marshals and unmarshals the Basic.Properties object values.

__eq__(other)[source]

Return self==value.

Parameters

other (object) –

Return type

bool

encode_property(name, value)[source]

Encode a single property value

Parameters
Raises

TypeError

Return type

bytes

marshal()[source]

Take the Basic.Properties data structure and marshal it into the data structure needed for the ContentHeader.

Return type

bytes

unmarshal(flags, data)[source]

Dynamically decode the frame data applying the values to the method object by iterating through the attributes in order and decoding them.

Parameters
Return type

None

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError

Return type

None

__contains__(item)

Return if the item is in the attribute list

Parameters

item (str) –

Return type

bool

__getitem__(item)

Return an attribute as if it were a dict

Parameters

item (str) – The key to use to retrieve the value

Return type

pamqp.common.FieldValue

Raises

KeyError

__iter__()

Iterate the attributes and values as key, value pairs

Return type

(str, pamqp.common.FieldValue)

__len__()

Return the length of the attribute list

Return type

int

classmethod amqp_type(attr)

Return the AMQP data type for an attribute

Parameters

attr (str) – The attribute name

Return type

str

classmethod attributes()

Return the list of attributes

Return type

list

pamqp.body

The pamqp.body module contains the Body class which is used when unmarshalling body frames. When dealing with content frames, the message body will be returned from the library as an instance of the body class.

class pamqp.body.ContentBody(value)[source]

ContentBody carries the value for an AMQP message body frame

Parameters

value (bytes) – The value for the ContentBody frame

__len__()[source]

Return the length of the content body value

Return type

int

marshal()[source]

Return the marshaled content body. This method is here for API compatibility, there is no special marshaling for the payload in a content frame.

Return type

bytes

unmarshal(data)[source]

Apply the data to the object. This method is here for API compatibility, there is no special unmarshalling for the payload in a content frame.

Parameters

data (bytes) – The content body data from the frame

Return type

None

pamqp.commands

The classes inside pamqp.commands allow for the automatic marshaling and unmarshaling of AMQP method frames and Basic.Properties. In addition the command classes contain information that designates if they are synchronous commands and if so, what the expected responses are. Each commands arguments are detailed in the class and are listed in the attributes property.

Note

All AMQ classes and methods extend pamqp.base.Frame.

class pamqp.commands.Connection[source]

Work with socket connections

The connection class provides methods for a client to establish a network connection to a server, and for both peers to operate the connection thereafter.

class Start(version_major=0, version_minor=9, server_properties=None, mechanisms='PLAIN', locales='en_US')[source]

Start connection negotiation

This method starts the connection negotiation process by telling the client the protocol version that the server proposes, along with a list of security mechanisms which the client can use for authentication.

Parameters
  • version_major (int) – Protocol major version - Default: 0

  • version_minor (int) – Protocol minor version - Default: 9

  • server_properties (FieldTable) – Server properties - Default: {}

  • mechanisms (str) – Available security mechanisms - Default: PLAIN

  • locales (str) – Available message locales - Default: en_US

class StartOk(client_properties=None, mechanism='PLAIN', response='', locale='en_US')[source]

Select security mechanism and locale

This method selects a SASL security mechanism.

Parameters
  • client_properties (FieldTable) – Client properties - Default: {}

  • mechanism (str) – Selected security mechanism - Default: PLAIN

  • response (str) – Security response data - Default: ''

  • locale (str) – Selected message locale - Default: en_US

class Secure(challenge=None)[source]

Security mechanism challenge

The SASL protocol works by exchanging challenges and responses until both peers have received sufficient information to authenticate each other. This method challenges the client to provide more information.

Parameters

challenge (typing.Optional[str]) – Security challenge data

class SecureOk(response=None)[source]

Security mechanism response

This method attempts to authenticate, passing a block of SASL data for the security mechanism at the server side.

Parameters

response (typing.Optional[str]) – Security response data

class Tune(channel_max=0, frame_max=0, heartbeat=0)[source]

Propose connection tuning parameters

This method proposes a set of connection configuration values to the client. The client can accept and/or adjust these.

Parameters
  • channel_max (int) – Proposed maximum channels - Default: 0

  • frame_max (int) – Proposed maximum frame size - Default: 0

  • heartbeat (int) – Desired heartbeat delay - Default: 0

class TuneOk(channel_max=0, frame_max=0, heartbeat=0)[source]

Negotiate connection tuning parameters

This method sends the client’s connection tuning parameters to the server. Certain fields are negotiated, others provide capability information.

Parameters
  • channel_max (int) – Negotiated maximum channels - Default: 0

  • frame_max (int) – Negotiated maximum frame size - Default: 0

  • heartbeat (int) – Desired heartbeat delay - Default: 0

class Open(virtual_host='/', capabilities='', insist=False)[source]

Open connection to virtual host

This method opens a connection to a virtual host, which is a collection of resources, and acts to separate multiple application domains within a server. The server may apply arbitrary limits per virtual host, such as the number of each type of entity that may be used, per connection and/or in total.

Parameters
  • virtual_host (str) – Virtual host name - Default: /

  • capabilities (str) – Deprecated, must be empty - Default: ''

  • insist (bool) – Deprecated, must be False - Default: False

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class OpenOk(known_hosts='')[source]

Signal that connection is ready

This method signals to the client that the connection is ready for use.

Parameters

known_hosts (str) – Deprecated, must be empty - Default: ''

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class Close(reply_code=None, reply_text='', class_id=None, method_id=None)[source]

Request a connection close

This method indicates that the sender wants to close the connection. This may be due to internal conditions (e.g. a forced shut-down) or due to an error handling a specific method, i.e. an exception. When a close is due to an exception, the sender provides the class and method id of the method which caused the exception.

Parameters
class CloseOk[source]

Confirm a connection close

This method confirms a Connection.Close method and tells the recipient that it is safe to release resources for the connection and close the socket.

class Blocked(reason='')[source]

Indicate that connection is blocked

This method indicates that a connection has been blocked and does not accept new publishes.

Parameters

reason (str) – Block reason - Default: ''

class Unblocked[source]

Indicate that connection is unblocked

This method indicates that a connection has been unblocked and now accepts publishes.

class UpdateSecret(new_secret=None, reason=None)[source]

Update secret

This method updates the secret used to authenticate this connection. It is used when secrets have an expiration date and need to be renewed, like OAuth 2 tokens.

Parameters
class UpdateSecretOk[source]

Update secret response

This method confirms the updated secret is valid.

class pamqp.commands.Channel[source]

Work with channels

The channel class provides methods for a client to establish a channel to a server and for both peers to operate the channel thereafter.

class Open(out_of_band='0')[source]

Open a channel for use

This method opens a channel to the server.

Parameters

out_of_band (str) – Protocol level field, do not use, must be 0. - Default: 0

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class OpenOk(channel_id='0')[source]

Signal that the channel is ready

This method signals to the client that the channel is ready for use.

Parameters

channel_id (str) – Deprecated, must be 0 - Default: 0

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class Flow(active=None)[source]

Enable/disable flow from peer

This method asks the peer to pause or restart the flow of content data sent by a consumer. This is a simple flow-control mechanism that a peer can use to avoid overflowing its queues or otherwise finding itself receiving more messages than it can process. Note that this method is not intended for window control. It does not affect contents returned by Basic.GetOk methods.

Parameters

active (typing.Optional[bool]) – Start/stop content frames

class FlowOk(active=None)[source]

Confirm a flow method

Confirms to the peer that a flow command was received and processed.

Parameters

active (typing.Optional[bool]) – Current flow setting

class Close(reply_code=None, reply_text='', class_id=None, method_id=None)[source]

Request a channel close

This method indicates that the sender wants to close the channel. This may be due to internal conditions (e.g. a forced shut-down) or due to an error handling a specific method, i.e. an exception. When a close is due to an exception, the sender provides the class and method id of the method which caused the exception.

Parameters
class CloseOk[source]

Confirm a channel close

This method confirms a Channel.Close method and tells the recipient that it is safe to release resources for the channel.

class pamqp.commands.Exchange[source]

Work with exchanges

Exchanges match and distribute messages across queues. Exchanges can be configured in the server or declared at runtime.

class Declare(ticket=0, exchange='', exchange_type='direct', passive=False, durable=False, auto_delete=False, internal=False, nowait=False, arguments=None)[source]

Verify exchange exists, create if needed

This method creates an exchange if it does not already exist, and if the exchange exists, verifies that it is of the correct and expected class.

Note

The AMQP type argument is referred to as “exchange_type” to not conflict with the Python type keyword.

Parameters
  • ticket (int) – Deprecated, must be 0 - Default: 0

  • exchange (str) – exchange name - Default: ''

  • exchange_type (str) – Exchange type - Default: direct

  • passive (bool) – Do not create exchange - Default: False

  • durable (bool) – Request a durable exchange - Default: False

  • auto_delete (bool) – Auto-delete when unused - Default: False

  • internal (bool) – Create internal exchange - Default: False

  • nowait (bool) – Do not send a reply method - Default: False

  • arguments (Arguments) – Arguments for declaration - Default: {}

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class DeclareOk[source]

Confirm exchange declaration

This method confirms a Declare method and confirms the name of the exchange, essential for automatically-named exchanges.

class Delete(ticket=0, exchange='', if_unused=False, nowait=False)[source]

Delete an exchange

This method deletes an exchange. When an exchange is deleted all queue bindings on the exchange are cancelled.

Parameters
  • ticket (int) – Deprecated, must be 0 - Default: 0

  • exchange (str) – exchange name - Default: ''

  • if_unused (bool) – Delete only if unused - Default: False

  • nowait (bool) – Do not send a reply method - Default: False

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class DeleteOk[source]

Confirm deletion of an exchange

This method confirms the deletion of an exchange.

class Bind(ticket=0, destination='', source='', routing_key='', nowait=False, arguments=None)[source]

Bind exchange to an exchange

This method binds an exchange to an exchange.

Parameters
  • ticket (int) – Deprecated, must be 0 - Default: 0

  • destination (str) – Name of the destination exchange to bind to - Default: ''

  • source (str) – Name of the source exchange to bind to - Default: ''

  • routing_key (str) – Message routing key - Default: ''

  • nowait (bool) – Do not send a reply method - Default: False

  • arguments (Arguments) – Arguments for binding - Default: {}

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class BindOk[source]

Confirm bind successful

This method confirms that the bind was successful.

class Unbind(ticket=0, destination='', source='', routing_key='', nowait=False, arguments=None)[source]

Unbind an exchange from an exchange

This method unbinds an exchange from an exchange.

Parameters
  • ticket (int) – Deprecated, must be 0 - Default: 0

  • destination (str) – Specifies the name of the destination exchange to unbind. - Default: ''

  • source (str) – Specifies the name of the source exchange to unbind. - Default: ''

  • routing_key (str) – Routing key of binding - Default: ''

  • nowait (bool) – Do not send a reply method - Default: False

  • arguments (Arguments) – Arguments of binding - Default: {}

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class UnbindOk[source]

Confirm unbind successful

This method confirms that the unbind was successful.

class pamqp.commands.Queue[source]

Work with queues

Queues store and forward messages. Queues can be configured in the server or created at runtime. Queues must be attached to at least one exchange in order to receive messages from publishers.

class Declare(ticket=0, queue='', passive=False, durable=False, exclusive=False, auto_delete=False, nowait=False, arguments=None)[source]

Declare queue, create if needed

This method creates or checks a queue. When creating a new queue the client can specify various properties that control the durability of the queue and its contents, and the level of sharing for the queue.

Parameters
  • ticket (int) – Deprecated, must be 0 - Default: 0

  • queue (str) – queue name - Default: ''

  • passive (bool) – Do not create queue - Default: False

  • durable (bool) – Request a durable queue - Default: False

  • exclusive (bool) – Request an exclusive queue - Default: False

  • auto_delete (bool) – Auto-delete queue when unused - Default: False

  • nowait (bool) – Do not send a reply method - Default: False

  • arguments (Arguments) – Arguments for declaration - Default: {}

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class DeclareOk(queue=None, message_count=None, consumer_count=None)[source]

Confirms a queue definition

This method confirms a Declare method and confirms the name of the queue, essential for automatically-named queues.

Parameters
  • queue (typing.Optional[str]) – Reports the name of the queue. If the server generated a queue name, this field contains that name.

  • message_count (typing.Optional[int]) – Number of messages in the queue.

  • consumer_count (typing.Optional[int]) – Number of consumers

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class Bind(ticket=0, queue='', exchange='', routing_key='', nowait=False, arguments=None)[source]

Bind queue to an exchange

This method binds a queue to an exchange. Until a queue is bound it will not receive any messages. In a classic messaging model, store-and- forward queues are bound to a direct exchange and subscription queues are bound to a topic exchange.

Parameters
  • ticket (int) – Deprecated, must be 0 - Default: 0

  • queue (str) – Specifies the name of the queue to bind. - Default: ''

  • exchange (str) – Name of the exchange to bind to - Default: ''

  • routing_key (str) – Message routing key - Default: ''

  • nowait (bool) – Do not send a reply method - Default: False

  • arguments (Arguments) – Arguments for binding - Default: {}

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class BindOk[source]

Confirm bind successful

This method confirms that the bind was successful.

class Purge(ticket=0, queue='', nowait=False)[source]

Purge a queue

This method removes all messages from a queue which are not awaiting acknowledgment.

Parameters
  • ticket (int) – Deprecated, must be 0 - Default: 0

  • queue (str) – Specifies the name of the queue to purge. - Default: ''

  • nowait (bool) – Do not send a reply method - Default: False

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class PurgeOk(message_count=None)[source]

Confirms a queue purge

This method confirms the purge of a queue.

Parameters

message_count (typing.Optional[int]) – Reports the number of messages purged.

class Delete(ticket=0, queue='', if_unused=False, if_empty=False, nowait=False)[source]

Delete a queue

This method deletes a queue. When a queue is deleted any pending messages are sent to a dead-letter queue if this is defined in the server configuration, and all consumers on the queue are cancelled.

Parameters
  • ticket (int) – Deprecated, must be 0 - Default: 0

  • queue (str) – Specifies the name of the queue to delete. - Default: ''

  • if_unused (bool) – Delete only if unused - Default: False

  • if_empty (bool) – Delete only if empty - Default: False

  • nowait (bool) – Do not send a reply method - Default: False

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class DeleteOk(message_count=None)[source]

Confirm deletion of a queue

This method confirms the deletion of a queue.

Parameters

message_count (typing.Optional[int]) – Reports the number of messages deleted.

class Unbind(ticket=0, queue='', exchange='', routing_key='', arguments=None)[source]

Unbind a queue from an exchange

This method unbinds a queue from an exchange.

Parameters
  • ticket (int) – Deprecated, must be 0 - Default: 0

  • queue (str) – Specifies the name of the queue to unbind. - Default: ''

  • exchange (str) – The name of the exchange to unbind from. - Default: ''

  • routing_key (str) – Routing key of binding - Default: ''

  • arguments (Arguments) – Arguments of binding - Default: {}

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class UnbindOk[source]

Confirm unbind successful

This method confirms that the unbind was successful.

class pamqp.commands.Basic[source]

Work with basic content

The Basic class provides methods that support an industry-standard messaging model.

class Qos(prefetch_size=0, prefetch_count=0, global_=False)[source]

Specify quality of service

This method requests a specific quality of service. The QoS can be specified for the current channel or for all channels on the connection. The particular properties and semantics of a qos method always depend on the content class semantics. Though the qos method could in principle apply to both peers, it is currently meaningful only for the server.

Parameters
  • prefetch_size (int) – Prefetch window in octets - Default: 0

  • prefetch_count (int) – Prefetch window in messages - Default: 0

  • global – Apply to entire connection - Default: False

  • global_ (bool) –

class QosOk[source]

Confirm the requested qos

This method tells the client that the requested QoS levels could be handled by the server. The requested QoS applies to all active consumers until a new QoS is defined.

class Consume(ticket=0, queue='', consumer_tag='', no_local=False, no_ack=False, exclusive=False, nowait=False, arguments=None)[source]

Start a queue consumer

This method asks the server to start a “consumer”, which is a transient request for messages from a specific queue. Consumers last as long as the channel they were declared on, or until the client cancels them.

Parameters
  • ticket (int) – Deprecated, must be 0 - Default: 0

  • queue (str) – Specifies the name of the queue to consume from. - Default: ''

  • consumer_tag (str) – Specifies the identifier for the consumer. The consumer tag is local to a channel, so two clients can use the same consumer tags. If this field is empty the server will generate a unique tag. - Default: ''

  • no_local (bool) – Do not deliver own messages - Default: False

  • no_ack (bool) – No acknowledgement needed - Default: False

  • exclusive (bool) – Request exclusive access - Default: False

  • nowait (bool) – Do not send a reply method - Default: False

  • arguments (Arguments) – Arguments for declaration - Default: {}

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class ConsumeOk(consumer_tag=None)[source]

Confirm a new consumer

The server provides the client with a consumer tag, which is used by the client for methods called on the consumer at a later stage.

Parameters

consumer_tag (typing.Optional[str]) – Holds the consumer tag specified by the client or provided by the server.

class Cancel(consumer_tag=None, nowait=False)[source]

End a queue consumer

This method cancels a consumer. This does not affect already delivered messages, but it does mean the server will not send any more messages for that consumer. The client may receive an arbitrary number of messages in between sending the cancel method and receiving the cancel- ok reply. It may also be sent from the server to the client in the event of the consumer being unexpectedly cancelled (i.e. cancelled for any reason other than the server receiving the corresponding basic.cancel from the client). This allows clients to be notified of the loss of consumers due to events such as queue deletion. Note that as it is not a MUST for clients to accept this method from the server, it is advisable for the broker to be able to identify those clients that are capable of accepting the method, through some means of capability negotiation.

Parameters
  • consumer_tag (typing.Optional[str]) – Consumer tag

  • nowait (bool) – Do not send a reply method - Default: False

class CancelOk(consumer_tag=None)[source]

Confirm a cancelled consumer

This method confirms that the cancellation was completed.

Parameters

consumer_tag (typing.Optional[str]) – Consumer tag

class Publish(ticket=0, exchange='', routing_key='', mandatory=False, immediate=False)[source]

Publish a message

This method publishes a message to a specific exchange. The message will be routed to queues as defined by the exchange configuration and distributed to any active consumers when the transaction, if any, is committed.

Parameters
  • ticket (int) – Deprecated, must be 0 - Default: 0

  • exchange (str) – Specifies the name of the exchange to publish to. The exchange name can be empty, meaning the default exchange. If the exchange name is specified, and that exchange does not exist, the server will raise a channel exception. - Default: ''

  • routing_key (str) – Message routing key - Default: ''

  • mandatory (bool) – Indicate mandatory routing - Default: False

  • immediate (bool) – Request immediate delivery - Default: False

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class Return(reply_code=None, reply_text='', exchange='', routing_key=None)[source]

Return a failed message

This method returns an undeliverable message that was published with the “immediate” flag set, or an unroutable message published with the “mandatory” flag set. The reply code and text provide information about the reason that the message was undeliverable.

Parameters
  • reply_code (typing.Optional[int]) – Reply code from server

  • reply_text (str) – Localised reply text - Default: ''

  • exchange (str) – Specifies the name of the exchange that the message was originally published to. May be empty, meaning the default exchange. - Default: ''

  • routing_key (typing.Optional[str]) – Message routing key

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class Deliver(consumer_tag=None, delivery_tag=None, redelivered=False, exchange='', routing_key=None)[source]

Notify the client of a consumer message

This method delivers a message to the client, via a consumer. In the asynchronous message delivery model, the client starts a consumer using the Consume method, then the server responds with Deliver methods as and when messages arrive for that consumer.

Parameters
  • consumer_tag (typing.Optional[str]) – Consumer tag

  • delivery_tag (typing.Optional[int]) – Server-assigned delivery tag

  • redelivered (bool) – Message is being redelivered - Default: False

  • exchange (str) – Specifies the name of the exchange that the message was originally published to. May be empty, indicating the default exchange. - Default: ''

  • routing_key (typing.Optional[str]) – Message routing key

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class Get(ticket=0, queue='', no_ack=False)[source]

Direct access to a queue

This method provides a direct access to the messages in a queue using a synchronous dialogue that is designed for specific types of application where synchronous functionality is more important than performance.

Parameters
  • ticket (int) – Deprecated, must be 0 - Default: 0

  • queue (str) – Specifies the name of the queue to get a message from. - Default: ''

  • no_ack (bool) – No acknowledgement needed - Default: False

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class GetOk(delivery_tag=None, redelivered=False, exchange='', routing_key=None, message_count=None)[source]

Provide client with a message

This method delivers a message to the client following a get method. A message delivered by ‘get-ok’ must be acknowledged unless the no-ack option was set in the get method.

Parameters
  • delivery_tag (typing.Optional[int]) – Server-assigned delivery tag

  • redelivered (bool) – Message is being redelivered - Default: False

  • exchange (str) – Specifies the name of the exchange that the message was originally published to. If empty, the message was published to the default exchange. - Default: ''

  • routing_key (typing.Optional[str]) – Message routing key

  • message_count (typing.Optional[int]) – Number of messages in the queue.

Raises

ValueError – when an argument fails to validate

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class GetEmpty(cluster_id='')[source]

Indicate no messages available

This method tells the client that the queue has no messages available for the client.

Parameters

cluster_id (str) – Deprecated, must be empty - Default: ''

validate()[source]

Validate the frame data ensuring all domains or attributes adhere to the protocol specification.

Raises

ValueError – on validation error

Return type

None

class Ack(delivery_tag=0, multiple=False)[source]

Acknowledge one or more messages

When sent by the client, this method acknowledges one or more messages delivered via the Deliver or Get-Ok methods. When sent by server, this method acknowledges one or more messages published with the Publish method on a channel in confirm mode. The acknowledgement can be for a single message or a set of messages up to and including a specific message.

Parameters
  • delivery_tag (int) – Server-assigned delivery tag - Default: 0

  • multiple (bool) – Acknowledge multiple messages - Default: False

class Reject(delivery_tag=None, requeue=True)[source]

Reject an incoming message

This method allows a client to reject a message. It can be used to interrupt and cancel large incoming messages, or return untreatable messages to their original queue.

Parameters
  • delivery_tag (typing.Optional[int]) – Server-assigned delivery tag

  • requeue (bool) – Requeue the message - Default: True

class RecoverAsync(requeue=False)[source]

Redeliver unacknowledged messages

This method asks the server to redeliver all unacknowledged messages on a specified channel. Zero or more messages may be redelivered. This method is deprecated in favour of the synchronous Recover/Recover-Ok.

Deprecated since version This: command is deprecated in AMQP 0-9-1

Parameters

requeue (bool) – Requeue the message - Default: False

class Recover(requeue=False)[source]

Redeliver unacknowledged messages

This method asks the server to redeliver all unacknowledged messages on a specified channel. Zero or more messages may be redelivered. This method replaces the asynchronous Recover.

Parameters

requeue (bool) – Requeue the message - Default: False

class RecoverOk[source]

Confirm recovery

This method acknowledges a Basic.Recover method.

class Nack(delivery_tag=0, multiple=False, requeue=True)[source]

Reject one or more incoming messages

This method allows a client to reject one or more incoming messages. It can be used to interrupt and cancel large incoming messages, or return untreatable messages to their original queue. This method is also used by the server to inform publishers on channels in confirm mode of unhandled messages. If a publisher receives this method, it probably needs to republish the offending messages.

Parameters
  • delivery_tag (int) – Server-assigned delivery tag - Default: 0

  • multiple (bool) – Reject multiple messages - Default: False

  • requeue (bool) – Requeue the message - Default: True

class Properties(content_type=None, content_encoding=None, headers=None, delivery_mode=None, priority=None, correlation_id=None, reply_to=None, expiration=None, message_id=None, timestamp=None, message_type=None, user_id=None, app_id=None, cluster_id='')[source]

Content Properties

Note

The AMQP property type is named message_type as to not conflict with the Python type keyword

Parameters
Raises

ValueError

class pamqp.commands.Tx[source]

Work with transactions

The Tx class allows publish and ack operations to be batched into atomic units of work. The intention is that all publish and ack requests issued within a transaction will complete successfully or none of them will. Servers SHOULD implement atomic transactions at least where all publish or ack requests affect a single queue. Transactions that cover multiple queues may be non-atomic, given that queues can be created and destroyed asynchronously, and such events do not form part of any transaction. Further, the behaviour of transactions with respect to the immediate and mandatory flags on Basic.Publish methods is not defined.

class Select[source]

Select standard transaction mode

This method sets the channel to use standard transactions. The client must use this method at least once on a channel before using the Commit or Rollback methods.

class SelectOk[source]

Confirm transaction mode

This method confirms to the client that the channel was successfully set to use standard transactions.

class Commit[source]

Commit the current transaction

This method commits all message publications and acknowledgments performed in the current transaction. A new transaction starts immediately after a commit.

class CommitOk[source]

Confirm a successful commit

This method confirms to the client that the commit succeeded. Note that if a commit fails, the server raises a channel exception.

class Rollback[source]

Abandon the current transaction

This method abandons all message publications and acknowledgments performed in the current transaction. A new transaction starts immediately after a rollback. Note that unacked messages will not be automatically redelivered by rollback; if that is required an explicit recover call should be issued.

class RollbackOk[source]

Confirm successful rollback

This method confirms to the client that the rollback succeeded. Note that if an rollback fails, the server raises a channel exception.

class pamqp.commands.Confirm[source]

Work with confirms

The Confirm class allows publishers to put the channel in confirm mode and subsequently be notified when messages have been handled by the broker. The intention is that all messages published on a channel in confirm mode will be acknowledged at some point. By acknowledging a message the broker assumes responsibility for it and indicates that it has done something it deems reasonable with it. Unroutable mandatory or immediate messages are acknowledged right after the Basic.Return method. Messages are acknowledged when all queues to which the message has been routed have either delivered the message and received an acknowledgement (if required), or enqueued the message (and persisted it if required). Published messages are assigned ascending sequence numbers, starting at 1 with the first Confirm.Select method. The server confirms messages by sending Basic.Ack methods referring to these sequence numbers.

class Select(nowait=False)[source]

Select confirm mode (i.e. enable publisher acknowledgements)

This method sets the channel to use publisher acknowledgements. The client can only use this method on a non-transactional channel.

Parameters

nowait (bool) – Do not send a reply method - Default: False

class SelectOk[source]

Acknowledge confirm mode

This method confirms to the client that the channel was successfully set to use publisher acknowledgements.

pamqp.common

Common type aliases and classes.

pamqp.common.Arguments = typing.Union[typing.Dict[str, ForwardRef('FieldValue')], NoneType]

Defines an AMQP method arguments argument data type

pamqp.common.FieldArray = typing.List[ForwardRef('FieldValue')]

A data structure for holding an array of field values.

pamqp.common.FieldTable = typing.Dict[str, ForwardRef('FieldValue')]

Field tables are data structures that contain packed name-value pairs.

The name-value pairs are encoded as short string defining the name, and octet defining the values type and then the value itself. The valid field types for tables are an extension of the native integer, bit, string, and timestamp types, and are shown in the grammar. Multi-octet integer fields are always held in network byte order.

Guidelines for implementers:

  • Field names MUST start with a letter, ‘$’ or ‘#’ and may continue with letters, $ or #, digits, or underlines, to a maximum length of 128 characters.

  • The server SHOULD validate field names and upon receiving an invalid field name, it SHOULD signal a connection exception with reply code 503 (syntax error).

  • Decimal values are not intended to support floating point values, but rather fixed-point business values such as currency rates and amounts. They are encoded as an octet representing the number of places followed by a long signed integer. The ‘decimals’ octet is not signed.

  • Duplicate fields are illegal. The behaviour of a peer with respect to a table containing duplicate fields is undefined.

pamqp.common.FieldValue = typing.Union[bool, bytearray, decimal.Decimal, typing.List[ForwardRef('FieldValue')], typing.Dict[str, ForwardRef('FieldValue')], float, int, NoneType, str, datetime.datetime]

Defines valid field values for a FieldTable and a FieldValue

class pamqp.common.Struct[source]

Simple object for getting to the struct objects for pamqp.decode / pamqp.encode.

byte = <Struct object>
double = <Struct object>
float = <Struct object>
integer = <Struct object>
long = <Struct object>
long_long_int = <Struct object>
short = <Struct object>
short_short_int = <Struct object>
short_short_uint = <Struct object>
timestamp = <Struct object>
uint = <Struct object>
ulong = <Struct object>
ushort = <Struct object>

pamqp.decode

Functions for decoding data of various types including field tables and arrays

pamqp.decode.by_type(value, data_type, offset=0)[source]

Decodes values using the specified type

Parameters
  • value (bytes) – The binary value to decode

  • data_type (str) – The data type name of the value

  • offset (int) – The starting position of the data in the byte stream

Return type

tuple (int, pamqp.common.FieldValue)

Raises

ValueError – when the data type is unknown

pamqp.decode.bit(value, position)[source]

Decode a bit value, returning bytes consumed and the value.

Parameters
  • value (bytes) – The binary value to decode

  • position (int) – The position in the byte of the bit value

Return type

tuple (int, bool)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.boolean(value)[source]

Decode a boolean value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, bool)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.byte_array(value)[source]

Decode a byte_array value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, bytearray)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.decimal(value)[source]

Decode a decimal value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, decimal.Decimal)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.double(value)[source]

Decode a double value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, float)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.floating_point(value)[source]

Decode a floating point value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, float)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.long_int(value)[source]

Decode a long integer value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, int)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.long_uint(value)[source]

Decode an unsigned long integer value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, int)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.long_long_int(value)[source]

Decode a long-long integer value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, int)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.long_str(value)[source]

Decode a string value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, str)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.octet(value)[source]

Decode an octet value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, int)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.short_int(value)[source]

Decode a short integer value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, int)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.short_uint(value)[source]

Decode an unsigned short integer value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, int)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.short_short_int(value)[source]

Decode a short-short integer value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, int)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.short_short_uint(value)[source]

Decode a unsigned short-short integer value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, int)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.short_str(value)[source]

Decode a string value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, str)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.timestamp(value)[source]

Decode a timestamp value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, datetime.datetime)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.embedded_value(value)[source]

Dynamically decode a value based upon the starting byte

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, pamqp.common.FieldValue)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.field_array(value)[source]

Decode a field array value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, pamqp.common.FieldArray)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.field_table(value)[source]

Decode a field array value, returning bytes consumed and the value.

Parameters

value (bytes) – The binary value to decode

Return type

tuple (int, pamqp.common.FieldTable)

Raises

ValueError – when the binary data can not be unpacked

pamqp.decode.void(_)[source]

Return a void, no data to decode

Parameters
  • _ (bytes) – The empty bytes object to ignore

  • _

Return type

tuple (int, None)

pamqp.encode

Functions for encoding data of various types including field tables and arrays

pamqp.encode.DEPRECATED_RABBITMQ_SUPPORT = False

Toggle to support older versions of RabbitMQ.

pamqp.encode.support_deprecated_rabbitmq(enabled=True)[source]

Toggle the data types available in field-tables

If called with True, than RabbitMQ versions, the field-table integer types will not support the full AMQP spec.

Parameters

enabled (bool) – Specify if deprecated RabbitMQ versions are supported

Return type

None

pamqp.encode.by_type(value, data_type)[source]

Takes a value of any type and tries to encode it with the specified encoder.

Parameters
Raises

TypeError – when the data_type is unknown

Return type

bytes

pamqp.encode.bit(value, byte, position)[source]

Encode a bit value

Parameters
  • value (int) – Value to encode

  • byte (int) – The byte to apply the value to

  • position (int) – The position in the byte to set the bit on

Return type

int

pamqp.encode.boolean(value)[source]

Encode a boolean value

Parameters

value (bool) – Value to encode

Raises

TypeError – when the value is not the correct type

Return type

bytes

pamqp.encode.byte_array(value)[source]

Encode a byte array value

Parameters

value (bytearray) – Value to encode

Raises

TypeError – when the value is not the correct type

Return type

bytes

pamqp.encode.decimal(value)[source]

Encode a decimal.Decimal value

Parameters

value (decimal.Decimal) – Value to encode

Raises

TypeError – when the value is not the correct type

Return type

bytes

pamqp.encode.double(value)[source]

Encode a floating point value as a double

Parameters

value (float) – Value to encode

Raises

TypeError – when the value is not the correct type

Return type

bytes

pamqp.encode.floating_point(value)[source]

Encode a floating point value

Parameters

value (float) – Value to encode

Raises

TypeError – when the value is not the correct type

Return type

bytes

pamqp.encode.long_int(value)[source]

Encode a long integer

Parameters

value (int) – Value to encode

Raises

TypeError – when the value is not the correct type or outside the acceptable range for the data type

Return type

bytes

pamqp.encode.long_uint(value)[source]

Encode a long unsigned integer

Parameters

value (int) – Value to encode

Raises

TypeError – when the value is not the correct type or outside the acceptable range for the data type

Return type

bytes

pamqp.encode.long_long_int(value)[source]

Encode a long-long int

Parameters

value (int) – Value to encode

Raises

TypeError – when the value is not the correct type or outside the acceptable range for the data type

Return type

bytes

pamqp.encode.long_string(value)[source]

Encode a “long string”

Parameters

value (str) – Value to encode

Raises

TypeError – when the value is not the correct type

Return type

bytes

pamqp.encode.octet(value)[source]

Encode an octet value

Parameters

value (int) – Value to encode

Raises

TypeError – when the value is not the correct type

Return type

bytes

pamqp.encode.short_int(value)[source]

Encode a short integer

Parameters

value (int) – Value to encode

Raises

TypeError – when the value is not the correct type or outside the acceptable range for the data type

Return type

bytes

pamqp.encode.short_uint(value)[source]

Encode an unsigned short integer

Parameters

value (int) – Value to encode

Raises

TypeError – when the value is not the correct type or outside the acceptable range for the data type

Return type

bytes

pamqp.encode.short_string(value)[source]

Encode a string

Parameters

value (str) – Value to encode

Raises

TypeError – when the value is not the correct type

Return type

bytes

pamqp.encode.timestamp(value)[source]

Encode a datetime.datetime object or time.struct_time

Parameters

value (typing.Union[datetime.datetime, time.struct_time]) – Value to encode

Raises

TypeError – when the value is not the correct type

Return type

bytes

pamqp.encode.field_array(value)[source]

Encode a field array from a list of values

Parameters

value (pamqp.common.FieldArray) – Value to encode

Raises

TypeError – when the value is not the correct type

Return type

bytes

pamqp.encode.field_table(value)[source]

Encode a field table from a dict

Parameters

value (pamqp.common.FieldTable) – Value to encode

Raises

TypeError – when the value is not the correct type

Return type

bytes

pamqp.encode.table_integer(value)[source]

Determines the best type of numeric type to encode value as, preferring the smallest data size first.

Parameters

value (int) – Value to encode

Raises

TypeError – when the value is not the correct type or outside the acceptable range for the data type

Return type

bytes

pamqp.encode.encode_table_value(value)[source]

Takes a value of any type and tries to encode it with the proper encoder

Parameters

value (pamqp.common.FieldArray or pamqp.common.FieldTable or pamqp.common.FieldValue) – Value to encode

Raises

TypeError – when the type of the value is not supported

Return type

bytes

pamqp.exceptions

The pamqp.exceptions module is auto-generated, created by the tools/codegen.py application.

pamqp.exceptions implements AMQP exceptions as Python exceptions so that client libraries can raise these exceptions as is appropriate without having to implement their own extensions for AMQP protocol related issues.

exception pamqp.exceptions.PAMQPException[source]

Base exception for all pamqp specific exceptions.

exception pamqp.exceptions.UnmarshalingException[source]

Raised when a frame is not able to be unmarshaled.

exception pamqp.exceptions.AMQPError[source]

Base exception for all AMQP errors.

exception pamqp.exceptions.AMQPSoftError[source]

Base exception for all AMQP soft errors.

exception pamqp.exceptions.AMQPHardError[source]

Base exception for all AMQP hard errors.

exception pamqp.exceptions.AMQPContentTooLarge[source]

The client attempted to transfer content larger than the server could accept at the present time. The client may retry at a later time.

exception pamqp.exceptions.AMQPNoRoute[source]

Returned when RabbitMQ sends back with ‘basic.return’ when a ‘mandatory’ message cannot be delivered to any queue.

exception pamqp.exceptions.AMQPNoConsumers[source]

When the exchange cannot deliver to a consumer when the immediate flag is set. As a result of pending data on the queue or the absence of any consumers of the queue.

exception pamqp.exceptions.AMQPAccessRefused[source]

The client attempted to work with a server entity to which it has no access due to security settings.

exception pamqp.exceptions.AMQPNotFound[source]

The client attempted to work with a server entity that does not exist.

exception pamqp.exceptions.AMQPResourceLocked[source]

The client attempted to work with a server entity to which it has no access because another client is working with it.

exception pamqp.exceptions.AMQPPreconditionFailed[source]

The client requested a method that was not allowed because some precondition failed.

exception pamqp.exceptions.AMQPConnectionForced[source]

An operator intervened to close the connection for some reason. The client may retry at some later date.

exception pamqp.exceptions.AMQPInvalidPath[source]

The client tried to work with an unknown virtual host.

exception pamqp.exceptions.AMQPFrameError[source]

The sender sent a malformed frame that the recipient could not decode. This strongly implies a programming error in the sending peer.

exception pamqp.exceptions.AMQPSyntaxError[source]

The sender sent a frame that contained illegal values for one or more fields. This strongly implies a programming error in the sending peer.

exception pamqp.exceptions.AMQPCommandInvalid[source]

The client sent an invalid sequence of frames, attempting to perform an operation that was considered invalid by the server. This usually implies a programming error in the client.

exception pamqp.exceptions.AMQPChannelError[source]

The client attempted to work with a channel that had not been correctly opened. This most likely indicates a fault in the client layer.

exception pamqp.exceptions.AMQPUnexpectedFrame[source]

The peer sent a frame that was not expected, usually in the context of a content header and body. This strongly indicates a fault in the peer’s content processing.

exception pamqp.exceptions.AMQPResourceError[source]

The server could not complete the method because it lacked sufficient resources. This may be due to the client creating too many of some type of entity.

exception pamqp.exceptions.AMQPNotAllowed[source]

The client tried to work with some entity in a manner that is prohibited by the server, due to security settings or by some other criteria.

exception pamqp.exceptions.AMQPNotImplemented[source]

The client tried to use functionality that is not implemented in the server.

exception pamqp.exceptions.AMQPInternalError[source]

The server could not complete the method because of an internal error. The server may require intervention by an operator in order to resume normal operations.

pamqp.frame

Manage the marshaling and unmarshaling of AMQP frames

unmarshal will turn a raw AMQP byte stream into the appropriate AMQP objects from the specification file.

marshal will take an object created from the specification file and turn it into a raw byte stream.

pamqp.frame.marshal(frame_value, channel_id)[source]

Marshal a frame to be sent over the wire.

Raises

ValueError

Parameters
Return type

bytes

pamqp.frame.unmarshal(data_in)[source]

Takes in binary data and maps builds the appropriate frame type, returning a frame object.

Return type

typing.Tuple[int, int, typing.Union[pamqp.base.Frame, pamqp.body.ContentBody, pamqp.header.ContentHeader, pamqp.header.ProtocolHeader, pamqp.heartbeat.Heartbeat]]

Returns

tuple of bytes consumed, channel, and a frame object

Raises

exceptions.UnmarshalingException

Parameters

data_in (bytes) –

pamqp.frame.frame_parts(data)[source]

Attempt to decode a low-level frame, returning frame parts

Parameters

data (bytes) –

Return type

typing.Tuple[int, int, typing.Optional[int]]

pamqp.header

AMQP Header Class Definitions

For encoding AMQP Header frames into binary AMQP stream data and decoding AMQP binary data into AMQP Header frames.

class pamqp.header.ProtocolHeader(major_version=0, minor_version=9, revision=1)[source]

Class that represents the AMQP Protocol Header

Parameters
  • major_version (int) –

  • minor_version (int) –

  • revision (int) –

marshal()[source]

Return the full AMQP wire protocol frame data representation of the ProtocolHeader frame.

Return type

bytes

unmarshal(data)[source]

Dynamically decode the frame data applying the values to the method object by iterating through the attributes in order and decoding them.

Parameters

data (bytes) – The frame value to unpack

Raises

ValueError

Return type

int

class pamqp.header.ContentHeader(weight=0, body_size=0, properties=None)[source]

Represent a content header frame

A Content Header frame is received after a Basic.Deliver or Basic.GetOk frame and has the data and properties for the Content Body frames that follow.

Parameters
marshal()[source]

Return the AMQP binary encoded value of the frame

Return type

bytes

unmarshal(data)[source]

Dynamically decode the frame data applying the values to the method object by iterating through the attributes in order and decoding them.

Parameters

data (bytes) – The raw frame data to unmarshal

Return type

None

pamqp.heartbeat

AMQP Heartbeat Frame, used to create new Heartbeat frames for sending to a peer

class pamqp.heartbeat.Heartbeat[source]

Heartbeat frame object mapping class. AMQP Heartbeat frames are mapped on to this class for a common access structure to the attributes/data values.

classmethod marshal()[source]

Return the binary frame content

Return type

bytes

Changelog

3.0.1 (2020-08-07)

  • Fix an issue with Basic.Reject requeue=False always being set to True (#29 - eandersson)

3.0.0 (2020-08-04)

  • Fix unsigned short-int encoding and decoding to use the correct amqp field designation of B instad of b (#27)

  • Fix timestamp encoding/decoding tests to work when the timezone is set on the host machine (#26)

3.0.0a6 (2020-03-19)

  • pamqp.commands.Basic.QoS.globally renamed back to pamqp.commands.Basic.QoS.global_

  • Refactored codegen to put params in the class level docstring not __init__

  • Added new pamqp.frame.Frame.validate() method

  • Changed validation to ignore attributes with a value of None

  • Changed default value behaviors to only use default values if one is specified, instead of by data type.

  • Overwrote AMQP spec for queue name max-length to match documented RabbitMQ value (#24)

  • Updated documentation in codegen output

  • Added strict validation of pamqp.commands.Basic.Properties.delivery_mode to ensure it’s 0 or 1

  • Fixed codegen with respect to applying extension data over base spec data

3.0.0a5 (2020-03-11)

  • Rename pamqp.frame._frame_parts to pamqp.frame.frame_parts() (#15 again)

  • pamqp.commands.Basic.QoS.global_ renamed to pamqp.commands.Basic.QoS.globally

  • Removed mypy checking due to errors in mypy and recursive type aliases

  • Added pamqp/py.typed for PEP-561 compatibility (#21 - michael-k)

3.0.0a4 (2020-01-01)

  • Refactor codegen.py

  • Revert the behaviors added in 3.0.0a2 with regard to documented defaults and None

  • Use amqp0-9-1.extended.xml instead of amqp-0-9-1.xml to get the documentation for RabbitMQ added classes/methods

  • Add strict value checking for deprecated values

  • Remove empty __init__ functions from method classes

3.0.0a3 (2019-12-31)

  • Make comparison of Basic.Properties against other object types raise NotImplementedError

  • Return test coverage to 100%

3.0.0a2 (2019-12-31)

  • Added mypy as part of the test pipeline and made updates based upon its findings.

  • Added length checking and regex checking for values specified in AMQP spec

  • Fixed some of the type annotations added in 3.0.0a0

  • Fixed some of the documentation and label usage in pamqp.commands

  • Removed redundant inline documentation in pamqp.commands

  • Updated default values to only reflect defaults specified in the XML and JSON specs. If no default is specified, the value will now be None.

3.0.0a1 (2019-12-19)

  • Revert the removal of pamqp.body.ContentBody.name

3.0.0a0 (2019-12-16)

  • Update to support Python 3.6+ only

  • Add typing annotations to all modules, callables, and classes

  • Moved exceptions from pamqp.specification to pamqp.exceptions

  • Moved constants from pamqp.specification to pamqp.constants

  • Moved base classes out of pamqp.specification to pamqp.base

  • Changed the structure of nested classes for AMQP Commands (Classes & Methods) in pamqp.specification to functions in pamqp.commands

  • Renamed pamqp.specification.ERRORS to pamqp.exceptions.CLASS_MAPPING

  • Remove convenience exports of pamqp.headers.ContentHeader and pamqp.header.ProtocolHeader

  • pamqp.body.ContentBody.value now only supports bytes

  • Changed pamqp.decode.timestamp to return a datetime.datetime instance instead of time.struct_time.

  • Updated pamqp.encode.support_deprecated_rabbitmq() to allow for toggling support.

  • Changed pamqp.encode.timestamp to only support datetime.datetime and time.struct_time values, dropping epoch (int) support.

  • Removed pamqp.frame.BasicProperties.to_dict() in favor of behavior allowing for dict(pamqp.frame.BasicProperties)

  • Optimized pamqp.heartbeat.Heartbeat to marshal the static frame value as a predefined class attribute.

  • Add support for Connection.UpdateSecret and Connection.UpdateSecretOk.

  • Removed the ability to unset a Basic.Property by invoking del properties[key]

  • Removed the deprecated pamqp.codec sub-package

2.3.0 (2019-04-18)

2.2.0 (2019-04-18)

2.1.0 (2018-12-28)

  • Change raising a DeprecationWarning exception to using warnings.warn for deprecated AMQP methods (#13 - dzen)

2.0.0 (2018-09-11)

  • Change Python versions supported to 2.7 and 3.4+

  • Always decode field table keys as strings (#6)
    • This may be a breaking change means in Python3 keys will always be type str for short strings. This includes frame values and field table values.

    • In Python 2.7 if a short-string (key, frame field value, etc) has UTF-8 characters in it, it will be a unicode object.

  • Combine test coverage across all Python versions

  • Fix range for signed short integer (#7)

  • Fix guards for usage of unsigned short usage in pamqp.encode (#7)

  • Fix encoding and decoding of unsigned short (#7)

  • Add support for unsigned short integer and long integer in field tables (#10)

  • Address edge case of small value in long type (#8)

  • Address long string encoding inconsistency (#9)

  • Cleanup unicode object & conditionals in py3 (#9)

  • Add pamqp.exceptions.PAMQPException as a base class for pamqp specific exceptions (#4)

  • Fix decoding of void values in a field table or array

1.6.1 (2015-02-05)

  • Fix the encoding guard for unsigned short integers to be 65535 [rabbitpy #62]

1.6.0 (2014-12-12)

  • Remove UTF-8 encoding from byte_array (#2)

  • Fix AMQP Field Tables / Basic.Properties headers behavior:
    • Field names per spec should not exceed 128 bytes

    • long-strings should not be utf-8 encoded (only short-strings boggle)

  • Ensure that field table long strings are not coerced to UTF-8 as specified in AMQP 0-9-1

    If a string is passed in as a long string in a field table and it contains UTF-8 characters it will be UTF-8 encoded

  • Move AMQP Methods in specification.py to slotted classes

  • Change Basic.Properties to a slotted class

  • Instead of class level attributes with the same name as obj attributes, prefix class attributes for data types with an underscore

  • Add new class method type() for Basic.Properties for accessing data type

  • Add new class method type() for AMQP methods for accessing data type

  • Change Basic.Properties.attributes to Basic.Properties.attributes(), returning the list of slotted attributes

  • Fix a typo for booleans in the method mapping for table decoding

  • Frame.__getitem__ will now raise a KeyError instead of None for an invalid attribute

  • PropertiesBase no longer checks to see if an attribute is set for contains

  • Adds new specification tests

  • More efficiently handle the frame end character in Python 3

1.5.0 (2014-11-05)

  • Cleanup how UTF-8 is handled in decoding strings

  • Ensure that field tables (headers property, etc) can use keys with utf-8 data

  • Address missing and mis-aligned AMQP-0-9-1 field table decoding with the field type indicators from the RabbitMQ protocol errata page

  • Fix a encoding by type bug introduced with 1.4 having to do with bytearrays

  • Be explicit about needing a class id in the ContentHeader

  • Update the tests to reflect the unicode changes

  • Clean up the tests

1.4.0 (2014-11-04)

  • Fix a long standing bug for non-specified responses for RabbitMQ AMQP extensions

  • Refactor adding bytearrays and recoding complexity

  • Add bytearray support (#1 and gmr/rabbitpy#48)

  • Change encode/decode type errors from ValueError to TypeError exceptions

  • Remove separate codecs for Python 2 & 3

  • Move codecs from pamqp.codec.encode and pamqp.codec.decode to pamqp.encode and pamqp.decode

  • Deprecate pamqp.codec

  • Remove weird imports from top level __init__.py, not sure what I was thinking there

  • Clean up codegen a bit to make it more PYTHON3 compatible

  • Update codegen/include for new codec and PYTHON2/PYTHON3 behavior

  • Update documentation

  • Distribution updates:
    • Let travis upload to pypi

    • Add wheel distribution

    • Update supported python versions

    • Update classifiers

1.3.1 (2014-02-14)

  • Fix encoding of long-long-integers

1.3.0 (2014-01-17)

  • Remove support for short strings in field tables

1.2.4 (2013-12-22)

  • Add short-short-int support

1.2.3 (2013-12-22)

  • Fix distribution requirements

1.2.2 (2013-12-22)

  • Add decimal data type support

1.2.1 (2013-07-29)

  • Fix Confirm.Select definition

1.2.0 (2013-07-08)

  • Add support for Connection.Blocked, Connection.Unblocked

  • Add documentation to specification.py in the codegen process

1.1.3 (2013-03-27)

  • Fix exception creation

1.1.2 (2013-03-27)

  • Add Confirm.Select, Confirm.SelectOk

1.1.1 (2013-03-22)

  • Remove debugging print statements (eek)

1.1.0 (2013-03-21)

  • Add Python 3.3 support

1.0.1 (2012-10-02)

  • Address Unicode issues

  • Add void support in table arrays

1.0.0 (2012-09-24)

  • Initial version

Index

License

Copyright (c) 2011-2022 Gavin M. Roy All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.