pyparam
pyparam
Powerful parameter processing with pyparam
Defaults for pyparam
Holds some default values for pyparam. To change any of the CONSOLE_WIDTH, HELP_SECTION_INDENT or HELP_OPTION_WIDTH:
from pyparam import defaults
default.CONSOLE_WIDTH = 100
CONSOLE_WIDTH
(int) — The total width for the help page.HELP_OPTION_WIDTH
(int) — The width that the option name and type take up in the help page.HELP_SECTION_INDENT
(int) — The indentation for the contents in a sectionPOSITIONAL
(str) — The name of positional parameterTYPE_NAMES
(dict(str: str)) — The type name mappings to get the type name from aliases Do not modify this variable. It is maintained bypyparam.param.regiest_param
pyparam.exceptions
Exceptions used in pyparam
PyParamException
— Base exception for pyparam</>PyParamTypeError
— When parameter type is not supported</>PyParamValueError
— When parameter value is improper</>PyParamNameError
— Any errors related to parameter names</>
Definition of a single parameter
PARAM_MAPPINGS
(dict(str: type of Param)) — The type to Param mappings, used for params to init a parameter. Managed byregister_param
Param
— Base class for parameter</>ParamAuto
— An auto parameter whose value is automatically casted</>ParamInt
— An int parameter whose value is automatically casted into an int</>ParamFloat
— A float parameter whose value is automatically casted into a float</>ParamStr
— A str parameter whose value is automatically casted into a str</>ParamBool
— A bool parameter whose value is automatically casted into a bool</>ParamCount
— A bool parameter whose value is automatically casted into a bool</>ParamPath
— A path parameter whose value is automatically casted into a pathlib.Path</>ParamDir
— Subclass of ParamPath.</>ParamPy
— A parameter whose value will be ast.literal_eval'ed</>ParamJson
— A parameter whose value will be parsed as json</>ParamList
— A parameter whose value is a list</>ParamChoice
— A bool parameter whose value is automatically casted into a bool</>ParamNamespace
— A pseudo parameter serving as a namespace for parameters under it</>ParamNamespace
— A pseudo parameter serving as a namespace for parameters under it</>
register_param
(
param
)
— Register a parameter class</>
Classes for completions
The idea is inspired from https://github.com/pallets/click/pull/1622
Some of the code is borrowing there, under following LICENSE:
Copyright 2014 Pallets
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Completer
— Main completion handler</>CompleterParam
— Class for a parameter dealing with completion</>
split_arg_string
(
string
)
(list of str) — Given an argument string this attempts to split it into small parts.</>
Utilities for pyparam
logger
— The logger
always_list
(
str_or_list
,strip
,split
)
(list of str) — Convert a string (comma separated) or a list to a list</>cast_to
(
value
,to_type
)
(any) — Cast a value to a given type</>parse_potential_argument
(
arg
,prefix
,allow_attached
)
(str, str, str) — Parse a potential argument with given prefix</>parse_type
(
typestr
)
(list of str) — Parse the type string</>type_from_value
(
value
)
(str) — Detect parameter type from a value</>
Help assembler for pyparam
THEMES
(dict(str: Theme)) — The theme for the help page.
ProgHighlighter
— Apply style to anything that looks like a program name.</>OptnameHighlighter
— Apply style to anything that looks like a option name.</>OpttypeHighlighter
— Apply style to anything that looks like a option type.</>DefaultHighlighter
— Apply style to anything that looks like default value in option desc.</>HelpSection
— Base class for all help sections.</>HelpSectionPlain
— Plain text section</>HelpSectionUsage
— Usage section in help</>HelpSectionOption
— Options section in help</>HelpAssembler
— Assemble a help page</>