Making and parsing messages

The core of Jeepney is code to build, serialise and deserialise DBus messages.

class jeepney.Message(header, body)[source]

Object representing a DBus message.

It’s not normally necessary to construct this directly: use higher level functions and methods instead.

serialise()[source]

Convert this message to bytes.

class jeepney.Parser[source]

Parse DBus messages from a stream of incoming data.

feed(data)[source]

Feed the parser newly read data.

Returns a list of messages completed by the new data.

Making messages

class jeepney.DBusAddress(object_path, bus_name=None, interface=None)[source]

This identifies the object and interface a message is for.

e.g. messages to display desktop notifications would have this address:

DBusAddress('/org/freedesktop/Notifications',
            bus_name='org.freedesktop.Notifications',
            interface='org.freedesktop.Notifications')
jeepney.new_method_call(remote_obj, method, signature=None, body=())[source]

Construct a new method call message

Parameters
  • remote_obj (DBusAddress) – The object to call a method on

  • method (str) – The name of the method to call

  • signature (str) – The DBus signature of the body data

  • body (tuple) – Body data (i.e. method parameters)

jeepney.new_method_return(parent_msg, signature=None, body=())[source]

Construct a new response message

Parameters
  • parent_msg (Message) – The method call this is a reply to

  • signature (str) – The DBus signature of the body data

  • body (tuple) – Body data

jeepney.new_error(parent_msg, error_name, signature=None, body=())[source]

Construct a new error response message

Parameters
  • parent_msg (Message) – The method call this is a reply to

  • signature (str) – The DBus signature of the body data

  • body (tuple) – Body data

jeepney.new_signal(emitter, signal, signature=None, body=())[source]

Construct a new signal message

Parameters
  • emitter (DBusAddress) – The object sending the signal

  • signal (str) – The name of the signal

  • signature (str) – The DBus signature of the body data

  • body (tuple) – Body data

Signatures

DBus is strongly typed, and every message has a signature describing the body data. These are strings using characters such as i for a signed 32-bit integer. See the DBus specification for the full list.

Jeepney does not try to guess or discover the signature when you build a message: your code must explicitly specify a signature for every message. However, Jeepney can help you write this code: see Generating D-Bus wrappers.

In most cases, DBus types have an obvious corresponding type in Python. However, a few types require further explanation:

  • DBus ARRAY are Python lists, except for arrays of DICT_ENTRY, which are dicts.

  • DBus STRUCT are Python tuples.

  • DBus VARIANT are 2-tuples (signature, data). E.g. to put a string into a variant field, you would pass the data ("s", "my string").

  • Jeepney does not (yet) support sending or receiving file descriptors.