An asyncio-based package for creating CLI utilities and service daemons.
Project description
ctlbase
An asyncio-based framework for creating CLI utilities and service daemons.
For CLI utilities, it supports ...
- ... sharing a common set of arguments across utlities, backed by default implementations.
- ... message output in plain text or JSON to stdout and stderr.
- ... setting so-called modes, i.e. persistent flags with an optional timeout after which the flag is unset automatically.
For both CLI utilities and service daemons, it supports ...
- ... auto-discovery of associated files, e.g. configuration files.
- ... parsing Bash-style configuration files.
- ... reading credentials from a file, a keyring, TPM2 or a user prompt.
- ... sophisticated message handling in English, supporting translations into other languages.
- ... automated exit code generation based on error and warning messages.
For service daemons, it supports ...
- ... logging to a file instead of or in addition to stdout and stderr.
- ... rendering credentials in various output formats, to be picked up by systemd services.
- ... automated logging of asyncio task results.
For apidocs, see https://xoocoon.github.io/ctlbase.
Core concepts
To understand the core concepts of the package, it is advisable to read the introduction of the control apidoc.
An example for a Bash-style configuration file is included in the repo under templates/etc/bashconfig. It can be used to initialize a Control instance or a ControlShell instance.
As an example for a i18next-like translation file, see the file templates/locales/de/translation.json in the repo. It can be used with the addTranslations() method of a MessageBuffer instance.
Installation
Package dependencies
The following packages need to be installed:
- aiofiles, for accessing files with asyncio
- keyring, if you want to retrieve credentials from your desktop environment's keyring, e.g. libsecret/Seahorse.
If you install ctlbase in a virtual Python environment, as recommended under Package installation, dependencies will be installed automatically as needed.
On a Debian-based system, the dependencies can be installed as follows:
sudo apt update && sudo apt install -y python3-aiofiles python3-keyring
Package installation
For installing the ctlbase package you have at least two choices:
- Install the latest release from PyPI via
pip. - Install directly from a local clone of the GitHub repo.
In both cases, it is recommended to use a virtual Python environment to encapsulate all the required dependencies. See https://docs.python.org/3/library/venv.html for details on how to create one.
For installing from PyPI, use the pip command of your target environment as follows:
pip install ctlbase
For installing from a local clone of the GitHub repo, use the pip command of your target environment as follows:
pip install $CTLBASE_PATH
... where $CTLBASE_PATH resolves to the root directory of the repo containing the pyproject.toml file.
In both cases, if you want to retrieve credentials from your desktop environment's keyring, install the optional keyring dependency by appending [keyring] to the command.
[!WARNING] On some Linux distributions, Python packages are managed by the system's package manager, especially Debian and derivatives. Installing ctlbase globally could break these system-wide packages. On these systems, a virtual Python environment is strongly recommended.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ctlbase-1.0a2.tar.gz.
File metadata
- Download URL: ctlbase-1.0a2.tar.gz
- Upload date:
- Size: 59.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1b5949016504b52f2c063b710278e31fa77cace63a97a51f2c1bb8ae55ca921
|
|
| MD5 |
853c1696fa26dae9eeecb2009f1283c0
|
|
| BLAKE2b-256 |
4e1128c93815f654533ec309a7e0c8dc10abeecc0a8d354c64decc3ce107aa52
|
File details
Details for the file ctlbase-1.0a2-py3-none-any.whl.
File metadata
- Download URL: ctlbase-1.0a2-py3-none-any.whl
- Upload date:
- Size: 66.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2fa562fecb3dd4193525edf19bdaf1b7d69d808bc17afda7f109241a00ca656
|
|
| MD5 |
138ab03a86297b09b1dafa4b468eab46
|
|
| BLAKE2b-256 |
c0a0af28b72d4695fb07e296e77f1af314b0ed623e1a5428e5c68a20d04e0ae5
|