# Asyncio integration

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

jeepney.io.asyncio.open_dbus_router(bus='SESSION')

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

  Use as an async context manager:

      async with open_dbus_router() as router:
          ...

class jeepney.io.asyncio.DBusRouter(conn: DBusConnection)

  A ‘client’ D-Bus connection which can wait for a specific reply.

  This runs a background receiver task, and makes it possible to send a request and wait for the relevant reply.

  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, *, queue: Queue | None = None, bufsize=1)

    Create a filter for incoming messages

    Usage:

        with router.filter(rule) as queue:
            matching_msg = await queue.get()

    Parameters:

      - rule (MatchRule) – Catch messages matching this rule

      - queue (asyncio.Queue) – Send matching messages here

      - bufsize (int) – If no queue is passed in, create one with this size

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

  An asyncio 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.asyncio.open_dbus_connection(bus='SESSION')

  Open a plain D-Bus connection

  Returns:

    `DBusConnection`

class jeepney.io.asyncio.DBusConnection(reader: StreamReader, writer: StreamWriter)

  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`.

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

    Serialise and send a `Message` object

  async receive() → Message

    Return the next available message from the connection

  async close()

    Close the D-Bus connection