[![CodeQL](https://github.com/python-sdbus/python-sdbus/actions/workflows/codeql.yml/badge.svg)](https://github.com/python-sdbus/python-sdbus/actions/workflows/codeql.yml)
[![Documentation Status](https://readthedocs.org/projects/python-sdbus/badge/?version=latest)](https://python-sdbus.readthedocs.io/en/latest/?badge=latest)
# Modern Python library for D-Bus
<a href="https://repology.org/project/python:sdbus/versions">
<img src="https://repology.org/badge/vertical-allrepos/python:sdbus.svg" alt="Packaging status" align="right">
</a>
Features:
* Asyncio and blocking calls.
* Type hints. (`mypy --strict` compatible)
* No Python 2 legacy.
* Based on fast sd-bus from systemd. (also supports elogind)
* Unified client/server interface classes. Write interface once!
* D-Bus methods can have keyword and default arguments.
See the
[documentation](https://python-sdbus.readthedocs.io/en/latest/index.html)
for tutorial and API reference.
### List of implemented interfaces
* D-Bus (built-in)
* [Freedesktop Notifications](https://github.com/python-sdbus/python-sdbus-notifications)
* [Network Manager](https://github.com/python-sdbus/python-sdbus-networkmanager)
* [Freedesktop Secrets](https://github.com/python-sdbus/python-sdbus-secrets)
More incoming. (systemd, Bluez, screen saver... )
### Community interfaces
* [systemd](https://github.com/bernhardkaindl/python-sdbus-systemd) (by [@bernhardkaindl](https://github.com/bernhardkaindl))
* [modemmanager](https://github.com/zhanglongqi/python-sdbus-modemmanager) (by [@zhanglongqi](https://github.com/zhanglongqi))
## Stability
Python-sdbus is under development and its API is not stable. Generally
anything documented in the official documentation is considered
stable but might be deprecated. Using deprecated feature will
raise a warning and the feature will be eventually removed.
See the [deprecations list](DEPRECATIONS.md).
If there is a feature that is not documented but you would like to use
please open a new issue.
## Requirements
### Binary package from PyPI
* Python 3.8 or higher. (3.7 might work but is not supported)
* `x86_64` or `aarch64` architecture.
* glibc 2.17 or higher. (released in 2014)
* pip 19.3 or higher.
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 or libelogind
* libsystemd headers. (`libsystemd-dev` package on ubuntu)
* Python setuptools.
* pkg-config
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:
```python
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:
```python
from asyncio import new_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 = new_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
# Clients will use that name to address this server
await request_default_bus_name_async('org.example.test')
# Export the object to D-Bus
export_object.export_to_dbus('/')
loop.run_until_complete(startup())
task_clock = loop.create_task(clock())
loop.run_forever()
```
Client `example_client.py` file:
```python
from asyncio import new_event_loop
from example_interface import ExampleInterface
# Create a new proxied object
example_object = ExampleInterface.new_proxy('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 = new_event_loop()
# Always bind your tasks to a variable
task_upper = loop.create_task(call_upper())
task_clock = loop.create_task(print_clock())
task_hello_world = loop.create_task(get_hello_world())
loop.run_forever()
```
## License
Python-sdbus is licensed under [LGPL-2.1-or-later](https://spdx.org/licenses/LGPL-2.1-or-later.html).
The LGPL license is an extension of GPL license therefore both licenses' texts are required.
Raw data
{
"_id": null,
"home_page": "https://github.com/igo95862/python-sdbus",
"name": "sdbus",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "dbus ipc linux freedesktop",
"author": "igo95862",
"author_email": "igo95862@yandex.ru",
"download_url": "https://files.pythonhosted.org/packages/4f/c7/8740ff78e9ffdbb9a28e7722e145795015c62ea7ce812242f5968073511c/sdbus-0.13.0.tar.gz",
"platform": null,
"description": "[![CodeQL](https://github.com/python-sdbus/python-sdbus/actions/workflows/codeql.yml/badge.svg)](https://github.com/python-sdbus/python-sdbus/actions/workflows/codeql.yml)\n[![Documentation Status](https://readthedocs.org/projects/python-sdbus/badge/?version=latest)](https://python-sdbus.readthedocs.io/en/latest/?badge=latest)\n\n# Modern Python library for D-Bus\n\n<a href=\"https://repology.org/project/python:sdbus/versions\">\n <img src=\"https://repology.org/badge/vertical-allrepos/python:sdbus.svg\" alt=\"Packaging status\" align=\"right\">\n</a>\n\nFeatures:\n\n* Asyncio and blocking calls.\n* Type hints. (`mypy --strict` compatible)\n* No Python 2 legacy.\n* Based on fast sd-bus from systemd. (also supports elogind)\n* Unified client/server interface classes. Write interface once!\n* D-Bus methods can have keyword and default arguments.\n\nSee the\n[documentation](https://python-sdbus.readthedocs.io/en/latest/index.html)\nfor tutorial and API reference.\n\n### List of implemented interfaces\n\n* D-Bus (built-in)\n* [Freedesktop Notifications](https://github.com/python-sdbus/python-sdbus-notifications)\n* [Network Manager](https://github.com/python-sdbus/python-sdbus-networkmanager)\n* [Freedesktop Secrets](https://github.com/python-sdbus/python-sdbus-secrets)\n\nMore incoming. (systemd, Bluez, screen saver... )\n\n### Community interfaces\n\n* [systemd](https://github.com/bernhardkaindl/python-sdbus-systemd) (by [@bernhardkaindl](https://github.com/bernhardkaindl))\n* [modemmanager](https://github.com/zhanglongqi/python-sdbus-modemmanager) (by [@zhanglongqi](https://github.com/zhanglongqi))\n\n## Stability\n\nPython-sdbus is under development and its API is not stable. Generally\nanything documented in the official documentation is considered\nstable but might be deprecated. Using deprecated feature will\nraise a warning and the feature will be eventually removed.\n\nSee the [deprecations list](DEPRECATIONS.md).\n\nIf there is a feature that is not documented but you would like to use\nplease open a new issue.\n\n## Requirements\n\n### Binary package from PyPI\n\n* Python 3.8 or higher. (3.7 might work but is not supported)\n* `x86_64` or `aarch64` architecture.\n* glibc 2.17 or higher. (released in 2014)\n* pip 19.3 or higher.\n\nStarting with version `0.8rc2` the libsystemd is statically\nlinked and is not required.\n\nPass `--only-binary ':all:'` to pip to ensure that it\ninstalls binary package.\n\n`i686`, `ppc64le` and `s390x` can be supported if there is a\ndemand. Please open an issue if you are interested in those\nplatforms.\n\n### Source package or compiling from source\n\n* Python 3.8 or higher.\n* Python headers. (`python3-dev` package on ubuntu)\n* GCC.\n* libsystemd or libelogind\n* libsystemd headers. (`libsystemd-dev` package on ubuntu)\n* Python setuptools.\n* pkg-config\n\nSystemd version should be higher than 246.\n\n### Optional dependencies\n\n* Jinja2 for code generator.\n* Sphinx for autodoc.\n\n## Installation\n\n### PyPI\n\nURL: https://pypi.org/project/sdbus/\n\n`pip install --only-binary ':all:' sdbus`\n\n### AUR\n\nURL: https://aur.archlinux.org/packages/python-sdbus-git/\n\n## Example code\n\nInterface `example_interface.py` file:\n\n```python\nfrom sdbus import (DbusInterfaceCommonAsync, dbus_method_async,\n dbus_property_async, dbus_signal_async)\n\n# This is file only contains interface definition for easy import\n# in server and client files\n\nclass ExampleInterface(\n DbusInterfaceCommonAsync,\n interface_name='org.example.interface'\n):\n @dbus_method_async(\n input_signature='s',\n result_signature='s',\n )\n async def upper(self, string: str) -> str:\n return string.upper()\n\n @dbus_property_async(\n property_signature='s',\n )\n def hello_world(self) -> str:\n return 'Hello, World!'\n\n @dbus_signal_async(\n signal_signature='i'\n )\n def clock(self) -> int:\n raise NotImplementedError\n```\n\nServer `example_server.py` file:\n\n```python\nfrom asyncio import new_event_loop, sleep\nfrom random import randint\nfrom time import time\n\nfrom example_interface import ExampleInterface\n\nfrom sdbus import request_default_bus_name_async\n\nloop = new_event_loop()\n\nexport_object = ExampleInterface()\n\n\nasync def clock() -> None:\n \"\"\"\n This coroutine will sleep a random time and emit\n a signal with current clock\n \"\"\"\n while True:\n await sleep(randint(2, 7)) # Sleep a random time\n current_time = int(time()) # The interface we defined uses integers\n export_object.clock.emit(current_time)\n\n\nasync def startup() -> None:\n \"\"\"Perform async startup actions\"\"\"\n # Acquire a known name on the bus\n # Clients will use that name to address this server\n await request_default_bus_name_async('org.example.test')\n # Export the object to D-Bus\n export_object.export_to_dbus('/')\n\n\nloop.run_until_complete(startup())\ntask_clock = loop.create_task(clock())\nloop.run_forever()\n```\n\nClient `example_client.py` file:\n\n```python\nfrom asyncio import new_event_loop\n\nfrom example_interface import ExampleInterface\n\n# Create a new proxied object\nexample_object = ExampleInterface.new_proxy('org.example.test', '/')\n\n\nasync def print_clock() -> None:\n # Use async for loop to print clock signals we receive\n async for x in example_object.clock:\n print('Got clock: ', x)\n\n\nasync def call_upper() -> None:\n s = 'test string'\n s_after = await example_object.upper(s)\n\n print('Initial string: ', s)\n print('After call: ', s_after)\n\n\nasync def get_hello_world() -> None:\n print('Remote property: ', await example_object.hello_world)\n\nloop = new_event_loop()\n\n# Always bind your tasks to a variable\ntask_upper = loop.create_task(call_upper())\ntask_clock = loop.create_task(print_clock())\ntask_hello_world = loop.create_task(get_hello_world())\n\nloop.run_forever()\n```\n\n## License\n\nPython-sdbus is licensed under [LGPL-2.1-or-later](https://spdx.org/licenses/LGPL-2.1-or-later.html).\n\nThe LGPL license is an extension of GPL license therefore both licenses' texts are required.\n",
"bugtrack_url": null,
"license": "LGPL-2.1-or-later",
"summary": "Modern Python D-Bus library. Based on sd-bus from libsystemd.",
"version": "0.13.0",
"project_urls": {
"Documentation": "https://python-sdbus.readthedocs.io/en/latest/",
"Homepage": "https://github.com/igo95862/python-sdbus",
"Source": "https://github.com/igo95862/python-sdbus/",
"Tracker": "https://github.com/igo95862/python-sdbus/issues/"
},
"split_keywords": [
"dbus",
"ipc",
"linux",
"freedesktop"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "85fb060bc3ffdbfae6062800ee516b68c5a050e5c4cb9424759a7650462a9f5b",
"md5": "a1bdc554a5f363e1d574a738a6395d51",
"sha256": "fcc88e70e76723234fd0987edccbcc3fe5f4e99245eb30a6b362ef7f882fd8a3"
},
"downloads": -1,
"filename": "sdbus-0.13.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
"has_sig": false,
"md5_digest": "a1bdc554a5f363e1d574a738a6395d51",
"packagetype": "bdist_wheel",
"python_version": "cp37",
"requires_python": ">=3.7",
"size": 540599,
"upload_time": "2024-10-31T22:13:15",
"upload_time_iso_8601": "2024-10-31T22:13:15.443902Z",
"url": "https://files.pythonhosted.org/packages/85/fb/060bc3ffdbfae6062800ee516b68c5a050e5c4cb9424759a7650462a9f5b/sdbus-0.13.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "57335d6d93d2897901cf503ed6db47b10208195fedaa0ed4e9f7c9f511fc649c",
"md5": "d241ab3216011bfeaba493789efbfe72",
"sha256": "199a4c321fc5b4cded57a110f82625f6541909c40e733f574d12afc5ace149a7"
},
"downloads": -1,
"filename": "sdbus-0.13.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
"has_sig": false,
"md5_digest": "d241ab3216011bfeaba493789efbfe72",
"packagetype": "bdist_wheel",
"python_version": "cp37",
"requires_python": ">=3.7",
"size": 539172,
"upload_time": "2024-10-31T22:13:17",
"upload_time_iso_8601": "2024-10-31T22:13:17.196286Z",
"url": "https://files.pythonhosted.org/packages/57/33/5d6d93d2897901cf503ed6db47b10208195fedaa0ed4e9f7c9f511fc649c/sdbus-0.13.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4fc78740ff78e9ffdbb9a28e7722e145795015c62ea7ce812242f5968073511c",
"md5": "ea63ebfd0499940dc32878b0ffb9601c",
"sha256": "801bd46608ee82614d42960c8ba8ae9300edb1bf5bbeb534bc8fd21f13d2c20e"
},
"downloads": -1,
"filename": "sdbus-0.13.0.tar.gz",
"has_sig": false,
"md5_digest": "ea63ebfd0499940dc32878b0ffb9601c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 85887,
"upload_time": "2024-10-31T22:13:19",
"upload_time_iso_8601": "2024-10-31T22:13:19.202442Z",
"url": "https://files.pythonhosted.org/packages/4f/c7/8740ff78e9ffdbb9a28e7722e145795015c62ea7ce812242f5968073511c/sdbus-0.13.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-31 22:13:19",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "igo95862",
"github_project": "python-sdbus",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "sdbus"
}