Making and parsing messages

The core of Jeepney is code to build, serialise and deserialise D-Bus messages.

Making messages

D-Bus has four message types. Three, method call, method return and error, are used in a request-reply pattern. The fourth, signal, is a broadcast message with no reply.

All of these return a Message object. Message.serialise() converts it to bytes, but none of these core methods ever send a message. See the integration layer for that.

Signatures

D-Bus 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.

D-Bus types are converted to and from native Python objects as follows:

  • All the D-Bus integer types are represented as Python int, including BYTE when it’s not in an array.
  • BOOLEAN is bool.
  • DOUBLE is float.
  • STRING, OBJECT_PATH and SIGNATURE are all str.
  • ARRAY is list, except that an array of BYTE is a bytes object, and an array of DICT_ENTRY is a dict.
  • STRUCT is tuple.
  • VARIANT is a 2-tuple (signature, data). E.g. to put a string into a variant field, you would pass the data ("s", "my string").
  • UNIX_FD are converted from objects with a .fileno() method or plain integers, and converted to FileDescriptor objects. See Sending & receiving file descriptors for more details.