Skip to main content

Python bindings for sd-bus

Project description

pysysdc Travis Build Status Github Actions Status

Python3.5+ sd-bus adapter which allows to manage services, publish and call methods.

Tested on Ubuntu 16.04 and Ubuntu 20.04.

Idea

If you are orchestrating a large number of services on a Linux system, you have to run the command service or systemctl quite frequently. If you want to do this programmatically, you have to start the process in most cases with a shell (to parse systemctl commands arguments) which sometimes may lead you to arguments symbols escaping.

What will do the systemctl restart nginx.service command in the end? This command will send message over SD-Bus to systemd daemon (PID 1) which will restart nginx service. What if it is possible to send the message to systemd through the SD-Bus directly from Python? What if the same mechanism can be used for IPC?

How to compile

sudo apt update
sudo apt install python3-setuptools python3-stdeb python3-all-dev libsystemd-dev
python3 ./setup.py build

How to build DEB package

Just run build.sh and make sure you installed fakeroot package.

sudo apt update
sudo apt install fakeroot python3-setuptools python3-stdeb python3-all-dev libsystemd-dev
./build.sh

How to use

For example you can reload nginx service in the following way:

from pysysdc.unit import Unit

Unit("nginx").reload()

All supported unit methods can be found here.

It's also possible to set your hostname through this library without any subprocess spawn, configuration editing and etc:

from pysysdc.methods import Methods

Methods.set_pretty_hostname("myhostname")

or reboot your machine

from pysysdc.methods import Methods

Methods.machine_reboot()

see other implemented systemd methods here.

Also you can publish method in you service.

from pysysdc.sdbus import SDBus

data = "example data string"
def handler():
	return True, data

sd = SDBus(path="/dc/cloud/auth", if_name="dc.cloud.auth", method_name="Token", method_args="s", output_sig="s", method_return="s")
sd.set_func(handler)
sd.listen()

and call it from another program

from pysysdc.sdbus import SDBus

sd = SDBus(
	path="/dc/cloud/auth", 
	if_name="dc.cloud.auth", 
	method_name="Token", 
	method_args="s", 
	method_return="s", 
	output_sig="s")
ret = sd.send(method_name="Token")
print(ret)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysysdc-1.0.0.tar.gz (15.0 kB view hashes)

Uploaded Source

Built Distributions

pysysdc-1.0.0-pp39-pypy39_pp73-manylinux_2_24_x86_64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.24+ x86-64

pysysdc-1.0.0-pp39-pypy39_pp73-manylinux_2_24_i686.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.24+ i686

pysysdc-1.0.0-pp38-pypy38_pp73-manylinux_2_24_x86_64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.24+ x86-64

pysysdc-1.0.0-pp38-pypy38_pp73-manylinux_2_24_i686.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.24+ i686

pysysdc-1.0.0-pp37-pypy37_pp73-manylinux_2_24_x86_64.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.24+ x86-64

pysysdc-1.0.0-pp37-pypy37_pp73-manylinux_2_24_i686.whl (1.1 MB view hashes)

Uploaded PyPy manylinux: glibc 2.24+ i686

pysysdc-1.0.0-cp311-cp311-manylinux_2_24_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.24+ x86-64

pysysdc-1.0.0-cp311-cp311-manylinux_2_24_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.24+ i686

pysysdc-1.0.0-cp310-cp310-manylinux_2_24_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.24+ x86-64

pysysdc-1.0.0-cp310-cp310-manylinux_2_24_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.24+ i686

pysysdc-1.0.0-cp39-cp39-manylinux_2_24_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.24+ x86-64

pysysdc-1.0.0-cp39-cp39-manylinux_2_24_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.24+ i686

pysysdc-1.0.0-cp38-cp38-manylinux_2_24_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.24+ x86-64

pysysdc-1.0.0-cp38-cp38-manylinux_2_24_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.24+ i686

pysysdc-1.0.0-cp37-cp37m-manylinux_2_24_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.24+ x86-64

pysysdc-1.0.0-cp37-cp37m-manylinux_2_24_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.24+ i686

pysysdc-1.0.0-cp36-cp36m-manylinux_2_24_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.24+ x86-64

pysysdc-1.0.0-cp36-cp36m-manylinux_2_24_i686.whl (1.1 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.24+ i686

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page