Package: dbus-objects
dbus-objectsDBus objects implementation on top of the Python type system.Integrations:jeepney(blocking IO andtriobackends)importrandomfromtypingimportListimportdbus_objectsimportdbus_objects.integration.jeepneyclassExampleObject(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()defping(self)->str:return'Pong!'@dbus_objects.dbus_method()defprint(self,msg:str)->None:print(msg)@dbus_objects.dbus_method()defsum(self,a:int,b:int)->int:returna+b@dbus_objects.dbus_method()defsave_bet(self,number:int)->None:self._bets.append(number)@dbus_objects.dbus_method()defget_bets(self)->List[int]:returnself._bets@dbus_objects.dbus_method()deflotery(self)->int:winner=random.choice(self._bets)self._bets=[]returnwinner@dbus_objects.dbus_property()defname(self)->str:returnself._name@name.setterdefname(self,value:str):self._name=valueself.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
        └── SetAnd, 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><interfacename="io.github.ffy00.dbus_objects.example.ExampleObject"><methodname="Ping"><argdirection="out"type="s"/></method><methodname="Print"><argdirection="in"type="s"name="msg"/></method><methodname="Sum"><argdirection="in"type="i"name="a"/><argdirection="in"type="i"name="b"/><argdirection="out"type="i"/></method><methodname="SaveBet"><argdirection="in"type="i"name="number"/></method><methodname="GetBets"><argdirection="out"type="ai"/></method><methodname="Lotery"><argdirection="out"type="i"/></method><propertyname="Name"type="s"access="readwrite"/><signalname="NameUpdated"><argtype="s"name="new_name"/></signal></interface><interfacename="org.freedesktop.DBus.Properties"><methodname="Get"><argdirection="in"type="s"name="interface_name"/><argdirection="in"type="s"name="property_name"/><argdirection="out"type="v"/></method><methodname="Set"><argdirection="in"type="s"name="interface_name"/><argdirection="in"type="s"name="property_name"/><argdirection="in"type="v"name="value"/></method><methodname="GetAll"><argdirection="in"type="s"name="interface_name"/><argdirection="out"type="a{sv}"/></method></interface><interfacename="org.freedesktop.DBus.Peer"><methodname="Ping"/></interface><interfacename="org.freedesktop.DBus.Introspectable"><methodname="Introspect"><argdirection="out"type="s"name="xml"/></method></interface></node>LicenseMIT