Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ffy00/dbus-objects
DBus objects implementation on top of the Python type system
https://github.com/ffy00/dbus-objects
dbus dbus-objects dbus-python hacktoberfest jeepney python
Last synced: 30 days ago
JSON representation
DBus objects implementation on top of the Python type system
- Host: GitHub
- URL: https://github.com/ffy00/dbus-objects
- Owner: FFY00
- License: mit
- Created: 2020-04-26T23:19:25.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-07T22:32:02.000Z (3 months ago)
- Last Synced: 2024-11-27T18:23:06.117Z (about 1 month ago)
- Topics: dbus, dbus-objects, dbus-python, hacktoberfest, jeepney, python
- Language: Python
- Homepage: https://dbus-objects.readthedocs.io/en/latest/
- Size: 204 KB
- Stars: 11
- Watchers: 3
- Forks: 4
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.rst
- Funding: FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# dbus-objects
![checks](https://github.com/FFY00/dbus-objects/workflows/checks/badge.svg)
![tests](https://github.com/FFY00/dbus-objects/workflows/tests/badge.svg)
[![codecov](https://codecov.io/gh/FFY00/dbus-objects/branch/master/graph/badge.svg)](https://codecov.io/gh/FFY00/dbus-objects)
[![PyPI version](https://badge.fury.io/py/dbus-objects.svg)](https://pypi.org/project/dbus-objects/)DBus objects implementation on top of the Python type system.
Object declarations will be introspected and the equivalent DBus signature
automatically generated. This makes it incredible easy to develop DBus object
providers ("servers"), especially if you are already writing typed Python!Integrations:
- [jeepney](https://gitlab.com/takluyver/jeepney) (blocking IO and [trio](https://github.com/python-trio/trio) backends)```python
import randomfrom typing import List
import dbus_objects
import dbus_objects.integration.jeepneyclass 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
│ ├── 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`:
```xml
```
### License
MIT