Tools for building CLI applications
Project description
pyapputil
Python module to simplify building CLI applications. Includes simple helpers for building an app, validating arguments, configfiles/default values, logging, global exception catching, privilege escalation, signal handling, time/timezones, multithreading...
Python 2 and 3 compatible.
appframework
This wrapper takes care of signal handling, uncaught exceptions, exit codes, and a host of other things so you don't have to. It integrates with appconfig, argutil to provide argument parsing with config file support, overidable default values, and user friendly help, plus typeutil to provide easy, strong argument validation while maintaining duck typing.
from pyapputil.appframework import PythonApp
from pyapputil.appconfig import appconfig
from pyapputil.argutil import ArgumentParser
from pyapputil.typeutil import ValidateAndDefault, OptionalValueType, StrType
@ValidateAndDefault({
# "arg_name" : (arg_type, arg_default)
"arg1" : (OptionalValueType(StrType(allowEmpty=False)), appconfig["arg1"]),
"arg2" : (float, 0),
})
def main(arg1, arg2):
pass
if __name__ == '__main__':
parser = ArgumentParser(description="My cool commandline app")
parser.add_argument("-a", "--arg1", type=StrType(allowEmpty=False), default=appconfig["arg1"], help="the first argument")
parser.add_argument("-b", "--arg2", type=float, help="the second argument")
args = parser.parse_args_to_dict()
app = PythonApp(main, args)
app.Run(**args)
appconfig
This module presents configuration values combined from defaults, user config, and environment variables.
To get a configuration variable named some_value
:
from pyapputil.appconfig import appconfig
appconfig["some_value"]
The default values are stored in appdefaults.py
in the application's
root directory. This is a pure python file that gets imported, so you it can be
anything from a list of variables/values to any arbitrary code you need to set
up your default values.
The user can optionally provide a userconfig.yml
file to override
the defaults. This is a text YAML file that gets loaded after appdefaults.py,
and any values in this file will override values from appdefautls.
If the user wants to override a default named some_var, they can simply add an
entry to userconfig.yml like this:
some_value: 123
The user can optionally export environment variables to override the defaults or user config. The prefix used for environment variables is set in appdefaults.py. If the prefix is set to "MYAPP_" and the user wan't to override a config var named some_value, they could override it with an environment varible like this:
export MYAPP_SOME_VALUE=123
argutil
This is a forked version of python's argparse, that is integrated with appconfig so that command line arguments can automatically set default values from appconfig, and the help display will show the default value as well as the name of the ENV variable that can be used to override it.
typeutil
Collection of type validators that can be used with argparse/argutil, and decorators and util functions for using the same validators on functions
exceptutil
logutil
shellutil
threadutil
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
File details
Details for the file pyapputil-1.1.8.tar.gz
.
File metadata
- Download URL: pyapputil-1.1.8.tar.gz
- Upload date:
- Size: 48.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d12c227acef9a03dadb7a93e66bfefc3af8e54e7d2c6d185e32e6c00eb7f3ebb |
|
MD5 | 080c58c4f6423f8ce0090d4563f8d43f |
|
BLAKE2b-256 | 97a6fe3a9f1ee2dbfeeb66e565fe310feb15a8fade781b51252bd8f06fc39e57 |