All Projects → rhinstaller → dasbus

rhinstaller / dasbus

Licence: LGPL-2.1 license
DBus library in Python 3

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to dasbus

xpub
POSIX Shell script to get user's display environment variables of any TTY from anywhere.
Stars: ✭ 36 (-30.77%)
Mutual labels:  dbus
RabbitMQTools
PowerShell module containing cmdlets to manage RabbitMQ.
Stars: ✭ 27 (-48.08%)
Mutual labels:  message-bus
grails-rabbitmq-native
A Grails plugin that provides convenient RabbitMQ functionality using the native Java library for RabbitMQ.
Stars: ✭ 27 (-48.08%)
Mutual labels:  message-bus
InitWare
The InitWare Suite of Middleware allows you to manage services and system resources as logical entities called units. Its main component is a service management ("init") system.
Stars: ✭ 164 (+215.38%)
Mutual labels:  dbus
scalanative-gtk
scala-native bindings for Gtk+, GLib, ...
Stars: ✭ 26 (-50%)
Mutual labels:  glib
hub
📨 A fast Message/Event Hub using publish/subscribe pattern with support for topics like* rabbitMQ exchanges for Go applications
Stars: ✭ 125 (+140.38%)
Mutual labels:  message-bus
jsonargparse
Implement minimal boilerplate CLIs derived from type hints and parse from command line, config files and environment variables
Stars: ✭ 168 (+223.08%)
Mutual labels:  type-hints
mpris-rs
Idiomatic MPRIS D-Bus interface library for Rust
Stars: ✭ 37 (-28.85%)
Mutual labels:  dbus
flake8-mypy
A plugin for flake8 integrating Mypy.
Stars: ✭ 103 (+98.08%)
Mutual labels:  type-hints
go-nats-examples
Single repository for go-nats example code. This includes all documentation examples and any common message pattern examples.
Stars: ✭ 99 (+90.38%)
Mutual labels:  message-bus
dbus-java
Improved version of java DBus library provided by freedesktop.org (https://dbus.freedesktop.org/doc/dbus-java/)
Stars: ✭ 124 (+138.46%)
Mutual labels:  dbus
gtk-sni-tray
A StatusNotifierHost widget written using the gtk+3 bindings for haskell provided by gi-gtk.
Stars: ✭ 24 (-53.85%)
Mutual labels:  dbus
NetworkManager-WiFi-WebUI
Web interface (python2/twisted) for NetworkManager daemon to manage WiFi connections
Stars: ✭ 42 (-19.23%)
Mutual labels:  dbus
gtk-rs-core
Rust bindings for GNOME libraries
Stars: ✭ 179 (+244.23%)
Mutual labels:  glib
bluez-dbus
bluetooth library for linux OSes using DBus and bluez (http://www.bluez.org/).
Stars: ✭ 49 (-5.77%)
Mutual labels:  dbus
gobject-example-rs
Example for exporting a GObject/C API from Rust
Stars: ✭ 31 (-40.38%)
Mutual labels:  glib
awesome-power widget
A Power widget for the Awesome Window Manager
Stars: ✭ 25 (-51.92%)
Mutual labels:  dbus
OmniPause
Control all of your media players with a single command
Stars: ✭ 33 (-36.54%)
Mutual labels:  dbus
yet-another-spotify-lyrics
Command Line Spotify Lyrics with Album Cover
Stars: ✭ 78 (+50%)
Mutual labels:  dbus
gdbus-codegen-glibmm
Code generator for C++ D-Bus stubs and proxies using Giomm/Glibmm
Stars: ✭ 21 (-59.62%)
Mutual labels:  dbus

dasbus

This DBus library is written in Python 3, based on GLib and inspired by pydbus. Find out more in the documentation.

The code used to be part of the Anaconda Installer project. It was based on the pydbus library, but we replaced it with our own solution because its upstream development stalled. The dasbus library is a result of this effort.

Build Status Documentation Status codecov

Requirements

  • Python 3.6+
  • PyGObject 3

You can install PyGObject provided by your system or use PyPI. The system package is usually called python3-gi, python3-gobject or pygobject3. See the instructions for your platform (only for PyGObject, you don't need cairo or GTK).

The library is known to work with Python 3.8, PyGObject 3.34 and GLib 2.63, but these are not the required minimal versions.

Installation

Install the package from PyPI. Follow the instructions above to install the required dependencies.

pip3 install dasbus

Or install the RPM package on Fedora 31+.

sudo dnf install python3-dasbus

Or install the DEB package on Ubuntu 22.04+ and Debian 11+.

sudo apt install python3-dasbus

Examples

Show the current hostname.

from dasbus.connection import SystemMessageBus
bus = SystemMessageBus()

proxy = bus.get_proxy(
    "org.freedesktop.hostname1",
    "/org/freedesktop/hostname1"
)

print(proxy.Hostname)

Send a notification to the notification server.

from dasbus.connection import SessionMessageBus
bus = SessionMessageBus()

proxy = bus.get_proxy(
    "org.freedesktop.Notifications",
    "/org/freedesktop/Notifications"
)

id = proxy.Notify(
    "", 0, "face-smile", "Hello World!",
    "This notification can be ignored.",
    [], {}, 0
)

print("The notification {} was sent.".format(id))

Handle a closed notification.

from dasbus.loop import EventLoop
loop = EventLoop()

from dasbus.connection import SessionMessageBus
bus = SessionMessageBus()

proxy = bus.get_proxy(
    "org.freedesktop.Notifications",
    "/org/freedesktop/Notifications"
)

def callback(id, reason):
    print("The notification {} was closed.".format(id))

proxy.NotificationClosed.connect(callback)
loop.run()

Asynchronously fetch a list of network devices.

from dasbus.loop import EventLoop
loop = EventLoop()

from dasbus.connection import SystemMessageBus
bus = SystemMessageBus()

proxy = bus.get_proxy(
    "org.freedesktop.NetworkManager",
    "/org/freedesktop/NetworkManager"
)

def callback(call):
    print(call())

proxy.GetDevices(callback=callback)
loop.run()

Inhibit the system suspend and hibernation.

import os
from dasbus.connection import SystemMessageBus
from dasbus.unix import GLibClientUnix
bus = SystemMessageBus()

proxy = bus.get_proxy(
    "org.freedesktop.login1",
    "/org/freedesktop/login1",
    client=GLibClientUnix
)

fd = proxy.Inhibit(
    "sleep", "my-example", "Running an example", "block"
)

proxy.ListInhibitors()
os.close(fd)

Define the org.example.HelloWorld service.

class HelloWorld(object):
    __dbus_xml__ = """
    <node>
        <interface name="org.example.HelloWorld">
            <method name="Hello">
                <arg direction="in" name="name" type="s" />
                <arg direction="out" name="return" type="s" />
            </method>
        </interface>
    </node>
    """

    def Hello(self, name):
        return "Hello {}!".format(name)

Define the org.example.HelloWorld service with an automatically generated XML specification.

from dasbus.server.interface import dbus_interface
from dasbus.typing import Str

@dbus_interface("org.example.HelloWorld")
class HelloWorld(object):

    def Hello(self, name: Str) -> Str:
        return "Hello {}!".format(name)

print(HelloWorld.__dbus_xml__)

Publish the org.example.HelloWorld service on the session message bus.

from dasbus.connection import SessionMessageBus
bus = SessionMessageBus()
bus.publish_object("/org/example/HelloWorld", HelloWorld())
bus.register_service("org.example.HelloWorld")

from dasbus.loop import EventLoop
loop = EventLoop()
loop.run()

See more examples in the documentation.

Inspiration

Look at the complete examples or DBus services of the Anaconda Installer for more inspiration.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].