<div dir="ltr"><div>Hello systemd developers:</div><div><br></div><div>We talked last week about entertaining the idea of make pystemd part of systemd github org and eventually merge (in functionalities, not literally merge both) with the current python-systemd, This is our proposal to do this. happy to hear feedback :)</div><div><br></div>What do we propose to do?<div>-----<br><br>We want to bring pystemd[1] into the systemd organization, and merge (functionality wise) with python-systemd[2], so that there is a single Python library, supported by the systemd community, that interacts with the systemd API.<br><br>Why?</div><div>-----<br><br>systemd has a Python library already under the organization: python-systemd. This library does some interesting stuff with the journal (my personal favorite is creating a Python logger that talks directly with the journal, kudos to whoever did that!). <br><br>But in my honest opinion, this library is missing some core functionality to interact with systemd: the service manager, start/stop/interaction with Units, create ephemeral units, etc. At Meta (the company formerly known as Facebook) we created a python library that does that… among other things. <br><br>What is pystemd?</div><div>-----<br><br>pystemd, at its core, is a Python library that allows users to talk to systemd over dbus, without thinking that you are talking to systemd over dbus. It does this by binding sd_bus and other sd_* libraries from C to Python. <br><br>This enables users to interact with systemd in many ways. Most notably, but not restricted to, start/stop/kill and checking the status of units. <br><br>It was created because Instagram (at the time) needed to expose systemd features, like managing units, creating ephemeral units, using the notify and watchdog interface, etc. to Python and reduce the need to “shell-out” in order to parse results.<br><br>Example of usage:<br><br>from pystemd.systemd1 import Unit<br> <br>with Unit(b'postfix.service') as unit:<br>   if unit.Unit.ActiveState == b"active":<br>       unit.Unit.Stop(b'replace')<br> <br><br>Or <br><br>from pystemd.systemd1 import Manager<br> <br>with Manager() as manager:<br>   print("Version", manager.Manager.Version)<br>   print("Architecture", manager.Manager.Architecture)<br> <br>   # List Units<br>   for unit, state in manager.Manager.ListUnitFiles():<br>       print(f"    {unit} is {state}")<br><br><br>It does a few more things (I won't bore you with details), but my particular favorite is an analogous feature to systemd-run called pystemd.run. It’s similar to systemd-run in that it is a smart wrapper around StartTransientUnit. But it's meant to be “programatically called” instead of a CLI.<br><br>>>> import pystemd.run, time<br>>>> unit = pystemd.run(<br>    [b'/usr/bin/psql', b'postgres'],<br>    machine=b'db1',<br>    user=b'postgres',<br>    wait=False,<br>    env={b'PGTZ': b'UTC'}<br>)<br>>>> time.sleep(300)<br>>>> unit.Unit.Stop(b'postgres') # you lived too long, time to stop<br><br>  <br>If you want to know more, Anita Zhang and I did a talk in SCaLE [3] where we abused pystemd.<br><br>How do we propose to do this?<div>-----<br><br>Preliminary plan (of course we are open to any suggestions) look like this:<br><br>1. We move pystemd repo [1] into the systemd org, something like <a href="https://github.com/systemd/pystemd">https://github.com/systemd/pystemd</a><br>2. People with commit access to this repo (Davide, Anita and me) would remain having commit access to this repo, and whoever has access to the python-systemd repo [2] would be added here.<br>3. We merge all features of python-systemd (that are not in pystemd yet) into pystemd, this will probably mean re-writing most of those features. Development would be done by mostly me, with code review and from hopefully as close to the original authors as possible… Basically I don't want to be disrespectful of python-systemd.<br>4. If we want to keep the name python-systemd (and the import namespace of systemd) we can rename the repo as python-systemd, if we want to keep pystemd as the name of the package and the import namespace, we can make python-systemd as “a link” to pystemd<br>5. Whatever we decide on the last point, we cut the version 1.0.0 of pystemd, or the next version of python-systemd. And we let the new era of Python bindings start!<br><br>Best regards<br>Alvaro Leiva Geisse<br><br>[1] <a href="https://github.com/facebookincubator/pystemd">https://github.com/facebookincubator/pystemd</a><br>[2] <a href="https://github.com/systemd/python-systemd">https://github.com/systemd/python-systemd</a><br>[3] <a href="https://youtu.be/FMnvvfBYypY?t=24789">https://youtu.be/FMnvvfBYypY?t=24789</a><br><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><br></div></div></div></div></div></div>