Skip to main content

No project description provided

Project description

dbus-objects

checks tests codecov PyPI version

DBus objects implementation on top of the Python type system.

Integrations:

import random

from typing import List

import dbus_objects
import dbus_objects.integration.jeepney


class ExampleObject(dbus_objects.DBusObject):
    def __init__(self):
        super().__init__(default_interface_root='io.github.ffy00.dbus_objects.example')
        self._bets = []
        self._name = 'something'

    @dbus_objects.dbus_method()
    def ping(self) -> str:
        return 'Pong!'

    @dbus_objects.dbus_method()
    def print(self, msg: str) -> None:
        print(msg)

    @dbus_objects.dbus_method()
    def sum(self, a: int, b: int) -> int:
        return a + b

    @dbus_objects.dbus_method()
    def save_bet(self, number: int) -> None:
        self._bets.append(number)

    @dbus_objects.dbus_method()
    def get_bets(self) -> List[int]:
        return self._bets

    @dbus_objects.dbus_method()
    def lotery(self) -> int:
        winner = random.choice(self._bets)
        self._bets = []
        return winner

    @dbus_objects.dbus_property()
    def name(self) -> str:
        return self._name

    @name.setter
    def name(self, value: str):
        self._name = value
        self.name_updated(value)

    name_updated = dbus_objects.dbus_signal(new_name=str)


server = dbus_objects.integration.jeepney.BlockingDBusServer(
    bus='SESSION',
    name='io.github.ffy00.dbus-objects',
)
server.register_object('/io/github/ffy00/dbus_objects/example', ExampleObject())

server.listen()

This example will generate the following server topology:

paths
├── /
│   ├── org.freedesktop.DBus.Introspectable
│   │   └── Introspect
│   └── org.freedesktop.DBus.Peer
│       └── Ping
├── /io
│   ├── org.freedesktop.DBus.Introspectable
│   │   └── Introspect
│   └── org.freedesktop.DBus.Peer
│       └── Ping
├── /io/github
│   ├── org.freedesktop.DBus.Introspectable
│   │   └── Introspect
│   └── org.freedesktop.DBus.Peer
│       └── Ping
├── /io/github/ffy00
│   ├── org.freedesktop.DBus.Introspectable
│   │   └── Introspect
│   └── org.freedesktop.DBus.Peer
│       └── Ping
├── /io/github/ffy00/dbus_objects
│   ├── org.freedesktop.DBus.Introspectable
│   │   └── Introspect
│   └── org.freedesktop.DBus.Peer
│       └── Ping
└── /io/github/ffy00/dbus_objects/example
    ├── io.github.ffy00.dbus_objects.example.ExampleObject
    │   ├── GetBets
    │   ├── Lotery
    │   ├── Ping
    │   ├── Print
    │   ├── SaveBet
    │   └── Sum
    ├── org.freedesktop.DBus.Introspectable
    │   └── Introspect
    ├── org.freedesktop.DBus.Peer
    │   └── Ping
    └── org.freedesktop.DBus.Properties
        ├── Get
        ├── GetAll
        └── Set

And, for eg., the following DBus introspection XML for /io/github/ffy00/dbus_objects/example:

<!DOCTYPE node PUBLIC
"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd" >
<node>
	<interface name="io.github.ffy00.dbus_objects.example.ExampleObject">
		<method name="Ping">
			<arg direction="out" type="s" />
		</method>
		<method name="Print">
			<arg direction="in" type="s" name="msg" />
		</method>
		<method name="Sum">
			<arg direction="in" type="i" name="a" />
			<arg direction="in" type="i" name="b" />
			<arg direction="out" type="i" />
		</method>
		<method name="SaveBet">
			<arg direction="in" type="i" name="number" />
		</method>
		<method name="GetBets">
			<arg direction="out" type="ai" />
		</method>
		<method name="Lotery">
			<arg direction="out" type="i" />
		</method>
		<property name="Name" type="s" access="readwrite" />
		<signal name="NameUpdated">
			<arg type="s" name="new_name" />
		</signal>
	</interface>
	<interface name="org.freedesktop.DBus.Properties">
		<method name="Get">
			<arg direction="in" type="s" name="interface_name" />
			<arg direction="in" type="s" name="property_name" />
			<arg direction="out" type="v" />
		</method>
		<method name="Set">
			<arg direction="in" type="s" name="interface_name" />
			<arg direction="in" type="s" name="property_name" />
			<arg direction="in" type="v" name="value" />
		</method>
		<method name="GetAll">
			<arg direction="in" type="s" name="interface_name" />
			<arg direction="out" type="a{sv}" />
		</method>
	</interface>
	<interface name="org.freedesktop.DBus.Peer">
		<method name="Ping" />
	</interface>
	<interface name="org.freedesktop.DBus.Introspectable">
		<method name="Introspect">
			<arg direction="out" type="s" name="xml" />
		</method>
	</interface>
</node>

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbus-objects-0.0.2.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

dbus_objects-0.0.2-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file dbus-objects-0.0.2.tar.gz.

File metadata

  • Download URL: dbus-objects-0.0.2.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

File hashes

Hashes for dbus-objects-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a55359454d502eb3f0727039e3c1f3d09897b5c72ed5e407ddcca8535b1e070a
MD5 ee13e0fbcad0b8160dff1da531f771b3
BLAKE2b-256 61e71f717515c7046cac62743e7b64d13f3b64021dc2f53c870c28abbb239609

See more details on using hashes here.

File details

Details for the file dbus_objects-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: dbus_objects-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2

File hashes

Hashes for dbus_objects-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e0256652d1c5f1410c0d7eda0173a1bf96028b291ad68c9a7553fbe4b0cda661
MD5 2c754d99edff84f2d4781c4fa6fa24de
BLAKE2b-256 56fcfeec91c1639392746e7b7021b7dee85e93eb7dc2b8c18385b79c2882d38b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page