Trio integration

This supports D-Bus in applications built with Trio. See Connections and Routers for more about the two interfaces.

jeepney.io.trio.open_dbus_router(bus='SESSION', *, enable_fds=False)[source]

Open a D-Bus ‘router’ to send and receive messages.

Use as an async context manager:

async with open_dbus_router() as req:
    ...
Parameters:bus (str) – ‘SESSION’ or ‘SYSTEM’ or a supported address.
Returns:DBusRouter

This is a shortcut for:

conn = await open_dbus_connection()
async with conn:
    async with conn.router() as req:
        ...
class jeepney.io.trio.DBusRouter(conn: jeepney.io.trio.DBusConnection)[source]

A client D-Bus connection which can wait for replies.

This runs a separate receiver task and dispatches received messages.

send(message, *, serial=None)[source]

Send a message, don’t wait for a reply

send_and_get_reply(message) → jeepney.low_level.Message[source]

Send a method call message and wait for the reply

Returns the reply message (method return or error message type).

filter(rule, *, channel: Optional[trio.MemorySendChannel] = None, bufsize=1)[source]

Create a filter for incoming messages

Usage:

async with router.filter(rule) as receive_channel:
    matching_msg = await receive_channel.receive()

# OR:
send_chan, recv_chan = trio.open_memory_channel(1)
async with router.filter(rule, channel=send_chan):
    matching_msg = await recv_chan.receive()

If the channel fills up, The sending end of the channel is closed when leaving the async with block, whether or not it was passed in.

Parameters:
  • rule (jeepney.MatchRule) – Catch messages matching this rule
  • channel (trio.MemorySendChannel) – Send matching messages here
  • bufsize (int) – If no channel is passed in, create one with this size
aclose()[source]

Stop the sender & receiver tasks

Leaving the async with block will also close the router.

class jeepney.io.trio.Proxy(msggen, router)[source]

A trio proxy for calling D-Bus methods

You can call methods on the proxy object, such as await bus_proxy.Hello() to make a method call over D-Bus and wait for a reply. It will either return a tuple of returned data, or raise DBusErrorResponse. The methods available are defined by the message generator you wrap.

Parameters:
  • msggen – A message generator object.
  • router (DBusRouter) – Router to send and receive messages.
jeepney.io.trio.open_dbus_connection(bus='SESSION', *, enable_fds=False) → jeepney.io.trio.DBusConnection[source]

Open a plain D-Bus connection

Returns:DBusConnection
class jeepney.io.trio.DBusConnection(socket, enable_fds=False)[source]

A plain D-Bus connection with no matching of replies.

This doesn’t run any separate tasks: sending and receiving are done in the task that calls those methods. It’s suitable for implementing servers: several worker tasks can receive requests and send replies. For a typical client pattern, see DBusRouter.

Implements trio’s channel interface for Message objects.

send(message: jeepney.low_level.Message, *, serial=None)[source]

Serialise and send a Message object

receive() → jeepney.low_level.Message[source]

Return the next available message from the connection

router()[source]

Temporarily wrap this connection as a DBusRouter

To be used like:

async with conn.router() as req:
    reply = await req.send_and_get_reply(msg)

While the router is running, you shouldn’t use receive(). Once the router is closed, you can use the plain connection again.

aclose()[source]

Close the D-Bus connection