{"id":22812735,"url":"https://github.com/sb0y/pysysdc","last_synced_at":"2026-04-19T05:32:45.286Z","repository":{"id":65187218,"uuid":"586183273","full_name":"sb0y/pysysdc","owner":"sb0y","description":"Python3.5+ sd-bus adapter which allows to manage services, publish and call methods","archived":false,"fork":false,"pushed_at":"2023-07-26T20:22:12.000Z","size":133,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-07T04:20:46.682Z","etag":null,"topics":["ipc","python","sd-bus","systemd","systemd-service","systemd-unit"],"latest_commit_sha":null,"homepage":"https://bagrintsev.me","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sb0y.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-01-07T08:23:55.000Z","updated_at":"2023-09-28T18:34:04.000Z","dependencies_parsed_at":"2023-02-08T08:02:09.547Z","dependency_job_id":null,"html_url":"https://github.com/sb0y/pysysdc","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sb0y%2Fpysysdc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sb0y%2Fpysysdc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sb0y%2Fpysysdc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sb0y%2Fpysysdc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sb0y","download_url":"https://codeload.github.com/sb0y/pysysdc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246385406,"owners_count":20768668,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ipc","python","sd-bus","systemd","systemd-service","systemd-unit"],"created_at":"2024-12-12T12:13:33.944Z","updated_at":"2026-04-19T05:32:45.280Z","avatar_url":"https://github.com/sb0y.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pysysdc [![Travis Build Status](https://app.travis-ci.com/sb0y/pysysdc.svg?branch=main)](https://app.travis-ci.com/sb0y/pysysdc) ![Github Actions Status](https://github.com/sb0y/pysysdc/actions/workflows/python-publish.yml/badge.svg)\n\n\nPython3.5+ sd-bus adapter which allows to manage services, publish and call methods, natively control systemd units.\n\nTested on Ubuntu 16.04, Ubuntu 20.04 and Ubuntu 24.04.\n\n## Idea\nIf you are orchestrating a large number of services on a Linux system, you have to run the command `service` or `systemctl` quite frequently.\nIf 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.\n\nWhat 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.\nWhat 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?\n\n## How to compile\n```\nsudo apt update\nsudo apt install python3-setuptools python3-stdeb python3-all-dev libsystemd-dev dh-python\npython3 ./setup.py build\n```\n\n## How to build DEB package\nJust run `build.sh` and make sure you installed `fakeroot` package.\n```\nsudo apt update\nsudo apt install fakeroot python3-setuptools python3-stdeb python3-all-dev libsystemd-dev\n./build.sh\n```\n\n## How to use\nFor example you can reload `nginx` service in the following way:\n```python\nimport pysysdc.systemctl as systemctl\n\nsystemctl(svc=\"nginx\", action=\"reload\")\n```\n\nAll supported unit methods can be found [here](https://github.com/sb0y/pysysdc/blob/main/pysysdc/unit.py#L32).\n\nIt's also possible to set your hostname through this library without any subprocess spawn, configuration editing and etc:\n```python3\nfrom pysysdc.methods import Methods\n\nMethods.set_pretty_hostname(\"myhostname\")\n```\nor reboot your machine\n```python3\nfrom pysysdc.methods import Methods\n\nMethods.machine_reboot()\n```\nsee other implemented systemd methods [here](https://github.com/sb0y/pysysdc/blob/ffa3b75bb782efdb167980a3a52b4ae4ec96ca0d/pysysdc/methods.py#L16).\n\nAlso you can publish method in you service.\n```python\nfrom pysysdc.sdbus import SDServer\n\ntoken_data = \"Zm9yaDhhOWViZWJjMjYxZmU1MTVlOTlhNjczMWE3NWQ3N2ZiOjoyMDQ3NzY6Omh0dHA6Ly9yZWdpb25zZWZmZWN0aXZlLmNvbS86Ojo6MTUxMDczMjE6OjY2NDcxNDo6MDo6MTo6MTo6OjowOjpkZWZhdWx0Ojow\"\ndef token(arg: str) -\u003e tuple:\n\tprint(\"Hello from handler token().\")\n\tprint(\"Function runned with argument: '%s'.\" % arg)\n\treturn True, token_data\n\ndef config(mode: str, data: str) -\u003e tuple:\n\tprint(\"Hello from handler config().\")\n\tprint(\"Mode: '%s'\" % mode)\n\tprint(\"Data: '%s'\" % data)\n\treturn True, 'done', 'test', 10\n\nsd = SDServer(\n\t(\n\t\t{\"path\": \"/dc/cloud/auth\", \n\t\t\"if_name\": \"dc.cloud.auth\", \n\t\t\"method_name\": \"Token\", \n\t\t\"input_sig\": \"s\", \n\t\t\"output_sig\": \"is\", \n\t\t\"method_handler\": token},\n\n\t\t{\"path\": \"/dc/cloud/auth\",\n\t\t\"if_name\": \"dc.cloud.auth.config\", \n\t\t\"method_name\": \"Config\", \n\t\t\"input_sig\": \"ss\", \n\t\t\"output_sig\": \"issi\", \n\t\t\"method_handler\": config},\n\t)\n\n)\nsd.listen() # blocking\n```\n\nand call it from another program\n\n```python\nfrom pysysdc.sdbus import SDClient\n\nsd = SDClient(\n\tservice_name=\"dc.cloud.auth\",\n\tpath=\"/dc/cloud/auth\",\n\tif_name=\"dc.cloud.auth\",\n\tmethod_name=\"Token\",\n\tinput_sig=\"s\",\n\toutput_sig=\"is\"\n)\nret = sd.send(method_name=\"Token\", first_arg=\"get\")\nprint(ret)\nprint(repr(ret))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsb0y%2Fpysysdc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsb0y%2Fpysysdc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsb0y%2Fpysysdc/lists"}