Package: adbus
D-Bus Binding for Python utilizing the Python’s asyncio module.LinksDocumentationProject PageIssuesDependenciesPython >= 3.7libsystemd >= 232 (don’t need systemd, just libsystemd which is a separate package)Cython >= 0.25.2Building / InstallingTo build in place for development python ./setup.py build_ext –inplaceThe html documents are stored in gh-pages branch, so that GitHub will
serve them as a GitHub Pages. To build them:
1. check out the gh-pages branch into ../python-adbus/html
2. cd into docs
3. sphinx-apidoc -o source/ ../adbus
4. make htmlUnit-TestsNOTE: Some test-cases require the busctl tool from systemd.To run a specific unit-test from the root directory (eg.):python -m unittest tests.test\_sdbus\_method.Test.test\_method\_single\_strTo run a specific unit-test module from the root directory (eg.):python -m unittest tests.test\_sdbus\_methodTo run all unit-tests from the root directory:toxServer ExamplesObject ExampleThis is an example of an object, which can be connected to a service.importadbusimporttypingclassExampleClass(adbus.server.Object):signal1:int=adbus.server.Signal()signal2:typing.List[int]=adbus.server.Signal()property1:str=adbus.server.Property('none',read_only=True,hidden=True)property2:typing.List[int]=adbus.server.Property(['rr','ff'],deprecated=True)def__init__(self,service):super().__init__(service,path='/xxx/yyy',interface='yyy.xxx')@adbus.server.method(name='test',hidden=True)deftest_method(self,r:int,gg:str)->int:returnr+10defdo_something(self):self.signal1.emit(14)Setting Multiple PropertiesIt’s possible to set multiple properties at the same time, this will defer the property
update signal, and send one signal for all property changes. It’s good practice to use
this when changing multiple properties, it will reduce traffic on the D-Bus.NOTE: Must be running in a loop.Client ExamplesAccessing Remote Interface via a ProxyIt’s possible to map a remote interface to a local instantiated class using a Proxy.If the even loop isn’t running no signals will caught, and properties will notcache (i.e. will read on every access instead of tracking the property changes signals)The proxy opbject must be saved for as long as you want to activily receive signals.If the proxy object is garbage collected it will no longer receive signals and it won’t forward them to a watcher.service=adbus.Service(bus='session')proxy=adbus.client.Proxy(service,'com.example.xxx','/com/example/Service1',interface='com.example.service.unit')asyncdefproxy_examples():awaitproxy.update()# initialize the proxy# == Access Propertiesawaitproxy.remote_propertyX.set(45)print(awaitproxy.remote_propertyY.get())# == orawaitproxy.remote_propertyX(45)print(awaitproxy.remote_propertyY())# == Access Methodsasyncio.ensure_future(proxy.remote_method_foo("some info"))# don't wait for resultx=awaitproxy.remote_method_bar(100,12,-45)# wait for result# == Add a Coroutine to a Signalasyncdeflocal_method(signal_data:int):print(signal_data)proxy.remote_signal.add(local_method)# == orproxy.remote_signal(local_method)# == Remove a Coroutine to a Signalproxy.remote_signal.remove(local_method)# == or (if already added)proxy.remote_signal(local_method)# == Access a method using a different interface nameproxy['com.example.service.serve'].remote_method_800(b"data")# == Create a new proxy from a node in the proxyproxy_new=awaitproxy('Test')# == Loop through all nodes in a proxysum_cnt=0asyncfornodeinproxy:try:sum_cnt+=awaitnode.countexceptAttributeError:pass# == set multiple properties in one message (if linked to an adbus based server)asyncwithproxyasp:p.property1="some data"p.property2=[1,2,3,4,5]loop=asyncio.get_event_loop()loop.run_until_complete(proxy_examples())loop.close()Style GuideFor a consistent style all code is updated using yapf with the following options:yapf –recursive –verbose –in-place –no-local-style–style="{dedent_closing_brackets: True, continuation_indent_width: 8, split_complex_comprehension: True}" <filename>