trick17


Nametrick17 JSON
Version 0.0.4 PyPI version JSON
download
home_pageNone
SummarySystemd utility functions in pure python
upload_time2024-08-26 16:20:08
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords systemd
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # trick17

[![Pre-Alpha warning](https://img.shields.io/badge/warning-Pre--Alpha%20code-red)]()

[![PyPI - Version](https://img.shields.io/pypi/v/trick17.svg)](https://pypi.org/project/trick17)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/trick17.svg)](https://pypi.org/project/trick17)

`trick17` is a pure python, lightweight package that interfaces with various [systemd](https://systemd.io) components.

-----

**Table of Contents**

- [Installation](#installation)
- [Modules](#modules)
- [License](#license)
- [Motivation](#motivation-and-alternatives)

## Installation

```console
pip install trick17
```

## Modules

### trick17.daemon

- `daemon.booted()` returns `True` if system was booted by systemd.
- `daemon.notify(state)` sends a notification to systemd.
- `listen_fds()` returns an list of (fd, name) tuples in case of socket activation,
  see [systemd.socket](https://www.freedesktop.org/software/systemd/man/systemd.socket.html)

### trick17.journal

The `trick17.journal` allows to use the systemd [Native Journal Protocol](https://systemd.io/JOURNAL_NATIVE_PROTOCOL/) via the Python [Logging facility](https://docs.python.org/3/library/logging.html).

- `JournalHandler` is a [`logging.Handler`](https://docs.python.org/3/library/logging.html#logging.Handler) subclass that speaks the systemd Native Journal Protocol
- Function `stderr_is_journal()` can be used to check if logging via `sys.stderr` should be upgraded to native logging, see [Automatic Protocol Upgrading](https://systemd.io/JOURNAL_NATIVE_PROTOCOL/#automatic-protocol-upgrading)

```python
import logging

from trick17 import journal

if journal.stderr_is_journal():
    handler = journal.JournalHandler()
else:
    handler = logging.StreamHandler()
root = logging.getLogger()
root.addHandler(handler)

logging.error('Something happened')
```

## License

`trick17` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.

## Motivation and alternatives

Many existing interfaces to systemd are python bindings to [libsystemd](https://www.freedesktop.org/software/systemd/man/latest/libsystemd.html), see e.g. [python-systemd](https://github.com/systemd/python-systemd) or [cysystemd](https://github.com/systemd/python-systemd).
Even if most systems running under systemd will have libsystemd already installed, a native python implementation has many advantages:
- easy vendoring,
- pypi availability of no-ABI, platform independent wheels, with no transitive dependencies.

This package is a partial implementation of the most used (at least by me) functions of libsystemd.
Please feel free open a issue if this package is useful to you and misses a feature.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "trick17",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "systemd",
    "author": null,
    "author_email": "Stefano Miccoli <stefano.miccoli@polimi.it>",
    "download_url": "https://files.pythonhosted.org/packages/b8/2e/fa685f2ebb6f39c84b6d8dd7c443073d2a2e365654fb6feea06d3f241453/trick17-0.0.4.tar.gz",
    "platform": null,
    "description": "# trick17\n\n[![Pre-Alpha warning](https://img.shields.io/badge/warning-Pre--Alpha%20code-red)]()\n\n[![PyPI - Version](https://img.shields.io/pypi/v/trick17.svg)](https://pypi.org/project/trick17)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/trick17.svg)](https://pypi.org/project/trick17)\n\n`trick17` is a pure python, lightweight package that interfaces with various [systemd](https://systemd.io) components.\n\n-----\n\n**Table of Contents**\n\n- [Installation](#installation)\n- [Modules](#modules)\n- [License](#license)\n- [Motivation](#motivation-and-alternatives)\n\n## Installation\n\n```console\npip install trick17\n```\n\n## Modules\n\n### trick17.daemon\n\n- `daemon.booted()` returns `True` if system was booted by systemd.\n- `daemon.notify(state)` sends a notification to systemd.\n- `listen_fds()` returns an list of (fd, name) tuples in case of socket activation,\n  see [systemd.socket](https://www.freedesktop.org/software/systemd/man/systemd.socket.html)\n\n### trick17.journal\n\nThe `trick17.journal` allows to use the systemd [Native Journal Protocol](https://systemd.io/JOURNAL_NATIVE_PROTOCOL/) via the Python [Logging facility](https://docs.python.org/3/library/logging.html).\n\n- `JournalHandler` is a [`logging.Handler`](https://docs.python.org/3/library/logging.html#logging.Handler) subclass that speaks the systemd Native Journal Protocol\n- Function `stderr_is_journal()` can be used to check if logging via `sys.stderr` should be upgraded to native logging, see [Automatic Protocol Upgrading](https://systemd.io/JOURNAL_NATIVE_PROTOCOL/#automatic-protocol-upgrading)\n\n```python\nimport logging\n\nfrom trick17 import journal\n\nif journal.stderr_is_journal():\n    handler = journal.JournalHandler()\nelse:\n    handler = logging.StreamHandler()\nroot = logging.getLogger()\nroot.addHandler(handler)\n\nlogging.error('Something happened')\n```\n\n## License\n\n`trick17` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.\n\n## Motivation and alternatives\n\nMany existing interfaces to systemd are python bindings to [libsystemd](https://www.freedesktop.org/software/systemd/man/latest/libsystemd.html), see e.g. [python-systemd](https://github.com/systemd/python-systemd) or [cysystemd](https://github.com/systemd/python-systemd).\nEven if most systems running under systemd will have libsystemd already installed, a native python implementation has many advantages:\n- easy vendoring,\n- pypi availability of no-ABI, platform independent wheels, with no transitive dependencies.\n\nThis package is a partial implementation of the most used (at least by me) functions of libsystemd.\nPlease feel free open a issue if this package is useful to you and misses a feature.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Systemd utility functions in pure python",
    "version": "0.0.4",
    "project_urls": {
        "Documentation": "https://github.com/miccoli/trick17#readme",
        "Issues": "https://github.com/miccoli/trick17/issues",
        "Source": "https://github.com/miccoli/trick17"
    },
    "split_keywords": [
        "systemd"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ae6feeee0dabe91a7de6436310c9fd7a718ff751b60250facd7b2a16511c1af6",
                "md5": "dfb5881e8308a7452c7b6a3623ef4f79",
                "sha256": "a089857b7de90d32d77f6c2b67678280ea37d319d9c92f74fa34b90593318d3e"
            },
            "downloads": -1,
            "filename": "trick17-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dfb5881e8308a7452c7b6a3623ef4f79",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 7824,
            "upload_time": "2024-08-26T16:20:07",
            "upload_time_iso_8601": "2024-08-26T16:20:07.157321Z",
            "url": "https://files.pythonhosted.org/packages/ae/6f/eeee0dabe91a7de6436310c9fd7a718ff751b60250facd7b2a16511c1af6/trick17-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b82efa685f2ebb6f39c84b6d8dd7c443073d2a2e365654fb6feea06d3f241453",
                "md5": "433b9aa8537838ec26c7ad56c8ac5444",
                "sha256": "4ff6c139ea8cc4729bb2ffa4b65bf0f393edd7b8453746b5e948e32bd073b8c9"
            },
            "downloads": -1,
            "filename": "trick17-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "433b9aa8537838ec26c7ad56c8ac5444",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 9072,
            "upload_time": "2024-08-26T16:20:08",
            "upload_time_iso_8601": "2024-08-26T16:20:08.482050Z",
            "url": "https://files.pythonhosted.org/packages/b8/2e/fa685f2ebb6f39c84b6d8dd7c443073d2a2e365654fb6feea06d3f241453/trick17-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-26 16:20:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "miccoli",
    "github_project": "trick17#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "trick17"
}
        
Elapsed time: 2.87735s