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')[source]

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)[source]

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)[source]

Send a message, don’t wait for a reply

async send_and_get_reply(message) Message[source]

Send a method call message and wait for the reply

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

filter(rule, *, queue: Optional[Queue] = None, bufsize=1)[source]

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)[source]

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.

async jeepney.io.asyncio.open_dbus_connection(bus='SESSION')[source]

Open a plain D-Bus connection

Returns:

DBusConnection

class jeepney.io.asyncio.DBusConnection(reader: StreamReader, writer: StreamWriter)[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.

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

Serialise and send a Message object

async receive() Message[source]

Return the next available message from the connection

async close()[source]

Close the D-Bus connection