{"id":13720228,"url":"https://github.com/systemd/python-systemd","last_synced_at":"2025-05-07T12:30:50.488Z","repository":{"id":38707124,"uuid":"38590109","full_name":"systemd/python-systemd","owner":"systemd","description":"Python wrappers for systemd functionality","archived":false,"fork":false,"pushed_at":"2025-01-19T15:59:22.000Z","size":414,"stargazers_count":469,"open_issues_count":19,"forks_count":66,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-01-19T16:46:12.185Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/systemd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-07-06T00:58:06.000Z","updated_at":"2025-01-19T15:59:24.000Z","dependencies_parsed_at":"2024-06-18T12:38:02.576Z","dependency_job_id":null,"html_url":"https://github.com/systemd/python-systemd","commit_stats":{"total_commits":326,"total_committers":53,"mean_commits":6.150943396226415,"dds":0.352760736196319,"last_synced_commit":"f95161fccd7cd2c2bce579001c5708f03ce000e1"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemd%2Fpython-systemd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemd%2Fpython-systemd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemd%2Fpython-systemd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemd%2Fpython-systemd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/systemd","download_url":"https://codeload.github.com/systemd/python-systemd/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252876315,"owners_count":21818163,"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":[],"created_at":"2024-08-03T01:01:01.289Z","updated_at":"2025-05-07T12:30:50.157Z","avatar_url":"https://github.com/systemd.png","language":"C","readme":"python-systemd\n===============\n\nPython module for native access to the systemd facilities. Functionality\nis separated into a number of modules:\n- `systemd.journal` supports sending of structured messages to the journal\n  and reading journal files,\n- `systemd.daemon` wraps parts of `libsystemd` useful for writing daemons\n  and socket activation,\n- `systemd.id128` provides functions for querying machine and boot identifiers\n  and a lists of message identifiers provided by systemd,\n- `systemd.login` wraps parts of `libsystemd` used to query logged in users\n  and available seats and machines.\n\nInstallation\n============\n\nThis module should be packaged for almost all Linux distributions. Use\n\nOn Fedora:\n\n    dnf install python3-systemd\n\nOn Debian/Ubuntu/Mint:\n\n    apt update\n    apt install python3-systemd\n\nOn openSUSE and SLE:\n\n    zypper in python3-systemd\n\nOn Arch:\n\n    pacman -Sy python-systemd\n\nThe project is also available on pypi as `systemd-python`:\n\n[![PyPI](https://img.shields.io/pypi/v/systemd-python.svg)](https://pypi.org/project/systemd-python/)\n\nTo build from source\n--------------------\n\nOn CentOS, RHEL, and Fedora:\n\n    dnf install git python3-pip gcc python3-devel systemd-devel\n    pip3 install 'git+https://github.com/systemd/python-systemd.git#egg=systemd-python'\n\nOn Debian or Ubuntu:\n\n    apt install libsystemd-{journal,daemon,login,id128}-dev gcc python3-dev pkg-config\n\nUsage\n=====\n\nQuick example:\n\n    from systemd import journal\n    journal.send('Hello world')\n    journal.send('Hello, again, world', FIELD2='Greetings!', FIELD3='Guten tag')\n    journal.send('Binary message', BINARY=b'\\xde\\xad\\xbe\\xef')\n\nThere is one required argument — the message, and additional fields\ncan be specified as keyword arguments. Following the journald API, all\nnames are uppercase.\n\nThe journald sendv call can also be accessed directly:\n\n    from systemd import journal\n    journal.sendv('MESSAGE=Hello world')\n    journal.sendv('MESSAGE=Hello, again, world', 'FIELD2=Greetings!',\n                   'FIELD3=Guten tag')\n    journal.sendv('MESSAGE=Binary message', b'BINARY=\\xde\\xad\\xbe\\xef')\n\nThe two examples should give the same results in the log.\n\nReading from the journal is often similar to using the `journalctl` utility.\n\nShow all entries since 20 minutes ago (`journalctl --since \"20 minutes ago\"`):\n\n    from systemd import journal\n    from datetime import datetime, timedelta\n    j = journal.Reader()\n    j.seek_realtime(datetime.now() - timedelta(minutes=20))\n    for entry in j:\n        print(entry['MESSAGE'])\n\nShow entries between two timestamps (`journalctl --since \"50 minutes ago\" --until \"10 minutes ago\"`):\n\n    from systemd import journal\n    from datetime import datetime, timedelta\n    j = journal.Reader()\n    since = datetime.now() - timedelta(minutes=50)\n    until = datetime.now() - timedelta(minutes=10)\n    j.seek_realtime(since)\n    for entry in j:\n      if entry['__REALTIME_TIMESTAMP'] \u003e until:\n        break\n      print(entry['MESSAGE'])\n\nShow explanations of log messages alongside entries (`journalctl -x`):\n\n    from systemd import journal\n    j = journal.Reader()\n    for entry in j:\n        print(\"MESSAGE: \", entry['MESSAGE'])\n        try:\n            print(\"CATALOG: \", j.get_catalog())\n        except:\n            pass\n\nShow entries by a specific executable (`journalctl /usr/bin/vim`):\n\n    from systemd import journal\n    j = journal.Reader()\n    j.add_match('_EXE=/usr/bin/vim')\n    for entry in j:\n        print(entry['MESSAGE'])\n\n - Note: matches can be added from many different fields, for example\n   entries from a specific process ID can be matched with the `_PID`\n   field, and entries from a specific unit (ie. `journalctl -u\n   systemd-udevd.service`) can be matched with `_SYSTEMD_UNIT`.\n   See all fields available at the\n   [systemd.journal-fields docs](https://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html).\n\nShow kernel ring buffer (`journalctl -k`):\n\n    from systemd import journal\n    j = journal.Reader()\n    j.add_match('_TRANSPORT=kernel')\n    for entry in j:\n        print(entry['MESSAGE'])\n\nRead entries in reverse (`journalctl _EXE=/usr/bin/vim -r`):\n  \n    from systemd import journal\n    class ReverseReader(journal.Reader):\n        def __next__(self):\n            ans = self.get_previous()\n            if ans:\n                return ans\n            raise StopIteration()\n\n    j = ReverseReader()\n    j.add_match('_EXE=/usr/bin/vim')\n    j.seek_tail()\n    for entry in j:\n      print(entry['MESSAGE'])\n\n\nNotes\n-----\n\n* Unlike the native C version of journald's `sd_journal_send()`,\n  printf-style substitution is not supported. Perform any substitution\n  using Python's f-strings first (or `.format()` or the `%` operator).\n* A `ValueError` is raised if `sd_journald_sendv()` results in an\n  error. This might happen if there are no arguments or one of them is\n  invalid.\n\nA handler class for the Python logging framework is also provided:\n\n    import logging\n    from systemd import journal\n    logger = logging.getLogger('custom_logger_name')\n    logger.addHandler(journal.JournalHandler(SYSLOG_IDENTIFIER='custom_unit_name'))\n    logger.warning(\"Some message: %s\", 'detail')\n\n`libsystemd` version compatibility\n----------------------------------\n\nThis module may be compiled against any version of `libsystemd`. At\ncompilation time, any functionality that is not available in that\nversion is disabled, and the resulting binary module will depend on\nsymbols that were available at compilation time. This means that the\nresulting binary module is compatible with that or any later version\nof `libsystemd`. To obtain maximum possible functionality, this module\nmust be compile against suitably recent libsystemd.\n\nDocumentation\n=============\n\nOnline documentation can be found at [freedesktop.org](https://www.freedesktop.org/software/systemd/python-systemd/)\n\nTo build it locally run:\n\n    make sphinx-html\n\nOr use any other builder, see `man sphinx-build` for a list. The compiled docs will be e.g. in `docs/html`.\n\nViewing Output\n==============\n\nQuick way to view output with all fields as it comes in:\n\n    sudo journalctl -f --output=json\n\nTest Builds (for Development)\n=============================\n\n    python setup.py build_ext -i\n    python\n    \u003e\u003e\u003e from systemd import journal\n    \u003e\u003e\u003e journal.send(\"Test\")\n\n[![Build Status](https://semaphoreci.com/api/v1/projects/42d43c62-f6e5-4fd5-a93a-2b165e6be575/530946/badge.svg)](https://semaphoreci.com/zbyszek/python-systemd)\n","funding_links":[],"categories":["C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystemd%2Fpython-systemd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsystemd%2Fpython-systemd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystemd%2Fpython-systemd/lists"}