# 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)

  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: DBusConnection)

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

  This runs a separate receiver task and dispatches received messages.

  async send(message, *, serial=None)

    Send a message, don’t wait for a reply

  async send_and_get_reply(message) → Message

    Send a method call message and wait for the reply

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

  filter(rule, *, channel: MemorySendChannel | None = None, bufsize=1)

    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

  async aclose()

    Stop the sender & receiver tasks

    Leaving the `async with` block will also close the router.

class jeepney.io.trio.Proxy(msggen, router)

  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.

  See also

  Message generators and proxies

async jeepney.io.trio.open_dbus_connection(bus='SESSION', *, enable_fds=False) → DBusConnection

  Open a plain D-Bus connection

  Returns:

    `DBusConnection`

class jeepney.io.trio.DBusConnection(socket, enable_fds=False)

  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.

  async send(message: Message, *, serial=None)

    Serialise and send a `Message` object

  async receive() → Message

    Return the next available message from the connection

  router()

    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.

  async aclose()

    Close the D-Bus connection