Modern Python D-Bus library. Based on sd-bus from libsystemd.
Project description
Modern Python library for D-Bus
Features:
- Asyncio and blocking calls.
- Type hints. (
mypy --strict
compatible) - No Python 2 legacy.
- Based on fast sd-bus from systemd.
- Unified client/server interface classes. Write interface once!
- Dbus methods can have keyword and default arguments.
See the documentation for tutorial and API reference.
List of implemented interfaces
- D-Bus (built-in)
- Freedesktop Notifications
- Network Manager
More incoming. (NetworkManager, secrets... )
Requirements
Binary package from PyPI
- Python 3.8 or higher. (3.7 might work but is not supported)
x86_64
oraarch64
architecture.- glibc 2.17 or higher. (released in 2014)
Starting with version 0.8rc2
the libsystemd is statically
linked and is not required.
Pass --only-binary ':all:'
to pip to ensure that it
installs binary package.
i686
, ppc64le
and s390x
can be supported if there is a
demand. Please open an issue if you are interested in those
platforms.
Source package or compiling from source
- Python 3.8 or higher.
- Python headers. (
python3-dev
package on ubuntu) - GCC.
- libsystemd. (comes with systemd)
- libsystemd headers. (
libsystemd-dev
package on ubuntu) - Python setuptools.
Systemd version should be higher than 246.
Optional dependencies
- Jinja2 for code generator.
- Sphinx for autodoc.
Installation
PyPI
URL: https://pypi.org/project/sdbus/
pip install --only-binary ':all:' sdbus
AUR
URL: https://aur.archlinux.org/packages/python-sdbus-git/
Example code
Interface example_interface.py
file:
from sdbus import (DbusInterfaceCommonAsync, dbus_method_async,
dbus_property_async, dbus_signal_async)
# This is file only contains interface definition for easy import
# in server and client files
class ExampleInterface(
DbusInterfaceCommonAsync,
interface_name='org.example.interface'
):
@dbus_method_async(
input_signature='s',
result_signature='s',
)
async def upper(self, string: str) -> str:
return string.upper()
@dbus_property_async(
property_signature='s',
)
def hello_world(self) -> str:
return 'Hello, World!'
@dbus_signal_async(
signal_signature='i'
)
def clock(self) -> int:
raise NotImplementedError
Server example_server.py
file:
from asyncio import get_event_loop, sleep
from random import randint
from time import time
from example_interface import ExampleInterface
from sdbus import request_default_bus_name_async
loop = get_event_loop()
export_object = ExampleInterface()
async def clock() -> None:
"""
This coroutine will sleep a random time and emit
a signal with current clock
"""
while True:
await sleep(randint(2, 7)) # Sleep a random time
current_time = int(time()) # The interface we defined uses integers
export_object.clock.emit(current_time)
async def startup() -> None:
"""Perform async startup actions"""
# Acquire a known name on the bus
# Client will use that name to connect to this server
await request_default_bus_name_async('org.example.test')
# Export the object to dbus
export_object.export_to_dbus('/')
loop.run_until_complete(startup())
loop.create_task(clock())
loop.run_forever()
Client example_client.py
file:
from asyncio import get_event_loop
from example_interface import ExampleInterface
# Create a new binded object
example_object = ExampleInterface.new_connect('org.example.test', '/')
async def print_clock() -> None:
# Use async for loop to print clock signals we receive
async for x in example_object.clock:
print('Got clock: ', x)
async def call_upper() -> None:
s = 'test string'
s_after = await example_object.upper(s)
print('Initial string: ', s)
print('After call: ', s_after)
async def get_hello_world() -> None:
print('Remote property: ', await example_object.hello_world)
loop = get_event_loop()
loop.create_task(call_upper())
loop.create_task(print_clock())
loop.create_task(get_hello_world())
loop.run_forever()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for sdbus-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ae7f4866a31d3eab59fd0a93693ba9dd22735a26eac993cd7dca32660b52118 |
|
MD5 | 1e2ab2a7e48c5c4d3ad4cb5c7860fc14 |
|
BLAKE2b-256 | ff1d8ee894bba818fbe1ce28a4a39569307d540ef0d503d5ab956dcddb867816 |
Hashes for sdbus-0.8.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9b3da57d54be15cc2562d9e09215474f9fd77abbd09a04149f0cd79b7b0f281 |
|
MD5 | 5034defeff4ea4a8f9a98316817f0a48 |
|
BLAKE2b-256 | cc1ef23e076913dddf92e7548eab8167aaaa2bd0f058ff419e873cecc44ec5b1 |
Hashes for sdbus-0.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cffefa0d17d0d84c19fdb08a65a873a5216ce2c9dba63a4727419912266e4703 |
|
MD5 | 283f94071e235f7af513df724e1aad9c |
|
BLAKE2b-256 | a5cbcdcadac3280355051ad984a9e74ca9c5ffd57eb2c02c07df652aaf81cea2 |
Hashes for sdbus-0.8.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2862222606fac3bce8822c985a68bb4063a6d7c4ed0b3c80647bd6dc9dc2afe |
|
MD5 | 3b78dde32c7e18ef0410c434e7370c64 |
|
BLAKE2b-256 | d2daa166fa30d310ea978492a338cd0bbd7f710e7067ab72c698ab320e8ac921 |
Hashes for sdbus-0.8.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24725767aea4a212e51b7e3271e2b7b0058645c0ad03578331bc98c7cec2a6ad |
|
MD5 | bbec124e0fa598a50251128184c75952 |
|
BLAKE2b-256 | 5f89c5701f70d3738f0ffd0bc3c9b63a8b7221c52303dd55b82d26e1fa7b5038 |
Hashes for sdbus-0.8.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e5c624e538efbc0d6866c5f2f274630a7c987946e2b15ae6fc2485a2eb5d8d0 |
|
MD5 | bab3c58141a85e3e4691fc1bbcfcdb77 |
|
BLAKE2b-256 | eeb9746ea3c5fdf7a5cf842c1e524b209cac3f823eafa5991959f1e5d63d2835 |