Skip to content

pyparam

package

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

Attributes
  • 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 section
  • POSITIONAL (str) The name of positional parameter
  • TYPE_NAMES (dict(str: str)) The type name mappings to get the type name from aliases Do not modify this variable. It is maintained by pyparam.param.regiest_param

Exceptions used in pyparam

Classes
module

pyparam.param

Definition of a single parameter

Attributes
  • PARAM_MAPPINGS (dict(str: type of Param)) The type to Param mappings, used for params to init a parameter. Managed by register_param
Classes
  • 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</>
Functions

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.

Classes
Functions
  • split_arg_string(string) (list of str) Given an argument string this attempts to split it into small parts.</>
module

pyparam.utils

Utilities for pyparam

Attributes
  • logger The logger
Classes
  • Namespace Subclass of argparse.Namespace</>
  • Codeblock A code block, will be rendered as rich.syntax.Syntax</>
  • RichHandler Subclass of rich.logging.RichHandler, showing log levels as a single character</>
Functions
  • 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</>
module

pyparam.help

Help assembler for pyparam

Attributes
  • THEMES (dict(str: Theme)) The theme for the help page.
Classes
module

pyparam.params

Definition of Params

Classes
  • Params Params, served as root params or subcommands</>