Skip to main content

dbus-fast

CI Status Documentation Status Test coverage percentage

Poetry Ruff pre-commit CodSpeed Badge

PyPI Version Supported Python versions License

A faster version of dbus-next originally from the great DBus next library ❤️

Installation

Install this via pip (or your favourite package manager):

pip install dbus-fast

Documentation

dbus-fast is a Python library for DBus that aims to be a performant fully featured high level library primarily geared towards integration of applications into Linux desktop and mobile environments.

Desktop application developers can use this library for integrating their applications into desktop environments by implementing common DBus standard interfaces or creating custom plugin interfaces.

Desktop users can use this library to create their own scripts and utilities to interact with those interfaces for customization of their desktop environment.

dbus-fast plans to improve over other DBus libraries for Python in the following ways:

  • Zero dependencies and pure Python 3
  • An optional cython extension is available to speed up (un)marshalling
  • Focus on performance
  • Support for multiple IO backends including asyncio and the GLib main loop.
  • Nonblocking IO suitable for GUI development.
  • Target the latest language features of Python for beautiful services and clients.
  • Complete implementation of the DBus type system without ever guessing types.
  • Integration tests for all features of the library.
  • Completely documented public API.

Installing

This library is available on PyPi as dbus-fast.

pip3 install dbus-fast

Installing without the Cython extension

The PyPI wheels bundle an optional Cython extension that speeds up the marshalling/unmarshalling hot paths but adds a few MB to the installed size. If you're bundling dbus-fast into a size-sensitive application and don't need the extra performance, install the pure-Python version by forcing a source build with SKIP_CYTHON=1:

SKIP_CYTHON=1 pip3 install --no-binary dbus-fast dbus-fast

See the installation docs for details.

The Client Interface

To use a service on the bus, the library constructs a proxy object you can use to call methods, get and set properties, and listen to signals.

For more information, see the overview for the high-level client.

This example connects to a media player and controls it with the MPRIS DBus interface.

from dbus_fast.aio import MessageBus

import asyncio


async def main():
    bus = await MessageBus().connect()
    # the introspection xml would normally be included in your project, but
    # this is convenient for development
    introspection = await bus.introspect(
        "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2"
    )

    obj = bus.get_proxy_object(
        "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2", introspection
    )
    player = obj.get_interface("org.mpris.MediaPlayer2.Player")
    properties = obj.get_interface("org.freedesktop.DBus.Properties")

    # call methods on the interface (this causes the media player to play)
    await player.call_play()

    volume = await player.get_volume()
    print(f"current volume: {volume}, setting to 0.5")

    await player.set_volume(0.5)

    # listen to signals
    def on_properties_changed(
        interface_name, changed_properties, invalidated_properties
    ):
        for changed, variant in changed_properties.items():
            print(f"property changed: {changed} - {variant.value}")

    properties.on_properties_changed(on_properties_changed)

    await asyncio.Event().wait()


asyncio.run(main())

The Service Interface

To define a service on the bus, use the ServiceInterface class and decorate class methods to specify DBus methods, properties, and signals with their type signatures.

For more information, see the overview for the high-level service.

from dbus_fast.annotations import DBusStr, DBusDict
from dbus_fast.service import ServiceInterface, dbus_method, dbus_property, dbus_signal
from dbus_fast import Variant
from dbus_fast.aio import MessageBus

import asyncio


class ExampleInterface(ServiceInterface):
    def __init__(self, name):
        super().__init__(name)
        self._string_prop = "kevin"

    @dbus_method()
    def Echo(self, what: DBusStr) -> DBusStr:
        return what

    @dbus_method()
    def GetVariantDict(self) -> DBusDict:
        return {
            "foo": Variant("s", "bar"),
            "bat": Variant("x", -55),
            "a_list": Variant("as", ["hello", "world"]),
        }

    @dbus_property()
    def string_prop(self) -> DBusStr:
        return self._string_prop

    @string_prop.setter
    def string_prop_setter(self, val: DBusStr):
        self._string_prop = val

    @dbus_signal()
    def signal_simple(self) -> DBusStr:
        return "hello"


async def main():
    bus = await MessageBus().connect()
    interface = ExampleInterface("test.interface")
    bus.export("/test/path", interface)
    # now that we are ready to handle requests, we can request name from D-Bus
    await bus.request_name("test.name")
    # wait indefinitely
    await asyncio.Event().wait()


asyncio.run(main())

The Low-Level Interface

The low-level interface works with DBus messages directly.

For more information, see the overview for the low-level interface.

from dbus_fast.message import Message, MessageType
from dbus_fast.aio import MessageBus

import asyncio
import json


async def main():
    bus = await MessageBus().connect()

    reply = await bus.call(
        Message(
            destination="org.freedesktop.DBus",
            path="/org/freedesktop/DBus",
            interface="org.freedesktop.DBus",
            member="ListNames",
        )
    )

    if reply.message_type == MessageType.ERROR:
        raise Exception(reply.body[0])

    print(json.dumps(reply.body[0], indent=2))


asyncio.run(main())

Projects that use dbus-fast

Contributing

Contributions are welcome. Development happens on Github.

Before you commit, run pre-commit run --all-files to run the linter, code formatter, and the test suite.

You can use this code under an MIT license (see LICENSE).

  • © 2019, Tony Crisci
  • © 2022, Bluetooth Devices authors

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

Credits

This package was created with Cookiecutter and the browniebroke/cookiecutter-pypackage project template.

Metadata

Release files for dbus-fast 5.0.25

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dbus-fast 5.0.25
File Size Uploaded
dbus_fast-5.0.25.tar.gz 85.8 kB Details

Release files / dbus_fast-5.0.25.tar.gz

Download URL dbus_fast-5.0.25.tar.gz
Size 85.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6491daa9edacbd28770ff84522ff9a335591a74d1da12ba06b395d1bde077f6a
BLAKE2b-256 checksum
How to use checksums
5b99898122941a032252282c6e52b9f34027fd542caa789b256328769d321918
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

5.0.25 This release

1 release file

5.0.9

49 release files

5.0.8

49 release files

5.0.7

49 release files

5.0.6

49 release files

5.0.5

49 release files

5.0.4

49 release files

5.0.3

49 release files

5.0.2

49 release files

5.0.1

49 release files

5.0.0

49 release files

4.3.0

49 release files

4.2.8

37 release files

4.2.7

37 release files

4.2.6

37 release files

4.2.5

37 release files

4.2.4

37 release files

4.2.3

37 release files

4.2.2

37 release files

4.2.1

2 release files

4.2.0

37 release files

4.1.1

37 release files

4.1.0

37 release files

4.0.5

37 release files

3.1.2

37 release files

3.1.1

37 release files

3.1.0

37 release files

3.0.0

37 release files

2.30.1

2 release files

2.30.0

2 release files

2.22.0

2 release files

2.9.0

34 release files

2.8.0

2 release files

2.7.0

34 release files

2.6.0

34 release files

2.5.0

34 release files

2.4.0

34 release files

2.3.0

34 release files

2.2.0

34 release files

2.1.0

34 release files

1.87.0

2 release files

1.17.0

2 release files

1.16.0

2 release files

1.15.3

2 release files

1.15.2

2 release files

1.15.1

2 release files

1.15.0

2 release files

1.14.0

2 release files

1.13.0

2 release files

1.12.0

2 release files

1.11.0

2 release files

1.10.0

2 release files

1.9.0

2 release files

1.8.0

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page