TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/alex-ber/AlexBerUtils/llms.txt
Use this file to discover all available pages before exploring further.
parsers module provides low-level utilities for parsing command-line arguments, converting string values to Python types, and checking for empty values. It is the foundation used by init_app_conf.parse_config().
No optional dependencies are required — this module is available in the base install:
Parsing CLI arguments
parse_sys_args(argumentParser=None, args=None)
Parses --key=value style CLI arguments and returns them as a flat OrderedDict.
An
argparse.ArgumentParser instance. If None, a new one is created automatically.Explicit argument list. If
None, reads from sys.argv[1:]. Pass a list to suppress sys.argv — useful in tests.(params, sys_d) where:
paramsis theargparse.Namespacewith known arguments (notablyparams.config_file)sys_dis anOrderedDictof unknown--key=valuearguments with--stripped
--general.config.file (maps to params.config_file, default 'config.yml'). All other --key=value arguments become entries in sys_d.
Arguments without = are parsed as keys with None as their value:
ArgumentParser
parsers.ArgumentParser is the standard argparse.ArgumentParser extended with an as_dict() method:
ArgumentParser.as_dict(args=None)
Parses --key=value arguments and returns them as an OrderedDict. Strips the -- prefix from keys.
None). Use safe_eval() or mask_value() from init_app_conf to convert types.
Type conversion
safe_eval(value)
Converts a string to a Python number type (int or float) using ast.literal_eval. Returns the original string if conversion is not possible — it never raises.
| Input string | Output |
|---|---|
'1000' | 1000 (int) |
'0.1' | 0.1 (float) |
'-5' | -5 (int) |
'John' | 'John' (str) |
'%(message)s' | '%(message)s' (str) |
decimal.Decimal, datetime.datetime, numpy types.
parse_boolean(value)
Converts a value to a Python bool. String comparison is case-insensitive.
The value to convert.
True, False, or None.
Raises: ValueError for unrecognized strings.
'true' → True, 'false' → False. All other strings raise ValueError.
Checking for empty values
is_empty(value)
Returns True if the value is None or an empty iterable (empty string, empty list, etc.).
Integration with init_app_conf
parse_sys_args() is called internally by init_app_conf.parse_config(). The flow is:
parse_sys_args is called
Reads
--key=value arguments from sys.argv (or the explicit args list). The --general.config.file argument is extracted into params.config_file.to_convex_map is applied
The flat
{'general.profiles': 'dev', 'app.host_name': 'yahoo.com'} dict is converted to nested OrderedDicts via to_convex_map().parse_sys_args() directly if you only need the raw flat argument dict without YAML loading:
