dasbus


Namedasbus JSON
Version 1.7 PyPI version JSON
download
home_pagehttps://github.com/rhinstaller/dasbus
SummaryDBus library in Python 3
upload_time2022-11-07 13:20:08
maintainer
docs_urlNone
authorVendula Poncova
requires_python>=3.6
license
keywords dbus glib library
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # dasbus
This DBus library is written in Python 3, based on GLib and inspired by pydbus. Find out more in
the [documentation](https://dasbus.readthedocs.io/en/latest/).

The code used to be part of the [Anaconda Installer](https://github.com/rhinstaller/anaconda)
project. It was based on the [pydbus](https://github.com/LEW21/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](https://travis-ci.com/rhinstaller/dasbus.svg?branch=master)](https://travis-ci.com/rhinstaller/dasbus)
[![Documentation Status](https://readthedocs.org/projects/dasbus/badge/?version=latest)](https://dasbus.readthedocs.io/en/latest/?badge=latest)
[![codecov](https://codecov.io/gh/rhinstaller/dasbus/branch/master/graph/badge.svg)](https://codecov.io/gh/rhinstaller/dasbus)

## Requirements

* Python 3.6+
* PyGObject 3

You can install [PyGObject](https://pygobject.readthedocs.io) provided by your operating system
or use PyPI. The system package is usually called `python3-gi`, `python3-gobject` or `pygobject3`.
See the [instructions](https://pygobject.readthedocs.io/en/latest/getting_started.html) 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](https://pypi.org/project/dasbus/) or install the package
provided by your operating system if available.

### Install from PyPI

Follow the instructions above to install the requirements before you install `dasbus` with `pip`.
The required dependencies has to be installed manually in this case.

```
pip3 install dasbus
```

### Install the system package

Follow the instructions for your operating system to install the `python-dasbus` package.
The required dependencies should be installed automatically by the system package manager.

* [Arch Linux](https://dasbus.readthedocs.io/en/latest/#install-on-arch-linux)
* [Debian / Ubuntu](https://dasbus.readthedocs.io/en/latest/#install-on-debian-ubuntu)
* [Fedora / CentOS / RHEL](https://dasbus.readthedocs.io/en/latest/#install-on-fedora-centos-rhel)
* [openSUSE](https://dasbus.readthedocs.io/en/latest/#install-on-opensuse)

## Examples

Show the current hostname.

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

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

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

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

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

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

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

```python
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](https://dasbus.readthedocs.io/en/latest/examples.html).

## Inspiration

Look at the [complete examples](https://github.com/rhinstaller/dasbus/tree/master/examples) or
[DBus services](https://github.com/rhinstaller/anaconda/tree/master/pyanaconda/modules) of
the Anaconda Installer for more inspiration.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rhinstaller/dasbus",
    "name": "dasbus",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "dbus glib library",
    "author": "Vendula Poncova",
    "author_email": "vponcova@redhat.com",
    "download_url": "https://files.pythonhosted.org/packages/37/79/9c5984d723ffbe2e839ee649690f3e1fa6544ab6a17a5150e5ac14a47072/dasbus-1.7.tar.gz",
    "platform": null,
    "description": "# dasbus\nThis DBus library is written in Python 3, based on GLib and inspired by pydbus. Find out more in\nthe [documentation](https://dasbus.readthedocs.io/en/latest/).\n\nThe code used to be part of the [Anaconda Installer](https://github.com/rhinstaller/anaconda)\nproject. It was based on the [pydbus](https://github.com/LEW21/pydbus) library, but we replaced\nit with our own solution because its upstream development stalled. The dasbus library is\na result of this effort.\n\n[![Build Status](https://travis-ci.com/rhinstaller/dasbus.svg?branch=master)](https://travis-ci.com/rhinstaller/dasbus)\n[![Documentation Status](https://readthedocs.org/projects/dasbus/badge/?version=latest)](https://dasbus.readthedocs.io/en/latest/?badge=latest)\n[![codecov](https://codecov.io/gh/rhinstaller/dasbus/branch/master/graph/badge.svg)](https://codecov.io/gh/rhinstaller/dasbus)\n\n## Requirements\n\n* Python 3.6+\n* PyGObject 3\n\nYou can install [PyGObject](https://pygobject.readthedocs.io) provided by your operating system\nor use PyPI. The system package is usually called `python3-gi`, `python3-gobject` or `pygobject3`.\nSee the [instructions](https://pygobject.readthedocs.io/en/latest/getting_started.html) for\nyour platform (only for PyGObject, you don't need cairo or GTK).\n\nThe library is known to work with Python 3.8, PyGObject 3.34 and GLib 2.63, but these are not the\nrequired minimal versions.\n\n## Installation\n\nInstall the package from [PyPI](https://pypi.org/project/dasbus/) or install the package\nprovided by your operating system if available.\n\n### Install from PyPI\n\nFollow the instructions above to install the requirements before you install `dasbus` with `pip`.\nThe required dependencies has to be installed manually in this case.\n\n```\npip3 install dasbus\n```\n\n### Install the system package\n\nFollow the instructions for your operating system to install the `python-dasbus` package.\nThe required dependencies should be installed automatically by the system package manager.\n\n* [Arch Linux](https://dasbus.readthedocs.io/en/latest/#install-on-arch-linux)\n* [Debian / Ubuntu](https://dasbus.readthedocs.io/en/latest/#install-on-debian-ubuntu)\n* [Fedora / CentOS / RHEL](https://dasbus.readthedocs.io/en/latest/#install-on-fedora-centos-rhel)\n* [openSUSE](https://dasbus.readthedocs.io/en/latest/#install-on-opensuse)\n\n## Examples\n\nShow the current hostname.\n\n```python\nfrom dasbus.connection import SystemMessageBus\nbus = SystemMessageBus()\n\nproxy = bus.get_proxy(\n    \"org.freedesktop.hostname1\",\n    \"/org/freedesktop/hostname1\"\n)\n\nprint(proxy.Hostname)\n```\n\nSend a notification to the notification server.\n\n```python\nfrom dasbus.connection import SessionMessageBus\nbus = SessionMessageBus()\n\nproxy = bus.get_proxy(\n    \"org.freedesktop.Notifications\",\n    \"/org/freedesktop/Notifications\"\n)\n\nid = proxy.Notify(\n    \"\", 0, \"face-smile\", \"Hello World!\",\n    \"This notification can be ignored.\",\n    [], {}, 0\n)\n\nprint(\"The notification {} was sent.\".format(id))\n```\n\nHandle a closed notification.\n\n```python\nfrom dasbus.loop import EventLoop\nloop = EventLoop()\n\nfrom dasbus.connection import SessionMessageBus\nbus = SessionMessageBus()\n\nproxy = bus.get_proxy(\n    \"org.freedesktop.Notifications\",\n    \"/org/freedesktop/Notifications\"\n)\n\ndef callback(id, reason):\n    print(\"The notification {} was closed.\".format(id))\n\nproxy.NotificationClosed.connect(callback)\nloop.run()\n```\n\nAsynchronously fetch a list of network devices.\n\n```python\nfrom dasbus.loop import EventLoop\nloop = EventLoop()\n\nfrom dasbus.connection import SystemMessageBus\nbus = SystemMessageBus()\n\nproxy = bus.get_proxy(\n    \"org.freedesktop.NetworkManager\",\n    \"/org/freedesktop/NetworkManager\"\n)\n\ndef callback(call):\n    print(call())\n\nproxy.GetDevices(callback=callback)\nloop.run()\n```\n\nInhibit the system suspend and hibernation.\n\n```python\nimport os\nfrom dasbus.connection import SystemMessageBus\nfrom dasbus.unix import GLibClientUnix\nbus = SystemMessageBus()\n\nproxy = bus.get_proxy(\n    \"org.freedesktop.login1\",\n    \"/org/freedesktop/login1\",\n    client=GLibClientUnix\n)\n\nfd = proxy.Inhibit(\n    \"sleep\", \"my-example\", \"Running an example\", \"block\"\n)\n\nproxy.ListInhibitors()\nos.close(fd)\n```\n\nDefine the org.example.HelloWorld service.\n\n```python\nclass HelloWorld(object):\n    __dbus_xml__ = \"\"\"\n    <node>\n        <interface name=\"org.example.HelloWorld\">\n            <method name=\"Hello\">\n                <arg direction=\"in\" name=\"name\" type=\"s\" />\n                <arg direction=\"out\" name=\"return\" type=\"s\" />\n            </method>\n        </interface>\n    </node>\n    \"\"\"\n\n    def Hello(self, name):\n        return \"Hello {}!\".format(name)\n```\n\nDefine the org.example.HelloWorld service with an automatically generated XML specification.\n\n```python\nfrom dasbus.server.interface import dbus_interface\nfrom dasbus.typing import Str\n\n@dbus_interface(\"org.example.HelloWorld\")\nclass HelloWorld(object):\n\n    def Hello(self, name: Str) -> Str:\n        return \"Hello {}!\".format(name)\n\nprint(HelloWorld.__dbus_xml__)\n```\n\nPublish the org.example.HelloWorld service on the session message bus.\n\n```python\nfrom dasbus.connection import SessionMessageBus\nbus = SessionMessageBus()\nbus.publish_object(\"/org/example/HelloWorld\", HelloWorld())\nbus.register_service(\"org.example.HelloWorld\")\n\nfrom dasbus.loop import EventLoop\nloop = EventLoop()\nloop.run()\n```\n\nSee more examples in the [documentation](https://dasbus.readthedocs.io/en/latest/examples.html).\n\n## Inspiration\n\nLook at the [complete examples](https://github.com/rhinstaller/dasbus/tree/master/examples) or\n[DBus services](https://github.com/rhinstaller/anaconda/tree/master/pyanaconda/modules) of\nthe Anaconda Installer for more inspiration.\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "DBus library in Python 3",
    "version": "1.7",
    "project_urls": {
        "Homepage": "https://github.com/rhinstaller/dasbus"
    },
    "split_keywords": [
        "dbus",
        "glib",
        "library"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e1b44d55b9359bc34d56b29b943b378331dd8aaea6db6d0543e5d97fed4b1af7",
                "md5": "7b86c4bfa1ff8ca252d04122468af565",
                "sha256": "0a9433e9e72c2c865fa2d5ef824ac4ef49b540cf57f6396e515c2f314e5c14cd"
            },
            "downloads": -1,
            "filename": "dasbus-1.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7b86c4bfa1ff8ca252d04122468af565",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 63118,
            "upload_time": "2022-11-07T13:20:05",
            "upload_time_iso_8601": "2022-11-07T13:20:05.071972Z",
            "url": "https://files.pythonhosted.org/packages/e1/b4/4d55b9359bc34d56b29b943b378331dd8aaea6db6d0543e5d97fed4b1af7/dasbus-1.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "37799c5984d723ffbe2e839ee649690f3e1fa6544ab6a17a5150e5ac14a47072",
                "md5": "36cc01e43cada6bd258f1732f7276e7c",
                "sha256": "a8850d841adfe8ee5f7bb9f82cf449ab9b4950dc0633897071718e0d0036b6f6"
            },
            "downloads": -1,
            "filename": "dasbus-1.7.tar.gz",
            "has_sig": false,
            "md5_digest": "36cc01e43cada6bd258f1732f7276e7c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 78603,
            "upload_time": "2022-11-07T13:20:08",
            "upload_time_iso_8601": "2022-11-07T13:20:08.536372Z",
            "url": "https://files.pythonhosted.org/packages/37/79/9c5984d723ffbe2e839ee649690f3e1fa6544ab6a17a5150e5ac14a47072/dasbus-1.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-11-07 13:20:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rhinstaller",
    "github_project": "dasbus",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "dasbus"
}
        
Elapsed time: 0.39374s