Skip to content

pyparam.param

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
class

pyparam.param.Param(names, default, desc, prefix='auto', show=True, required=False, subtype=None, type_frozen=True, callback=None, complete_callback=None, argname_shorten=True, **kwargs)

Base class for parameter

Parameters
  • names (Union(str, list of str)) The names of the parameter
  • default (any) The default value
  • desc (list of str) The description of the parameter
  • prefix (str, optional) The prefix of the parameter on the command line
  • show (bool, optional) Whether this parameter should show on help page
  • required (bool, optional) Whether this parameter is required
  • subtype (str or bool, optional) The subtype of the parameter if this is a complex type
  • type_frozen (bool, optional) Whether the type is frozen (not allowing overwritting from command line)
  • callback (callable, optional) The callback to modify the final value
  • complete_callback (callable, optional) The callback for complete the values of the parameter
  • argname_shorten (bool, optional) Whether show shortened name for parameters under namespace parameters
  • **kwargs (dict(str: any)) Additional keyword arguments
Attributes
  • _desc (list of str) The raw description of the parameter
  • _kwargs (dict(str: any)) other kwargs
  • _stack (list of any) The stack to push the values
  • _value_cached (any) The cached value calculated from the stack
  • argname_shorten (bool) Whether show shortened name for the parameters under namespace parameters
  • callback (callable) The callback to modify the final value
  • complete_callback (callable) The callback for complete the values of the parameter
  • default The default value
  • default_group Get the default group of the parameter</>
  • desc (list of str) The formatted description using attributes and _kwargs</>
  • desc_with_default If default is not specified in desc, just to add with the default value</>
  • hit (bool) Whether the parameter is just hit
  • is_help (bool) Whether this is a help parameter
  • is_positional Tell if this parameter is positional</>
  • names The names of the parameter
  • ns_param (ParamNamespace) The namespace parameter where this parameter is under
  • prefix (str) The prefix of the parameter on the command line
  • required (bool) Whether this parameter is required
  • show (bool) Whether this parameter should show on help page
  • subtype The subtype of the parameter if this is a complex type
  • type_frozen (bool) Whether the type is frozen (not allowing overwritting from command line)
  • value Return the cached value if possible, otherwise calcuate one</>
Methods
  • apply_callback(all_values) (any) Apply the callback function to the value</>
  • close() Close up the parameter while scanning the command line</>
  • complete_name(current) (iterator of (str, str)) Give the completion name candidates</>
  • complete_value(current, prefix) (Union(str, iterator of (str, ...))) Give the completion candidates</>
  • consume(value) (bool) Consume a value</>
  • copy() (Param) Copy a parameter so that it can be reused.</>
  • full_names() (list of str) make the names with full combinations of namespaces and terminals</>
  • name(which, with_prefix) (str) Get the shortest/longest name of the parameter</>
  • namespaces(index) (Union(list of str, int)) Get the namespaces at the given index or number of namespaces</>
  • namestr(sep, with_prefix) (str) Get all names connected with a separator.</>
  • on_register() Opens opportunity to do something when a parameter is registered</>
  • optstr() (str) Get the string representation of the parameter names and types in the optname section in help page</>
  • overwrite_type(param_type) (Param) Try to overwrite the type</>
  • push(item) Push a value into the stack for calculating</>
  • to(to_type) (Param) Generate a different type of parameter using current settings</>
  • typestr() (str) Get the string representation of the type</>
  • usagestr() (str) Get the string representation of the parameter in the default usage constructor</>
method

complete_value(current, prefix='')

Give the completion candidates

Parameters
  • current (str) Current prefix
Returns (Union(str, iterator of (str, ...)))

None when there are no candidates, nor should we have next paramters/commands as candidates (requiring a value). An empty string if we should put next parameters/commands as candidates. Otherwise yields The candidates should be either 1-, 2-, or 3-element tuple. If 1-element, type plain and no description implied. If 2-element, type plain and 2nd element should be description. If 3-element, 2nd element the type, 3rd the description.

generator

complete_name(current)

Give the completion name candidates

Parameters
  • current (str) The current prefix or word under cursor
Returns (iterator of (str, str))

An iterator of a tuple including the prefixed name and description.

classmethod

on_register()

Opens opportunity to do something when a parameter is registered

method

namespaces(index='len')

Get the namespaces at the given index or number of namespaces

Parameters
  • index (int or str, optional) The index or a length indicator
Returns (Union(list of str, int))

The length of the namespaces or the namespaces at index.

method

full_names()

make the names with full combinations of namespaces and terminals

Since one can define a parameter like n.arg but namespace n can have aliases (i.e. ns). This makes sure the names of n.arg expands to n.arg and ns.arg

Returns (list of str)

The names with full combinations of namespaces and terminals

method

close()

Close up the parameter while scanning the command line

We are mostly doing nothing, only if, say, param is bool and it was just hit, we should push a true value to it.

method

overwrite_type(param_type)

Try to overwrite the type

Only when param_type is not None and it's different from mine A new param will be returned if different

Parameters
  • param_type (str) The type to overwrite
Returns (Param)

Self when type not changed otherwise a new parameter with the given type

method

consume(value)

Consume a value

Parameters
  • Value value to consume
Returns (bool)

True if value was consumed, otherwise False

method

name(which, with_prefix=True)

Get the shortest/longest name of the parameter

A name is ensured to be returned. It does not mean it is the real short/long name, but just the shortest/longest name among all the names

Parameters
  • which (str) Whether get the shortest or longest name Could use short or long for short.
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

The shortest/longest name of the parameter

method

namestr(sep=', ', with_prefix=True)

Get all names connected with a separator.

Parameters
  • sep (str, optional) The separator to connect the names
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

the connected names

method

typestr()

Get the string representation of the type

Returns (str)

the string representation of the type

method

usagestr()

Get the string representation of the parameter in the default usage constructor

Returns (str)

the string representation of the parameter in the default usage

method

optstr()

Get the string representation of the parameter names and types in the optname section in help page

Returns (str)

the string representation of the parameter names and types in the optname section in help page

method

to(to_type)

Generate a different type of parameter using current settings

Parameters
  • to_type (str) the type of parameter to generate
Returns (Param)

the generated parameter with different type

method

copy()

Copy a parameter so that it can be reused.

Returns (Param)

The copy of the parameter

method

push(item)

Push a value into the stack for calculating

Returns

The item to be pushed

method

apply_callback(all_values)

Apply the callback function to the value

Parameters
  • all_values (Namespace) The namespace of values of all parameters
Returns (any)

The value after the callback applied

Raises
  • PyParamTypeError When exceptions raised or returned from callback
class

pyparam.param.ParamAuto(names, default, desc, prefix='auto', show=True, required=False, subtype=None, type_frozen=True, callback=None, complete_callback=None, argname_shorten=True, **kwargs)

An auto parameter whose value is automatically casted

Parameters
  • names (Union(str, list of str)) The names of the parameter
  • default (any) The default value
  • desc (list of str) The description of the parameter
  • prefix (str, optional) The prefix of the parameter on the command line
  • show (bool, optional) Whether this parameter should show on help page
  • required (bool, optional) Whether this parameter is required
  • subtype (str or bool, optional) The subtype of the parameter if this is a complex type
  • type_frozen (bool, optional) Whether the type is frozen (not allowing overwritting from command line)
  • callback (callable, optional) The callback to modify the final value
  • complete_callback (callable, optional) The callback for complete the values of the parameter
  • argname_shorten (bool, optional) Whether show shortened name for parameters under namespace parameters
  • **kwargs (dict(str: any)) Additional keyword arguments
Attributes
  • _desc (list of str) The raw description of the parameter
  • _kwargs (dict(str: any)) other kwargs
  • _stack (list of any) The stack to push the values
  • _value_cached (any) The cached value calculated from the stack
  • argname_shorten (bool) Whether show shortened name for the parameters under namespace parameters
  • callback (callable) The callback to modify the final value
  • complete_callback (callable) The callback for complete the values of the parameter
  • default The default value
  • default_group Get the default group of the parameter</>
  • desc (list of str) The formatted description using attributes and _kwargs</>
  • desc_with_default If default is not specified in desc, just to add with the default value</>
  • hit (bool) Whether the parameter is just hit
  • is_help (bool) Whether this is a help parameter
  • is_positional Tell if this parameter is positional</>
  • names The names of the parameter
  • ns_param (ParamNamespace) The namespace parameter where this parameter is under
  • prefix (str) The prefix of the parameter on the command line
  • required (bool) Whether this parameter is required
  • show (bool) Whether this parameter should show on help page
  • subtype The subtype of the parameter if this is a complex type
  • type_frozen (bool) Whether the type is frozen (not allowing overwritting from command line)
  • value Return the cached value if possible, otherwise calcuate one</>
Methods
  • apply_callback(all_values) (any) Apply the callback function to the value</>
  • close() Close up the parameter while scanning the command line</>
  • complete_name(current) (iterator of (str, str)) Give the completion name candidates</>
  • complete_value(current, prefix) (Union(str, iterator of (str, ...))) Give the completion candidates</>
  • consume(value) (bool) Consume a value</>
  • copy() (Param) Copy a parameter so that it can be reused.</>
  • full_names() (list of str) make the names with full combinations of namespaces and terminals</>
  • name(which, with_prefix) (str) Get the shortest/longest name of the parameter</>
  • namespaces(index) (Union(list of str, int)) Get the namespaces at the given index or number of namespaces</>
  • namestr(sep, with_prefix) (str) Get all names connected with a separator.</>
  • on_register() Opens opportunity to do something when a parameter is registered</>
  • optstr() (str) Get the string representation of the parameter names and types in the optname section in help page</>
  • overwrite_type(param_type) (Param) Try to overwrite the type</>
  • push(item) Push a value into the stack for calculating</>
  • to(to_type) (Param) Generate a different type of parameter using current settings</>
  • typestr() (str) Get the string representation of the type</>
  • usagestr() (str) Get the string representation of the parameter in the default usage constructor</>
method

complete_value(current, prefix='')

Give the completion candidates

Parameters
  • current (str) Current prefix
Returns (Union(str, iterator of (str, ...)))

None when there are no candidates, nor should we have next paramters/commands as candidates (requiring a value). An empty string if we should put next parameters/commands as candidates. Otherwise yields The candidates should be either 1-, 2-, or 3-element tuple. If 1-element, type plain and no description implied. If 2-element, type plain and 2nd element should be description. If 3-element, 2nd element the type, 3rd the description.

generator

complete_name(current)

Give the completion name candidates

Parameters
  • current (str) The current prefix or word under cursor
Returns (iterator of (str, str))

An iterator of a tuple including the prefixed name and description.

classmethod

on_register()

Opens opportunity to do something when a parameter is registered

method

namespaces(index='len')

Get the namespaces at the given index or number of namespaces

Parameters
  • index (int or str, optional) The index or a length indicator
Returns (Union(list of str, int))

The length of the namespaces or the namespaces at index.

method

full_names()

make the names with full combinations of namespaces and terminals

Since one can define a parameter like n.arg but namespace n can have aliases (i.e. ns). This makes sure the names of n.arg expands to n.arg and ns.arg

Returns (list of str)

The names with full combinations of namespaces and terminals

method

close()

Close up the parameter while scanning the command line

We are mostly doing nothing, only if, say, param is bool and it was just hit, we should push a true value to it.

method

overwrite_type(param_type)

Try to overwrite the type

Only when param_type is not None and it's different from mine A new param will be returned if different

Parameters
  • param_type (str) The type to overwrite
Returns (Param)

Self when type not changed otherwise a new parameter with the given type

method

consume(value)

Consume a value

Returns (bool)

True if value was consumed, otherwise False

method

name(which, with_prefix=True)

Get the shortest/longest name of the parameter

A name is ensured to be returned. It does not mean it is the real short/long name, but just the shortest/longest name among all the names

Parameters
  • which (str) Whether get the shortest or longest name Could use short or long for short.
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

The shortest/longest name of the parameter

method

namestr(sep=', ', with_prefix=True)

Get all names connected with a separator.

Parameters
  • sep (str, optional) The separator to connect the names
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

the connected names

method

typestr()

Get the string representation of the type

Returns (str)

the string representation of the type

method

usagestr()

Get the string representation of the parameter in the default usage constructor

Returns (str)

the string representation of the parameter in the default usage

method

optstr()

Get the string representation of the parameter names and types in the optname section in help page

Returns (str)

the string representation of the parameter names and types in the optname section in help page

method

to(to_type)

Generate a different type of parameter using current settings

Parameters
  • to_type (str) the type of parameter to generate
Returns (Param)

the generated parameter with different type

method

copy()

Copy a parameter so that it can be reused.

Returns (Param)

The copy of the parameter

method

push(item)

Push a value into the stack for calculating

Returns

The item to be pushed

method

apply_callback(all_values)

Apply the callback function to the value

Parameters
  • all_values (Namespace) The namespace of values of all parameters
Returns (any)

The value after the callback applied

Raises
  • PyParamTypeError When exceptions raised or returned from callback
class

pyparam.param.ParamInt(*args, **kwargs)

An int parameter whose value is automatically casted into an int

Parameters
  • **kwargs (dict(str: any)) Additional keyword arguments
Attributes
  • _desc (list of str) The raw description of the parameter
  • _kwargs (dict(str: any)) other kwargs
  • _stack (list of any) The stack to push the values
  • _value_cached (any) The cached value calculated from the stack
  • argname_shorten (bool) Whether show shortened name for the parameters under namespace parameters
  • callback (callable) The callback to modify the final value
  • complete_callback (callable) The callback for complete the values of the parameter
  • default The default value
  • default_group Get the default group of the parameter</>
  • desc (list of str) The formatted description using attributes and _kwargs</>
  • desc_with_default If default is not specified in desc, just to add with the default value</>
  • hit (bool) Whether the parameter is just hit
  • is_help (bool) Whether this is a help parameter
  • is_positional Tell if this parameter is positional</>
  • names The names of the parameter
  • ns_param (ParamNamespace) The namespace parameter where this parameter is under
  • prefix (str) The prefix of the parameter on the command line
  • required (bool) Whether this parameter is required
  • show (bool) Whether this parameter should show on help page
  • subtype The subtype of the parameter if this is a complex type
  • type_frozen (bool) Whether the type is frozen (not allowing overwritting from command line)
  • value Return the cached value if possible, otherwise calcuate one</>
Methods
  • apply_callback(all_values) (any) Apply the callback function to the value</>
  • close() Close up the parameter while scanning the command line</>
  • complete_name(current) (iterator of (str, str)) Give the completion name candidates</>
  • complete_value(current, prefix) (Union(str, iterator of (str, ...))) Give the completion candidates</>
  • consume(value) (bool) Consume a value</>
  • copy() (Param) Copy a parameter so that it can be reused.</>
  • full_names() (list of str) make the names with full combinations of namespaces and terminals</>
  • name(which, with_prefix) (str) Get the shortest/longest name of the parameter</>
  • namespaces(index) (Union(list of str, int)) Get the namespaces at the given index or number of namespaces</>
  • namestr(sep, with_prefix) (str) Get all names connected with a separator.</>
  • on_register() Opens opportunity to do something when a parameter is registered</>
  • optstr() (str) Get the string representation of the parameter names and types in the optname section in help page</>
  • overwrite_type(param_type) (Param) Try to overwrite the type</>
  • push(item) Push a value into the stack for calculating</>
  • to(to_type) (Param) Generate a different type of parameter using current settings</>
  • typestr() (str) Get the string representation of the type</>
  • usagestr() (str) Get the string representation of the parameter in the default usage constructor</>
method

complete_value(current, prefix='')

Give the completion candidates

Parameters
  • current (str) Current prefix
Returns (Union(str, iterator of (str, ...)))

None when there are no candidates, nor should we have next paramters/commands as candidates (requiring a value). An empty string if we should put next parameters/commands as candidates. Otherwise yields The candidates should be either 1-, 2-, or 3-element tuple. If 1-element, type plain and no description implied. If 2-element, type plain and 2nd element should be description. If 3-element, 2nd element the type, 3rd the description.

generator

complete_name(current)

Give the completion name candidates

Parameters
  • current (str) The current prefix or word under cursor
Returns (iterator of (str, str))

An iterator of a tuple including the prefixed name and description.

classmethod

on_register()

Opens opportunity to do something when a parameter is registered

method

namespaces(index='len')

Get the namespaces at the given index or number of namespaces

Parameters
  • index (int or str, optional) The index or a length indicator
Returns (Union(list of str, int))

The length of the namespaces or the namespaces at index.

method

full_names()

make the names with full combinations of namespaces and terminals

Since one can define a parameter like n.arg but namespace n can have aliases (i.e. ns). This makes sure the names of n.arg expands to n.arg and ns.arg

Returns (list of str)

The names with full combinations of namespaces and terminals

method

close()

Close up the parameter while scanning the command line

We are mostly doing nothing, only if, say, param is bool and it was just hit, we should push a true value to it.

method

overwrite_type(param_type)

Try to overwrite the type

Only when param_type is not None and it's different from mine A new param will be returned if different

Parameters
  • param_type (str) The type to overwrite
Returns (Param)

Self when type not changed otherwise a new parameter with the given type

method

consume(value)

Consume a value

Returns (bool)

True if value was consumed, otherwise False

method

name(which, with_prefix=True)

Get the shortest/longest name of the parameter

A name is ensured to be returned. It does not mean it is the real short/long name, but just the shortest/longest name among all the names

Parameters
  • which (str) Whether get the shortest or longest name Could use short or long for short.
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

The shortest/longest name of the parameter

method

namestr(sep=', ', with_prefix=True)

Get all names connected with a separator.

Parameters
  • sep (str, optional) The separator to connect the names
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

the connected names

method

typestr()

Get the string representation of the type

Returns (str)

the string representation of the type

method

usagestr()

Get the string representation of the parameter in the default usage constructor

Returns (str)

the string representation of the parameter in the default usage

method

optstr()

Get the string representation of the parameter names and types in the optname section in help page

Returns (str)

the string representation of the parameter names and types in the optname section in help page

method

to(to_type)

Generate a different type of parameter using current settings

Parameters
  • to_type (str) the type of parameter to generate
Returns (Param)

the generated parameter with different type

method

copy()

Copy a parameter so that it can be reused.

Returns (Param)

The copy of the parameter

method

push(item)

Push a value into the stack for calculating

Returns

The item to be pushed

method

apply_callback(all_values)

Apply the callback function to the value

Parameters
  • all_values (Namespace) The namespace of values of all parameters
Returns (any)

The value after the callback applied

Raises
  • PyParamTypeError When exceptions raised or returned from callback
class

pyparam.param.ParamFloat(*args, **kwargs)

A float parameter whose value is automatically casted into a float

Parameters
  • **kwargs (dict(str: any)) Additional keyword arguments
Attributes
  • _desc (list of str) The raw description of the parameter
  • _kwargs (dict(str: any)) other kwargs
  • _stack (list of any) The stack to push the values
  • _value_cached (any) The cached value calculated from the stack
  • argname_shorten (bool) Whether show shortened name for the parameters under namespace parameters
  • callback (callable) The callback to modify the final value
  • complete_callback (callable) The callback for complete the values of the parameter
  • default The default value
  • default_group Get the default group of the parameter</>
  • desc (list of str) The formatted description using attributes and _kwargs</>
  • desc_with_default If default is not specified in desc, just to add with the default value</>
  • hit (bool) Whether the parameter is just hit
  • is_help (bool) Whether this is a help parameter
  • is_positional Tell if this parameter is positional</>
  • names The names of the parameter
  • ns_param (ParamNamespace) The namespace parameter where this parameter is under
  • prefix (str) The prefix of the parameter on the command line
  • required (bool) Whether this parameter is required
  • show (bool) Whether this parameter should show on help page
  • subtype The subtype of the parameter if this is a complex type
  • type_frozen (bool) Whether the type is frozen (not allowing overwritting from command line)
  • value Return the cached value if possible, otherwise calcuate one</>
Methods
  • apply_callback(all_values) (any) Apply the callback function to the value</>
  • close() Close up the parameter while scanning the command line</>
  • complete_name(current) (iterator of (str, str)) Give the completion name candidates</>
  • complete_value(current, prefix) (Union(str, iterator of (str, ...))) Give the completion candidates</>
  • consume(value) (bool) Consume a value</>
  • copy() (Param) Copy a parameter so that it can be reused.</>
  • full_names() (list of str) make the names with full combinations of namespaces and terminals</>
  • name(which, with_prefix) (str) Get the shortest/longest name of the parameter</>
  • namespaces(index) (Union(list of str, int)) Get the namespaces at the given index or number of namespaces</>
  • namestr(sep, with_prefix) (str) Get all names connected with a separator.</>
  • on_register() Opens opportunity to do something when a parameter is registered</>
  • optstr() (str) Get the string representation of the parameter names and types in the optname section in help page</>
  • overwrite_type(param_type) (Param) Try to overwrite the type</>
  • push(item) Push a value into the stack for calculating</>
  • to(to_type) (Param) Generate a different type of parameter using current settings</>
  • typestr() (str) Get the string representation of the type</>
  • usagestr() (str) Get the string representation of the parameter in the default usage constructor</>
method

complete_value(current, prefix='')

Give the completion candidates

Parameters
  • current (str) Current prefix
Returns (Union(str, iterator of (str, ...)))

None when there are no candidates, nor should we have next paramters/commands as candidates (requiring a value). An empty string if we should put next parameters/commands as candidates. Otherwise yields The candidates should be either 1-, 2-, or 3-element tuple. If 1-element, type plain and no description implied. If 2-element, type plain and 2nd element should be description. If 3-element, 2nd element the type, 3rd the description.

generator

complete_name(current)

Give the completion name candidates

Parameters
  • current (str) The current prefix or word under cursor
Returns (iterator of (str, str))

An iterator of a tuple including the prefixed name and description.

classmethod

on_register()

Opens opportunity to do something when a parameter is registered

method

namespaces(index='len')

Get the namespaces at the given index or number of namespaces

Parameters
  • index (int or str, optional) The index or a length indicator
Returns (Union(list of str, int))

The length of the namespaces or the namespaces at index.

method

full_names()

make the names with full combinations of namespaces and terminals

Since one can define a parameter like n.arg but namespace n can have aliases (i.e. ns). This makes sure the names of n.arg expands to n.arg and ns.arg

Returns (list of str)

The names with full combinations of namespaces and terminals

method

close()

Close up the parameter while scanning the command line

We are mostly doing nothing, only if, say, param is bool and it was just hit, we should push a true value to it.

method

overwrite_type(param_type)

Try to overwrite the type

Only when param_type is not None and it's different from mine A new param will be returned if different

Parameters
  • param_type (str) The type to overwrite
Returns (Param)

Self when type not changed otherwise a new parameter with the given type

method

consume(value)

Consume a value

Returns (bool)

True if value was consumed, otherwise False

method

name(which, with_prefix=True)

Get the shortest/longest name of the parameter

A name is ensured to be returned. It does not mean it is the real short/long name, but just the shortest/longest name among all the names

Parameters
  • which (str) Whether get the shortest or longest name Could use short or long for short.
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

The shortest/longest name of the parameter

method

namestr(sep=', ', with_prefix=True)

Get all names connected with a separator.

Parameters
  • sep (str, optional) The separator to connect the names
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

the connected names

method

typestr()

Get the string representation of the type

Returns (str)

the string representation of the type

method

usagestr()

Get the string representation of the parameter in the default usage constructor

Returns (str)

the string representation of the parameter in the default usage

method

optstr()

Get the string representation of the parameter names and types in the optname section in help page

Returns (str)

the string representation of the parameter names and types in the optname section in help page

method

to(to_type)

Generate a different type of parameter using current settings

Parameters
  • to_type (str) the type of parameter to generate
Returns (Param)

the generated parameter with different type

method

copy()

Copy a parameter so that it can be reused.

Returns (Param)

The copy of the parameter

method

push(item)

Push a value into the stack for calculating

Returns

The item to be pushed

method

apply_callback(all_values)

Apply the callback function to the value

Parameters
  • all_values (Namespace) The namespace of values of all parameters
Returns (any)

The value after the callback applied

Raises
  • PyParamTypeError When exceptions raised or returned from callback
class

pyparam.param.ParamStr(*args, **kwargs)

A str parameter whose value is automatically casted into a str

Parameters
  • **kwargs (dict(str: any)) Additional keyword arguments
Attributes
  • _desc (list of str) The raw description of the parameter
  • _kwargs (dict(str: any)) other kwargs
  • _stack (list of any) The stack to push the values
  • _value_cached (any) The cached value calculated from the stack
  • argname_shorten (bool) Whether show shortened name for the parameters under namespace parameters
  • callback (callable) The callback to modify the final value
  • complete_callback (callable) The callback for complete the values of the parameter
  • default The default value
  • default_group Get the default group of the parameter</>
  • desc (list of str) The formatted description using attributes and _kwargs</>
  • desc_with_default If default is not specified in desc, just to add with the default value</>
  • hit (bool) Whether the parameter is just hit
  • is_help (bool) Whether this is a help parameter
  • is_positional Tell if this parameter is positional</>
  • names The names of the parameter
  • ns_param (ParamNamespace) The namespace parameter where this parameter is under
  • prefix (str) The prefix of the parameter on the command line
  • required (bool) Whether this parameter is required
  • show (bool) Whether this parameter should show on help page
  • subtype The subtype of the parameter if this is a complex type
  • type_frozen (bool) Whether the type is frozen (not allowing overwritting from command line)
  • value Return the cached value if possible, otherwise calcuate one</>
Methods
  • apply_callback(all_values) (any) Apply the callback function to the value</>
  • close() Close up the parameter while scanning the command line</>
  • complete_name(current) (iterator of (str, str)) Give the completion name candidates</>
  • complete_value(current, prefix) (Union(str, iterator of (str, ...))) Give the completion candidates</>
  • consume(value) (bool) Consume a value</>
  • copy() (Param) Copy a parameter so that it can be reused.</>
  • full_names() (list of str) make the names with full combinations of namespaces and terminals</>
  • name(which, with_prefix) (str) Get the shortest/longest name of the parameter</>
  • namespaces(index) (Union(list of str, int)) Get the namespaces at the given index or number of namespaces</>
  • namestr(sep, with_prefix) (str) Get all names connected with a separator.</>
  • on_register() Opens opportunity to do something when a parameter is registered</>
  • optstr() (str) Get the string representation of the parameter names and types in the optname section in help page</>
  • overwrite_type(param_type) (Param) Try to overwrite the type</>
  • push(item) Push a value into the stack for calculating</>
  • to(to_type) (Param) Generate a different type of parameter using current settings</>
  • typestr() (str) Get the string representation of the type</>
  • usagestr() (str) Get the string representation of the parameter in the default usage constructor</>
method

complete_value(current, prefix='')

Give the completion candidates

Parameters
  • current (str) Current prefix
Returns (Union(str, iterator of (str, ...)))

None when there are no candidates, nor should we have next paramters/commands as candidates (requiring a value). An empty string if we should put next parameters/commands as candidates. Otherwise yields The candidates should be either 1-, 2-, or 3-element tuple. If 1-element, type plain and no description implied. If 2-element, type plain and 2nd element should be description. If 3-element, 2nd element the type, 3rd the description.

generator

complete_name(current)

Give the completion name candidates

Parameters
  • current (str) The current prefix or word under cursor
Returns (iterator of (str, str))

An iterator of a tuple including the prefixed name and description.

classmethod

on_register()

Opens opportunity to do something when a parameter is registered

method

namespaces(index='len')

Get the namespaces at the given index or number of namespaces

Parameters
  • index (int or str, optional) The index or a length indicator
Returns (Union(list of str, int))

The length of the namespaces or the namespaces at index.

method

full_names()

make the names with full combinations of namespaces and terminals

Since one can define a parameter like n.arg but namespace n can have aliases (i.e. ns). This makes sure the names of n.arg expands to n.arg and ns.arg

Returns (list of str)

The names with full combinations of namespaces and terminals

method

close()

Close up the parameter while scanning the command line

We are mostly doing nothing, only if, say, param is bool and it was just hit, we should push a true value to it.

method

overwrite_type(param_type)

Try to overwrite the type

Only when param_type is not None and it's different from mine A new param will be returned if different

Parameters
  • param_type (str) The type to overwrite
Returns (Param)

Self when type not changed otherwise a new parameter with the given type

method

consume(value)

Consume a value

Returns (bool)

True if value was consumed, otherwise False

method

name(which, with_prefix=True)

Get the shortest/longest name of the parameter

A name is ensured to be returned. It does not mean it is the real short/long name, but just the shortest/longest name among all the names

Parameters
  • which (str) Whether get the shortest or longest name Could use short or long for short.
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

The shortest/longest name of the parameter

method

namestr(sep=', ', with_prefix=True)

Get all names connected with a separator.

Parameters
  • sep (str, optional) The separator to connect the names
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

the connected names

method

typestr()

Get the string representation of the type

Returns (str)

the string representation of the type

method

usagestr()

Get the string representation of the parameter in the default usage constructor

Returns (str)

the string representation of the parameter in the default usage

method

optstr()

Get the string representation of the parameter names and types in the optname section in help page

Returns (str)

the string representation of the parameter names and types in the optname section in help page

method

to(to_type)

Generate a different type of parameter using current settings

Parameters
  • to_type (str) the type of parameter to generate
Returns (Param)

the generated parameter with different type

method

copy()

Copy a parameter so that it can be reused.

Returns (Param)

The copy of the parameter

method

push(item)

Push a value into the stack for calculating

Returns

The item to be pushed

method

apply_callback(all_values)

Apply the callback function to the value

Parameters
  • all_values (Namespace) The namespace of values of all parameters
Returns (any)

The value after the callback applied

Raises
  • PyParamTypeError When exceptions raised or returned from callback
class

pyparam.param.ParamBool(*args, **kwargs)

A bool parameter whose value is automatically casted into a bool

Parameters
  • **kwargs (dict(str: any)) Additional keyword arguments
Attributes
  • _desc (list of str) The raw description of the parameter
  • _kwargs (dict(str: any)) other kwargs
  • _stack (list of any) The stack to push the values
  • _value_cached (any) The cached value calculated from the stack
  • argname_shorten (bool) Whether show shortened name for the parameters under namespace parameters
  • callback (callable) The callback to modify the final value
  • complete_callback (callable) The callback for complete the values of the parameter
  • default The default value
  • default_group Get the default group of the parameter</>
  • desc (list of str) The formatted description using attributes and _kwargs</>
  • desc_with_default If default is not specified in desc, just to add with the default value</>
  • hit (bool) Whether the parameter is just hit
  • is_help (bool) Whether this is a help parameter
  • is_positional Tell if this parameter is positional</>
  • names The names of the parameter
  • ns_param (ParamNamespace) The namespace parameter where this parameter is under
  • prefix (str) The prefix of the parameter on the command line
  • required (bool) Whether this parameter is required
  • show (bool) Whether this parameter should show on help page
  • subtype The subtype of the parameter if this is a complex type
  • type_frozen (bool) Whether the type is frozen (not allowing overwritting from command line)
  • value Return the cached value if possible, otherwise calcuate one</>
Methods
  • apply_callback(all_values) (any) Apply the callback function to the value</>
  • close() Close up the parameter while scanning the command line</>
  • complete_name(current) (iterator of (str, str)) Give the completion name candidates</>
  • complete_value(current, prefix) (Union(str, iterator of (str), iterator of (str, str), iterator of (str, str, str))) Get the completion candidates for the current parameter</>
  • consume(value) (bool) Should I consume given value?</>
  • copy() (Param) Copy a parameter so that it can be reused.</>
  • full_names() (list of str) make the names with full combinations of namespaces and terminals</>
  • name(which, with_prefix) (str) Get the shortest/longest name of the parameter</>
  • namespaces(index) (Union(list of str, int)) Get the namespaces at the given index or number of namespaces</>
  • namestr(sep, with_prefix) (str) Get all names connected with a separator.</>
  • on_register() Opens opportunity to do something when a parameter is registered</>
  • optstr() (str) Get the string representation of the parameter names and types in the optname section in help page</>
  • overwrite_type(param_type) (Param) Try to overwrite the type</>
  • push(item) Push a value into the stack for calculating</>
  • to(to_type) (Param) Generate a different type of parameter using current settings</>
  • typestr() (str) Get the string representation of the type</>
  • usagestr() (str) Get the string representation of the parameter in the default usage constructor</>
generator

complete_name(current)

Give the completion name candidates

Parameters
  • current (str) The current prefix or word under cursor
Returns (iterator of (str, str))

An iterator of a tuple including the prefixed name and description.

classmethod

on_register()

Opens opportunity to do something when a parameter is registered

method

namespaces(index='len')

Get the namespaces at the given index or number of namespaces

Parameters
  • index (int or str, optional) The index or a length indicator
Returns (Union(list of str, int))

The length of the namespaces or the namespaces at index.

method

full_names()

make the names with full combinations of namespaces and terminals

Since one can define a parameter like n.arg but namespace n can have aliases (i.e. ns). This makes sure the names of n.arg expands to n.arg and ns.arg

Returns (list of str)

The names with full combinations of namespaces and terminals

method

overwrite_type(param_type)

Try to overwrite the type

Only when param_type is not None and it's different from mine A new param will be returned if different

Parameters
  • param_type (str) The type to overwrite
Returns (Param)

Self when type not changed otherwise a new parameter with the given type

method

name(which, with_prefix=True)

Get the shortest/longest name of the parameter

A name is ensured to be returned. It does not mean it is the real short/long name, but just the shortest/longest name among all the names

Parameters
  • which (str) Whether get the shortest or longest name Could use short or long for short.
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

The shortest/longest name of the parameter

method

namestr(sep=', ', with_prefix=True)

Get all names connected with a separator.

Parameters
  • sep (str, optional) The separator to connect the names
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

the connected names

method

typestr()

Get the string representation of the type

Returns (str)

the string representation of the type

method

to(to_type)

Generate a different type of parameter using current settings

Parameters
  • to_type (str) the type of parameter to generate
Returns (Param)

the generated parameter with different type

method

copy()

Copy a parameter so that it can be reused.

Returns (Param)

The copy of the parameter

method

push(item)

Push a value into the stack for calculating

Returns

The item to be pushed

method

apply_callback(all_values)

Apply the callback function to the value

Parameters
  • all_values (Namespace) The namespace of values of all parameters
Returns (any)

The value after the callback applied

Raises
  • PyParamTypeError When exceptions raised or returned from callback
method

usagestr()

Get the string representation of the parameter in the default usage constructor

Returns (str)

the string representation of the parameter in the default usage

method

optstr()

Get the string representation of the parameter names and types in the optname section in help page

Returns (str)

the string representation of the parameter names and types in the optname section in help page

method

close()

Close up the parameter while scanning the command line

We are mostly doing nothing, only if, say, param is bool and it was just hit, we should push a true value to it.

method

consume(value) → bool

Should I consume given value?

method

complete_value(current, prefix='') → Union(str, iterator of (str), iterator of (str, str), iterator of (str, str, str))

Get the completion candidates for the current parameter

Parameters
  • current (str) Current prefix
class

pyparam.param.ParamCount(*args, **kwargs)

A bool parameter whose value is automatically casted into a bool

Parameters
  • **kwargs (dict(str: any)) Additional keyword arguments
Attributes
  • _desc (list of str) The raw description of the parameter
  • _kwargs (dict(str: any)) other kwargs
  • _stack (list of any) The stack to push the values
  • _value_cached (any) The cached value calculated from the stack
  • argname_shorten (bool) Whether show shortened name for the parameters under namespace parameters
  • callback (callable) The callback to modify the final value
  • complete_callback (callable) The callback for complete the values of the parameter
  • default The default value
  • default_group Get the default group of the parameter</>
  • desc (list of str) The formatted description using attributes and _kwargs</>
  • desc_with_default If default is not specified in desc, just to add with the default value</>
  • hit (bool) Whether the parameter is just hit
  • is_help (bool) Whether this is a help parameter
  • is_positional Tell if this parameter is positional</>
  • names The names of the parameter
  • ns_param (ParamNamespace) The namespace parameter where this parameter is under
  • prefix (str) The prefix of the parameter on the command line
  • required (bool) Whether this parameter is required
  • show (bool) Whether this parameter should show on help page
  • subtype The subtype of the parameter if this is a complex type
  • type_frozen (bool) Whether the type is frozen (not allowing overwritting from command line)
  • value Return the cached value if possible, otherwise calcuate one</>
Methods
  • apply_callback(all_values) (any) Apply the callback function to the value</>
  • close() Close up the parameter while scanning the command line</>
  • complete_name(current) (str, str) Complete names for a count parameter</>
  • complete_value(current, prefix) (Union(str, iterator of (str, ...))) Give the completion candidates</>
  • consume(value) (bool) Should I consume given parameter?</>
  • copy() (Param) Copy a parameter so that it can be reused.</>
  • full_names() (list of str) make the names with full combinations of namespaces and terminals</>
  • name(which, with_prefix) (str) Get the shortest/longest name of the parameter</>
  • namespaces(index) (Union(list of str, int)) Get the namespaces at the given index or number of namespaces</>
  • namestr(sep, with_prefix) (str) Get all names connected with a separator.</>
  • on_register() Opens opportunity to do something when a parameter is registered</>
  • optstr() (str) Get the string representation of the parameter names and types in the optname section in help page</>
  • overwrite_type(param_type) (Param) Try to overwrite the type</>
  • push(item) Push a value into the stack for calculating</>
  • to(to_type) (Param) Generate a different type of parameter using current settings</>
  • typestr() (str) Get the string representation of the type</>
  • usagestr() (str) Get the string representation of the parameter in the default usage constructor</>
method

complete_value(current, prefix='')

Give the completion candidates

Parameters
  • current (str) Current prefix
Returns (Union(str, iterator of (str, ...)))

None when there are no candidates, nor should we have next paramters/commands as candidates (requiring a value). An empty string if we should put next parameters/commands as candidates. Otherwise yields The candidates should be either 1-, 2-, or 3-element tuple. If 1-element, type plain and no description implied. If 2-element, type plain and 2nd element should be description. If 3-element, 2nd element the type, 3rd the description.

classmethod

on_register()

Opens opportunity to do something when a parameter is registered

method

namespaces(index='len')

Get the namespaces at the given index or number of namespaces

Parameters
  • index (int or str, optional) The index or a length indicator
Returns (Union(list of str, int))

The length of the namespaces or the namespaces at index.

method

full_names()

make the names with full combinations of namespaces and terminals

Since one can define a parameter like n.arg but namespace n can have aliases (i.e. ns). This makes sure the names of n.arg expands to n.arg and ns.arg

Returns (list of str)

The names with full combinations of namespaces and terminals

method

overwrite_type(param_type)

Try to overwrite the type

Only when param_type is not None and it's different from mine A new param will be returned if different

Parameters
  • param_type (str) The type to overwrite
Returns (Param)

Self when type not changed otherwise a new parameter with the given type

method

name(which, with_prefix=True)

Get the shortest/longest name of the parameter

A name is ensured to be returned. It does not mean it is the real short/long name, but just the shortest/longest name among all the names

Parameters
  • which (str) Whether get the shortest or longest name Could use short or long for short.
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

The shortest/longest name of the parameter

method

namestr(sep=', ', with_prefix=True)

Get all names connected with a separator.

Parameters
  • sep (str, optional) The separator to connect the names
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

the connected names

method

typestr()

Get the string representation of the type

Returns (str)

the string representation of the type

method

usagestr()

Get the string representation of the parameter in the default usage constructor

Returns (str)

the string representation of the parameter in the default usage

method

optstr()

Get the string representation of the parameter names and types in the optname section in help page

Returns (str)

the string representation of the parameter names and types in the optname section in help page

method

to(to_type)

Generate a different type of parameter using current settings

Parameters
  • to_type (str) the type of parameter to generate
Returns (Param)

the generated parameter with different type

method

copy()

Copy a parameter so that it can be reused.

Returns (Param)

The copy of the parameter

method

push(item)

Push a value into the stack for calculating

Returns

The item to be pushed

method

apply_callback(all_values)

Apply the callback function to the value

Parameters
  • all_values (Namespace) The namespace of values of all parameters
Returns (any)

The value after the callback applied

Raises
  • PyParamTypeError When exceptions raised or returned from callback
method

close()

Close up the parameter while scanning the command line

We are mostly doing nothing, only if, say, param is bool and it was just hit, we should push a true value to it.

method

consume(value) → bool

Should I consume given parameter?

generator

complete_name(current) → (str, str)

Complete names for a count parameter

Since we have -v, -vv, -vvv allowed for a count parameter, we need to put them in the completions, too.

Parameters
  • current (str) The current prefix or word under cursor
class

pyparam.param.ParamPath(names, default, desc, prefix='auto', show=True, required=False, subtype=None, type_frozen=True, callback=None, complete_callback=None, argname_shorten=True, **kwargs)

A path parameter whose value is automatically casted into a pathlib.Path

Parameters
  • names (Union(str, list of str)) The names of the parameter
  • default (any) The default value
  • desc (list of str) The description of the parameter
  • prefix (str, optional) The prefix of the parameter on the command line
  • show (bool, optional) Whether this parameter should show on help page
  • required (bool, optional) Whether this parameter is required
  • subtype (str or bool, optional) The subtype of the parameter if this is a complex type
  • type_frozen (bool, optional) Whether the type is frozen (not allowing overwritting from command line)
  • callback (callable, optional) The callback to modify the final value
  • complete_callback (callable, optional) The callback for complete the values of the parameter
  • argname_shorten (bool, optional) Whether show shortened name for parameters under namespace parameters
  • **kwargs (dict(str: any)) Additional keyword arguments
Attributes
  • _desc (list of str) The raw description of the parameter
  • _kwargs (dict(str: any)) other kwargs
  • _stack (list of any) The stack to push the values
  • _value_cached (any) The cached value calculated from the stack
  • argname_shorten (bool) Whether show shortened name for the parameters under namespace parameters
  • callback (callable) The callback to modify the final value
  • complete_callback (callable) The callback for complete the values of the parameter
  • default The default value
  • default_group Get the default group of the parameter</>
  • desc (list of str) The formatted description using attributes and _kwargs</>
  • desc_with_default If default is not specified in desc, just to add with the default value</>
  • hit (bool) Whether the parameter is just hit
  • is_help (bool) Whether this is a help parameter
  • is_positional Tell if this parameter is positional</>
  • names The names of the parameter
  • ns_param (ParamNamespace) The namespace parameter where this parameter is under
  • prefix (str) The prefix of the parameter on the command line
  • required (bool) Whether this parameter is required
  • show (bool) Whether this parameter should show on help page
  • subtype The subtype of the parameter if this is a complex type
  • type_frozen (bool) Whether the type is frozen (not allowing overwritting from command line)
  • value Return the cached value if possible, otherwise calcuate one</>
Methods
  • apply_callback(all_values) (any) Apply the callback function to the value</>
  • close() Close up the parameter while scanning the command line</>
  • complete_name(current) (iterator of (str, str)) Give the completion name candidates</>
  • complete_value(current, prefix) (Union(str, iterator of (str, ...))) Generate file paths with given current prefix as completion candidates</>
  • consume(value) (bool) Consume a value</>
  • copy() (Param) Copy a parameter so that it can be reused.</>
  • full_names() (list of str) make the names with full combinations of namespaces and terminals</>
  • name(which, with_prefix) (str) Get the shortest/longest name of the parameter</>
  • namespaces(index) (Union(list of str, int)) Get the namespaces at the given index or number of namespaces</>
  • namestr(sep, with_prefix) (str) Get all names connected with a separator.</>
  • on_register() Opens opportunity to do something when a parameter is registered</>
  • optstr() (str) Get the string representation of the parameter names and types in the optname section in help page</>
  • overwrite_type(param_type) (Param) Try to overwrite the type</>
  • push(item) Push a value into the stack for calculating</>
  • to(to_type) (Param) Generate a different type of parameter using current settings</>
  • typestr() (str) Get the string representation of the type</>
  • usagestr() (str) Get the string representation of the parameter in the default usage constructor</>
generator

complete_name(current)

Give the completion name candidates

Parameters
  • current (str) The current prefix or word under cursor
Returns (iterator of (str, str))

An iterator of a tuple including the prefixed name and description.

classmethod

on_register()

Opens opportunity to do something when a parameter is registered

method

namespaces(index='len')

Get the namespaces at the given index or number of namespaces

Parameters
  • index (int or str, optional) The index or a length indicator
Returns (Union(list of str, int))

The length of the namespaces or the namespaces at index.

method

full_names()

make the names with full combinations of namespaces and terminals

Since one can define a parameter like n.arg but namespace n can have aliases (i.e. ns). This makes sure the names of n.arg expands to n.arg and ns.arg

Returns (list of str)

The names with full combinations of namespaces and terminals

method

close()

Close up the parameter while scanning the command line

We are mostly doing nothing, only if, say, param is bool and it was just hit, we should push a true value to it.

method

overwrite_type(param_type)

Try to overwrite the type

Only when param_type is not None and it's different from mine A new param will be returned if different

Parameters
  • param_type (str) The type to overwrite
Returns (Param)

Self when type not changed otherwise a new parameter with the given type

method

consume(value)

Consume a value

Returns (bool)

True if value was consumed, otherwise False

method

name(which, with_prefix=True)

Get the shortest/longest name of the parameter

A name is ensured to be returned. It does not mean it is the real short/long name, but just the shortest/longest name among all the names

Parameters
  • which (str) Whether get the shortest or longest name Could use short or long for short.
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

The shortest/longest name of the parameter

method

namestr(sep=', ', with_prefix=True)

Get all names connected with a separator.

Parameters
  • sep (str, optional) The separator to connect the names
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

the connected names

method

typestr()

Get the string representation of the type

Returns (str)

the string representation of the type

method

usagestr()

Get the string representation of the parameter in the default usage constructor

Returns (str)

the string representation of the parameter in the default usage

method

optstr()

Get the string representation of the parameter names and types in the optname section in help page

Returns (str)

the string representation of the parameter names and types in the optname section in help page

method

to(to_type)

Generate a different type of parameter using current settings

Parameters
  • to_type (str) the type of parameter to generate
Returns (Param)

the generated parameter with different type

method

copy()

Copy a parameter so that it can be reused.

Returns (Param)

The copy of the parameter

method

push(item)

Push a value into the stack for calculating

Returns

The item to be pushed

method

apply_callback(all_values)

Apply the callback function to the value

Parameters
  • all_values (Namespace) The namespace of values of all parameters
Returns (any)

The value after the callback applied

Raises
  • PyParamTypeError When exceptions raised or returned from callback
method

complete_value(current, prefix='') → Union(str, iterator of (str, ...))

Generate file paths with given current prefix as completion candidates

Parameters
  • current (str) The current word or prefix under cursor
class

pyparam.param.ParamDir(names, default, desc, prefix='auto', show=True, required=False, subtype=None, type_frozen=True, callback=None, complete_callback=None, argname_shorten=True, **kwargs)

Subclass of ParamPath.

It does not make any difference with pyparam. However, it works differently for completions. The completion items for this param will only give directories instead of all paths

Parameters
  • names (Union(str, list of str)) The names of the parameter
  • default (any) The default value
  • desc (list of str) The description of the parameter
  • prefix (str, optional) The prefix of the parameter on the command line
  • show (bool, optional) Whether this parameter should show on help page
  • required (bool, optional) Whether this parameter is required
  • subtype (str or bool, optional) The subtype of the parameter if this is a complex type
  • type_frozen (bool, optional) Whether the type is frozen (not allowing overwritting from command line)
  • callback (callable, optional) The callback to modify the final value
  • complete_callback (callable, optional) The callback for complete the values of the parameter
  • argname_shorten (bool, optional) Whether show shortened name for parameters under namespace parameters
  • **kwargs (dict(str: any)) Additional keyword arguments
Attributes
  • _desc (list of str) The raw description of the parameter
  • _kwargs (dict(str: any)) other kwargs
  • _stack (list of any) The stack to push the values
  • _value_cached (any) The cached value calculated from the stack
  • argname_shorten (bool) Whether show shortened name for the parameters under namespace parameters
  • callback (callable) The callback to modify the final value
  • complete_callback (callable) The callback for complete the values of the parameter
  • default The default value
  • default_group Get the default group of the parameter</>
  • desc (list of str) The formatted description using attributes and _kwargs</>
  • desc_with_default If default is not specified in desc, just to add with the default value</>
  • hit (bool) Whether the parameter is just hit
  • is_help (bool) Whether this is a help parameter
  • is_positional Tell if this parameter is positional</>
  • names The names of the parameter
  • ns_param (ParamNamespace) The namespace parameter where this parameter is under
  • prefix (str) The prefix of the parameter on the command line
  • required (bool) Whether this parameter is required
  • show (bool) Whether this parameter should show on help page
  • subtype The subtype of the parameter if this is a complex type
  • type_frozen (bool) Whether the type is frozen (not allowing overwritting from command line)
  • value Return the cached value if possible, otherwise calcuate one</>
Methods
  • apply_callback(all_values) (any) Apply the callback function to the value</>
  • close() Close up the parameter while scanning the command line</>
  • complete_name(current) (iterator of (str, str)) Give the completion name candidates</>
  • complete_value(current, prefix) (Union(str, iterator of (str, ...))) Generate dir paths with given current prefix as completion candidates</>
  • consume(value) (bool) Consume a value</>
  • copy() (Param) Copy a parameter so that it can be reused.</>
  • full_names() (list of str) make the names with full combinations of namespaces and terminals</>
  • name(which, with_prefix) (str) Get the shortest/longest name of the parameter</>
  • namespaces(index) (Union(list of str, int)) Get the namespaces at the given index or number of namespaces</>
  • namestr(sep, with_prefix) (str) Get all names connected with a separator.</>
  • on_register() Opens opportunity to do something when a parameter is registered</>
  • optstr() (str) Get the string representation of the parameter names and types in the optname section in help page</>
  • overwrite_type(param_type) (Param) Try to overwrite the type</>
  • push(item) Push a value into the stack for calculating</>
  • to(to_type) (Param) Generate a different type of parameter using current settings</>
  • typestr() (str) Get the string representation of the type</>
  • usagestr() (str) Get the string representation of the parameter in the default usage constructor</>
generator

complete_name(current)

Give the completion name candidates

Parameters
  • current (str) The current prefix or word under cursor
Returns (iterator of (str, str))

An iterator of a tuple including the prefixed name and description.

classmethod

on_register()

Opens opportunity to do something when a parameter is registered

method

namespaces(index='len')

Get the namespaces at the given index or number of namespaces

Parameters
  • index (int or str, optional) The index or a length indicator
Returns (Union(list of str, int))

The length of the namespaces or the namespaces at index.

method

full_names()

make the names with full combinations of namespaces and terminals

Since one can define a parameter like n.arg but namespace n can have aliases (i.e. ns). This makes sure the names of n.arg expands to n.arg and ns.arg

Returns (list of str)

The names with full combinations of namespaces and terminals

method

close()

Close up the parameter while scanning the command line

We are mostly doing nothing, only if, say, param is bool and it was just hit, we should push a true value to it.

method

overwrite_type(param_type)

Try to overwrite the type

Only when param_type is not None and it's different from mine A new param will be returned if different

Parameters
  • param_type (str) The type to overwrite
Returns (Param)

Self when type not changed otherwise a new parameter with the given type

method

consume(value)

Consume a value

Returns (bool)

True if value was consumed, otherwise False

method

name(which, with_prefix=True)

Get the shortest/longest name of the parameter

A name is ensured to be returned. It does not mean it is the real short/long name, but just the shortest/longest name among all the names

Parameters
  • which (str) Whether get the shortest or longest name Could use short or long for short.
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

The shortest/longest name of the parameter

method

namestr(sep=', ', with_prefix=True)

Get all names connected with a separator.

Parameters
  • sep (str, optional) The separator to connect the names
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

the connected names

method

typestr()

Get the string representation of the type

Returns (str)

the string representation of the type

method

usagestr()

Get the string representation of the parameter in the default usage constructor

Returns (str)

the string representation of the parameter in the default usage

method

optstr()

Get the string representation of the parameter names and types in the optname section in help page

Returns (str)

the string representation of the parameter names and types in the optname section in help page

method

to(to_type)

Generate a different type of parameter using current settings

Parameters
  • to_type (str) the type of parameter to generate
Returns (Param)

the generated parameter with different type

method

copy()

Copy a parameter so that it can be reused.

Returns (Param)

The copy of the parameter

method

push(item)

Push a value into the stack for calculating

Returns

The item to be pushed

method

apply_callback(all_values)

Apply the callback function to the value

Parameters
  • all_values (Namespace) The namespace of values of all parameters
Returns (any)

The value after the callback applied

Raises
  • PyParamTypeError When exceptions raised or returned from callback
method

complete_value(current, prefix='') → Union(str, iterator of (str, ...))

Generate dir paths with given current prefix as completion candidates

Parameters
  • current (str) The current word or prefix under cursor
class

pyparam.param.ParamPy(names, default, desc, prefix='auto', show=True, required=False, subtype=None, type_frozen=True, callback=None, complete_callback=None, argname_shorten=True, **kwargs)

A parameter whose value will be ast.literal_eval'ed

Parameters
  • names (Union(str, list of str)) The names of the parameter
  • default (any) The default value
  • desc (list of str) The description of the parameter
  • prefix (str, optional) The prefix of the parameter on the command line
  • show (bool, optional) Whether this parameter should show on help page
  • required (bool, optional) Whether this parameter is required
  • subtype (str or bool, optional) The subtype of the parameter if this is a complex type
  • type_frozen (bool, optional) Whether the type is frozen (not allowing overwritting from command line)
  • callback (callable, optional) The callback to modify the final value
  • complete_callback (callable, optional) The callback for complete the values of the parameter
  • argname_shorten (bool, optional) Whether show shortened name for parameters under namespace parameters
  • **kwargs (dict(str: any)) Additional keyword arguments
Attributes
  • _desc (list of str) The raw description of the parameter
  • _kwargs (dict(str: any)) other kwargs
  • _stack (list of any) The stack to push the values
  • _value_cached (any) The cached value calculated from the stack
  • argname_shorten (bool) Whether show shortened name for the parameters under namespace parameters
  • callback (callable) The callback to modify the final value
  • complete_callback (callable) The callback for complete the values of the parameter
  • default The default value
  • default_group Get the default group of the parameter</>
  • desc (list of str) The formatted description using attributes and _kwargs</>
  • desc_with_default If default is not specified in desc, just to add with the default value</>
  • hit (bool) Whether the parameter is just hit
  • is_help (bool) Whether this is a help parameter
  • is_positional Tell if this parameter is positional</>
  • names The names of the parameter
  • ns_param (ParamNamespace) The namespace parameter where this parameter is under
  • prefix (str) The prefix of the parameter on the command line
  • required (bool) Whether this parameter is required
  • show (bool) Whether this parameter should show on help page
  • subtype The subtype of the parameter if this is a complex type
  • type_frozen (bool) Whether the type is frozen (not allowing overwritting from command line)
  • value Return the cached value if possible, otherwise calcuate one</>
Methods
  • apply_callback(all_values) (any) Apply the callback function to the value</>
  • close() Close up the parameter while scanning the command line</>
  • complete_name(current) (iterator of (str, str)) Give the completion name candidates</>
  • complete_value(current, prefix) (Union(str, iterator of (str, ...))) Give the completion candidates</>
  • consume(value) (bool) Consume a value</>
  • copy() (Param) Copy a parameter so that it can be reused.</>
  • full_names() (list of str) make the names with full combinations of namespaces and terminals</>
  • name(which, with_prefix) (str) Get the shortest/longest name of the parameter</>
  • namespaces(index) (Union(list of str, int)) Get the namespaces at the given index or number of namespaces</>
  • namestr(sep, with_prefix) (str) Get all names connected with a separator.</>
  • on_register() Opens opportunity to do something when a parameter is registered</>
  • optstr() (str) Get the string representation of the parameter names and types in the optname section in help page</>
  • overwrite_type(param_type) (Param) Try to overwrite the type</>
  • push(item) Push a value into the stack for calculating</>
  • to(to_type) (Param) Generate a different type of parameter using current settings</>
  • typestr() (str) Get the string representation of the type</>
  • usagestr() (str) Get the string representation of the parameter in the default usage constructor</>
method

complete_value(current, prefix='')

Give the completion candidates

Parameters
  • current (str) Current prefix
Returns (Union(str, iterator of (str, ...)))

None when there are no candidates, nor should we have next paramters/commands as candidates (requiring a value). An empty string if we should put next parameters/commands as candidates. Otherwise yields The candidates should be either 1-, 2-, or 3-element tuple. If 1-element, type plain and no description implied. If 2-element, type plain and 2nd element should be description. If 3-element, 2nd element the type, 3rd the description.

generator

complete_name(current)

Give the completion name candidates

Parameters
  • current (str) The current prefix or word under cursor
Returns (iterator of (str, str))

An iterator of a tuple including the prefixed name and description.

classmethod

on_register()

Opens opportunity to do something when a parameter is registered

method

namespaces(index='len')

Get the namespaces at the given index or number of namespaces

Parameters
  • index (int or str, optional) The index or a length indicator
Returns (Union(list of str, int))

The length of the namespaces or the namespaces at index.

method

full_names()

make the names with full combinations of namespaces and terminals

Since one can define a parameter like n.arg but namespace n can have aliases (i.e. ns). This makes sure the names of n.arg expands to n.arg and ns.arg

Returns (list of str)

The names with full combinations of namespaces and terminals

method

close()

Close up the parameter while scanning the command line

We are mostly doing nothing, only if, say, param is bool and it was just hit, we should push a true value to it.

method

overwrite_type(param_type)

Try to overwrite the type

Only when param_type is not None and it's different from mine A new param will be returned if different

Parameters
  • param_type (str) The type to overwrite
Returns (Param)

Self when type not changed otherwise a new parameter with the given type

method

consume(value)

Consume a value

Returns (bool)

True if value was consumed, otherwise False

method

name(which, with_prefix=True)

Get the shortest/longest name of the parameter

A name is ensured to be returned. It does not mean it is the real short/long name, but just the shortest/longest name among all the names

Parameters
  • which (str) Whether get the shortest or longest name Could use short or long for short.
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

The shortest/longest name of the parameter

method

namestr(sep=', ', with_prefix=True)

Get all names connected with a separator.

Parameters
  • sep (str, optional) The separator to connect the names
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

the connected names

method

typestr()

Get the string representation of the type

Returns (str)

the string representation of the type

method

usagestr()

Get the string representation of the parameter in the default usage constructor

Returns (str)

the string representation of the parameter in the default usage

method

optstr()

Get the string representation of the parameter names and types in the optname section in help page

Returns (str)

the string representation of the parameter names and types in the optname section in help page

method

to(to_type)

Generate a different type of parameter using current settings

Parameters
  • to_type (str) the type of parameter to generate
Returns (Param)

the generated parameter with different type

method

copy()

Copy a parameter so that it can be reused.

Returns (Param)

The copy of the parameter

method

push(item)

Push a value into the stack for calculating

Returns

The item to be pushed

method

apply_callback(all_values)

Apply the callback function to the value

Parameters
  • all_values (Namespace) The namespace of values of all parameters
Returns (any)

The value after the callback applied

Raises
  • PyParamTypeError When exceptions raised or returned from callback
class

pyparam.param.ParamJson(names, default, desc, prefix='auto', show=True, required=False, subtype=None, type_frozen=True, callback=None, complete_callback=None, argname_shorten=True, **kwargs)

A parameter whose value will be parsed as json

Parameters
  • names (Union(str, list of str)) The names of the parameter
  • default (any) The default value
  • desc (list of str) The description of the parameter
  • prefix (str, optional) The prefix of the parameter on the command line
  • show (bool, optional) Whether this parameter should show on help page
  • required (bool, optional) Whether this parameter is required
  • subtype (str or bool, optional) The subtype of the parameter if this is a complex type
  • type_frozen (bool, optional) Whether the type is frozen (not allowing overwritting from command line)
  • callback (callable, optional) The callback to modify the final value
  • complete_callback (callable, optional) The callback for complete the values of the parameter
  • argname_shorten (bool, optional) Whether show shortened name for parameters under namespace parameters
  • **kwargs (dict(str: any)) Additional keyword arguments
Attributes
  • _desc (list of str) The raw description of the parameter
  • _kwargs (dict(str: any)) other kwargs
  • _stack (list of any) The stack to push the values
  • _value_cached (any) The cached value calculated from the stack
  • argname_shorten (bool) Whether show shortened name for the parameters under namespace parameters
  • callback (callable) The callback to modify the final value
  • complete_callback (callable) The callback for complete the values of the parameter
  • default The default value
  • default_group Get the default group of the parameter</>
  • desc (list of str) The formatted description using attributes and _kwargs</>
  • desc_with_default If default is not specified in desc, just to add with the default value</>
  • hit (bool) Whether the parameter is just hit
  • is_help (bool) Whether this is a help parameter
  • is_positional Tell if this parameter is positional</>
  • names The names of the parameter
  • ns_param (ParamNamespace) The namespace parameter where this parameter is under
  • prefix (str) The prefix of the parameter on the command line
  • required (bool) Whether this parameter is required
  • show (bool) Whether this parameter should show on help page
  • subtype The subtype of the parameter if this is a complex type
  • type_frozen (bool) Whether the type is frozen (not allowing overwritting from command line)
  • value Return the cached value if possible, otherwise calcuate one</>
Methods
  • apply_callback(all_values) (any) Apply the callback function to the value</>
  • close() Close up the parameter while scanning the command line</>
  • complete_name(current) (iterator of (str, str)) Give the completion name candidates</>
  • complete_value(current, prefix) (Union(str, iterator of (str, ...))) Give the completion candidates</>
  • consume(value) (bool) Consume a value</>
  • copy() (Param) Copy a parameter so that it can be reused.</>
  • full_names() (list of str) make the names with full combinations of namespaces and terminals</>
  • name(which, with_prefix) (str) Get the shortest/longest name of the parameter</>
  • namespaces(index) (Union(list of str, int)) Get the namespaces at the given index or number of namespaces</>
  • namestr(sep, with_prefix) (str) Get all names connected with a separator.</>
  • on_register() Opens opportunity to do something when a parameter is registered</>
  • optstr() (str) Get the string representation of the parameter names and types in the optname section in help page</>
  • overwrite_type(param_type) (Param) Try to overwrite the type</>
  • push(item) Push a value into the stack for calculating</>
  • to(to_type) (Param) Generate a different type of parameter using current settings</>
  • typestr() (str) Get the string representation of the type</>
  • usagestr() (str) Get the string representation of the parameter in the default usage constructor</>
method

complete_value(current, prefix='')

Give the completion candidates

Parameters
  • current (str) Current prefix
Returns (Union(str, iterator of (str, ...)))

None when there are no candidates, nor should we have next paramters/commands as candidates (requiring a value). An empty string if we should put next parameters/commands as candidates. Otherwise yields The candidates should be either 1-, 2-, or 3-element tuple. If 1-element, type plain and no description implied. If 2-element, type plain and 2nd element should be description. If 3-element, 2nd element the type, 3rd the description.

generator

complete_name(current)

Give the completion name candidates

Parameters
  • current (str) The current prefix or word under cursor
Returns (iterator of (str, str))

An iterator of a tuple including the prefixed name and description.

classmethod

on_register()

Opens opportunity to do something when a parameter is registered

method

namespaces(index='len')

Get the namespaces at the given index or number of namespaces

Parameters
  • index (int or str, optional) The index or a length indicator
Returns (Union(list of str, int))

The length of the namespaces or the namespaces at index.

method

full_names()

make the names with full combinations of namespaces and terminals

Since one can define a parameter like n.arg but namespace n can have aliases (i.e. ns). This makes sure the names of n.arg expands to n.arg and ns.arg

Returns (list of str)

The names with full combinations of namespaces and terminals

method

close()

Close up the parameter while scanning the command line

We are mostly doing nothing, only if, say, param is bool and it was just hit, we should push a true value to it.

method

overwrite_type(param_type)

Try to overwrite the type

Only when param_type is not None and it's different from mine A new param will be returned if different

Parameters
  • param_type (str) The type to overwrite
Returns (Param)

Self when type not changed otherwise a new parameter with the given type

method

consume(value)

Consume a value

Returns (bool)

True if value was consumed, otherwise False

method

name(which, with_prefix=True)

Get the shortest/longest name of the parameter

A name is ensured to be returned. It does not mean it is the real short/long name, but just the shortest/longest name among all the names

Parameters
  • which (str) Whether get the shortest or longest name Could use short or long for short.
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

The shortest/longest name of the parameter

method

namestr(sep=', ', with_prefix=True)

Get all names connected with a separator.

Parameters
  • sep (str, optional) The separator to connect the names
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

the connected names

method

typestr()

Get the string representation of the type

Returns (str)

the string representation of the type

method

usagestr()

Get the string representation of the parameter in the default usage constructor

Returns (str)

the string representation of the parameter in the default usage

method

optstr()

Get the string representation of the parameter names and types in the optname section in help page

Returns (str)

the string representation of the parameter names and types in the optname section in help page

method

to(to_type)

Generate a different type of parameter using current settings

Parameters
  • to_type (str) the type of parameter to generate
Returns (Param)

the generated parameter with different type

method

copy()

Copy a parameter so that it can be reused.

Returns (Param)

The copy of the parameter

method

push(item)

Push a value into the stack for calculating

Returns

The item to be pushed

method

apply_callback(all_values)

Apply the callback function to the value

Parameters
  • all_values (Namespace) The namespace of values of all parameters
Returns (any)

The value after the callback applied

Raises
  • PyParamTypeError When exceptions raised or returned from callback
class

pyparam.param.ParamList(*args, **kwargs)

A parameter whose value is a list

Parameters
  • **kwargs (dict(str: any)) Additional keyword arguments
Attributes
  • _desc (list of str) The raw description of the parameter
  • _kwargs (dict(str: any)) other kwargs
  • _stack (list of any) The stack to push the values
  • _value_cached (any) The cached value calculated from the stack
  • argname_shorten (bool) Whether show shortened name for the parameters under namespace parameters
  • callback (callable) The callback to modify the final value
  • complete_callback (callable) The callback for complete the values of the parameter
  • default The default value
  • default_group Get the default group of the parameter</>
  • desc (list of str) The formatted description using attributes and _kwargs</>
  • desc_with_default If default is not specified in desc, just to add with the default value</>
  • hit (bool) Whether the parameter is just hit
  • is_help (bool) Whether this is a help parameter
  • is_positional Tell if this parameter is positional</>
  • names The names of the parameter
  • ns_param (ParamNamespace) The namespace parameter where this parameter is under
  • prefix (str) The prefix of the parameter on the command line
  • required (bool) Whether this parameter is required
  • show (bool) Whether this parameter should show on help page
  • subtype The subtype of the parameter if this is a complex type
  • type_frozen (bool) Whether the type is frozen (not allowing overwritting from command line)
  • value Return the cached value if possible, otherwise calcuate one</>
Methods
  • apply_callback(all_values) (any) Apply the callback function to the value</>
  • close() Close up the parameter while scanning the command line</>
  • complete_name(current) (iterator of (str, str)) Give the completion name candidates</>
  • complete_value(current, prefix) (Union(str, iterator of (str, ...))) Give the completion candidates</>
  • consume(value) (bool) Should I consume given parameter?</>
  • copy() (Param) Copy a parameter so that it can be reused.</>
  • full_names() (list of str) make the names with full combinations of namespaces and terminals</>
  • name(which, with_prefix) (str) Get the shortest/longest name of the parameter</>
  • namespaces(index) (Union(list of str, int)) Get the namespaces at the given index or number of namespaces</>
  • namestr(sep, with_prefix) (str) Get all names connected with a separator.</>
  • on_register() Also register reset type</>
  • optstr() (str) Get the string representation of the parameter names and types in the optname section in help page</>
  • overwrite_type(param_type) (Param) Deal with when param_type is reset</>
  • push(item) Push a value into the stack for calculating</>
  • to(to_type) (Param) Generate a different type of parameter using current settings</>
  • typestr() (str) Get the string representation of the type</>
  • usagestr() (str) Get the string representation of the parameter in the default usage constructor</>
method

complete_value(current, prefix='')

Give the completion candidates

Parameters
  • current (str) Current prefix
Returns (Union(str, iterator of (str, ...)))

None when there are no candidates, nor should we have next paramters/commands as candidates (requiring a value). An empty string if we should put next parameters/commands as candidates. Otherwise yields The candidates should be either 1-, 2-, or 3-element tuple. If 1-element, type plain and no description implied. If 2-element, type plain and 2nd element should be description. If 3-element, 2nd element the type, 3rd the description.

generator

complete_name(current)

Give the completion name candidates

Parameters
  • current (str) The current prefix or word under cursor
Returns (iterator of (str, str))

An iterator of a tuple including the prefixed name and description.

method

namespaces(index='len')

Get the namespaces at the given index or number of namespaces

Parameters
  • index (int or str, optional) The index or a length indicator
Returns (Union(list of str, int))

The length of the namespaces or the namespaces at index.

method

full_names()

make the names with full combinations of namespaces and terminals

Since one can define a parameter like n.arg but namespace n can have aliases (i.e. ns). This makes sure the names of n.arg expands to n.arg and ns.arg

Returns (list of str)

The names with full combinations of namespaces and terminals

method

close()

Close up the parameter while scanning the command line

We are mostly doing nothing, only if, say, param is bool and it was just hit, we should push a true value to it.

method

name(which, with_prefix=True)

Get the shortest/longest name of the parameter

A name is ensured to be returned. It does not mean it is the real short/long name, but just the shortest/longest name among all the names

Parameters
  • which (str) Whether get the shortest or longest name Could use short or long for short.
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

The shortest/longest name of the parameter

method

namestr(sep=', ', with_prefix=True)

Get all names connected with a separator.

Parameters
  • sep (str, optional) The separator to connect the names
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

the connected names

method

typestr()

Get the string representation of the type

Returns (str)

the string representation of the type

method

usagestr()

Get the string representation of the parameter in the default usage constructor

Returns (str)

the string representation of the parameter in the default usage

method

optstr()

Get the string representation of the parameter names and types in the optname section in help page

Returns (str)

the string representation of the parameter names and types in the optname section in help page

method

to(to_type)

Generate a different type of parameter using current settings

Parameters
  • to_type (str) the type of parameter to generate
Returns (Param)

the generated parameter with different type

method

copy()

Copy a parameter so that it can be reused.

Returns (Param)

The copy of the parameter

method

apply_callback(all_values)

Apply the callback function to the value

Parameters
  • all_values (Namespace) The namespace of values of all parameters
Returns (any)

The value after the callback applied

Raises
  • PyParamTypeError When exceptions raised or returned from callback
classmethod

on_register()

Also register reset type

method

overwrite_type(param_type)Param

Deal with when param_type is reset

Parameters
  • param_type (str) The type to overwrite
method

consume(value) → bool

Should I consume given parameter?

method

push(item)

Push a value into the stack for calculating

class

pyparam.param.ParamChoice(*args, **kwargs)

A bool parameter whose value is automatically casted into a bool

Parameters
  • **kwargs (dict(str: any)) Additional keyword arguments
Attributes
  • _desc (list of str) The raw description of the parameter
  • _kwargs (dict(str: any)) other kwargs
  • _stack (list of any) The stack to push the values
  • _value_cached (any) The cached value calculated from the stack
  • argname_shorten (bool) Whether show shortened name for the parameters under namespace parameters
  • callback (callable) The callback to modify the final value
  • complete_callback (callable) The callback for complete the values of the parameter
  • default The default value
  • default_group Get the default group of the parameter</>
  • desc (list of str) The formatted description using attributes and _kwargs</>
  • desc_with_default If default is not specified in desc, just to add with the default value</>
  • hit (bool) Whether the parameter is just hit
  • is_help (bool) Whether this is a help parameter
  • is_positional Tell if this parameter is positional</>
  • names The names of the parameter
  • ns_param (ParamNamespace) The namespace parameter where this parameter is under
  • prefix (str) The prefix of the parameter on the command line
  • required (bool) Whether this parameter is required
  • show (bool) Whether this parameter should show on help page
  • subtype The subtype of the parameter if this is a complex type
  • type_frozen (bool) Whether the type is frozen (not allowing overwritting from command line)
  • value Return the cached value if possible, otherwise calcuate one</>
Methods
  • apply_callback(all_values) (any) Apply the callback function to the value</>
  • close() Close up the parameter while scanning the command line</>
  • complete_name(current) (iterator of (str, str)) Give the completion name candidates</>
  • complete_value(current, prefix) (Union(str, iterator of (str, ...))) Generate choices with given current prefix as completion candidates</>
  • consume(value) (bool) Consume a value</>
  • copy() (Param) Copy a parameter so that it can be reused.</>
  • full_names() (list of str) make the names with full combinations of namespaces and terminals</>
  • name(which, with_prefix) (str) Get the shortest/longest name of the parameter</>
  • namespaces(index) (Union(list of str, int)) Get the namespaces at the given index or number of namespaces</>
  • namestr(sep, with_prefix) (str) Get all names connected with a separator.</>
  • on_register() Opens opportunity to do something when a parameter is registered</>
  • optstr() (str) Get the string representation of the parameter names and types in the optname section in help page</>
  • overwrite_type(param_type) (Param) Try to overwrite the type</>
  • push(item) Push a value into the stack for calculating</>
  • to(to_type) (Param) Generate a different type of parameter using current settings</>
  • typestr() (str) Get the string representation of the type</>
  • usagestr() (str) Get the string representation of the parameter in the default usage constructor</>
generator

complete_name(current)

Give the completion name candidates

Parameters
  • current (str) The current prefix or word under cursor
Returns (iterator of (str, str))

An iterator of a tuple including the prefixed name and description.

classmethod

on_register()

Opens opportunity to do something when a parameter is registered

method

namespaces(index='len')

Get the namespaces at the given index or number of namespaces

Parameters
  • index (int or str, optional) The index or a length indicator
Returns (Union(list of str, int))

The length of the namespaces or the namespaces at index.

method

full_names()

make the names with full combinations of namespaces and terminals

Since one can define a parameter like n.arg but namespace n can have aliases (i.e. ns). This makes sure the names of n.arg expands to n.arg and ns.arg

Returns (list of str)

The names with full combinations of namespaces and terminals

method

close()

Close up the parameter while scanning the command line

We are mostly doing nothing, only if, say, param is bool and it was just hit, we should push a true value to it.

method

overwrite_type(param_type)

Try to overwrite the type

Only when param_type is not None and it's different from mine A new param will be returned if different

Parameters
  • param_type (str) The type to overwrite
Returns (Param)

Self when type not changed otherwise a new parameter with the given type

method

consume(value)

Consume a value

Returns (bool)

True if value was consumed, otherwise False

method

name(which, with_prefix=True)

Get the shortest/longest name of the parameter

A name is ensured to be returned. It does not mean it is the real short/long name, but just the shortest/longest name among all the names

Parameters
  • which (str) Whether get the shortest or longest name Could use short or long for short.
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

The shortest/longest name of the parameter

method

namestr(sep=', ', with_prefix=True)

Get all names connected with a separator.

Parameters
  • sep (str, optional) The separator to connect the names
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

the connected names

method

typestr()

Get the string representation of the type

Returns (str)

the string representation of the type

method

usagestr()

Get the string representation of the parameter in the default usage constructor

Returns (str)

the string representation of the parameter in the default usage

method

optstr()

Get the string representation of the parameter names and types in the optname section in help page

Returns (str)

the string representation of the parameter names and types in the optname section in help page

method

to(to_type)

Generate a different type of parameter using current settings

Parameters
  • to_type (str) the type of parameter to generate
Returns (Param)

the generated parameter with different type

method

copy()

Copy a parameter so that it can be reused.

Returns (Param)

The copy of the parameter

method

push(item)

Push a value into the stack for calculating

Returns

The item to be pushed

method

apply_callback(all_values)

Apply the callback function to the value

Parameters
  • all_values (Namespace) The namespace of values of all parameters
Returns (any)

The value after the callback applied

Raises
  • PyParamTypeError When exceptions raised or returned from callback
method

complete_value(current, prefix='') → Union(str, iterator of (str, ...))

Generate choices with given current prefix as completion candidates

Parameters
  • current (str) The current word or prefix under cursor
class

pyparam.param.ParamNamespace(*args, **kwargs)

A pseudo parameter serving as a namespace for parameters under it

So that it is possible to do:

prog --namespace.arg1 1 --namespace.arg2 2

Parameters
  • **kwargs (dict(str: any)) Additional keyword arguments
Attributes
  • _desc (list of str) The raw description of the parameter
  • _kwargs (dict(str: any)) other kwargs
  • _stack (list of any) The stack to push the values
  • _value_cached (any) The cached value calculated from the stack
  • argname_shorten (bool) Whether show shortened name for the parameters under namespace parameters
  • callback (callable) The callback to modify the final value
  • complete_callback (callable) The callback for complete the values of the parameter
  • default The default value
  • default_group (str) Get the default group of the parameter</>
  • desc (list of str) The formatted description using attributes and _kwargs</>
  • desc_with_default (list of str) Namespace parameters do not have a default value</>
  • hit (bool) Whether the parameter is just hit
  • is_help (bool) Whether this is a help parameter
  • is_positional Tell if this parameter is positional</>
  • names The names of the parameter
  • ns_param (ParamNamespace) The namespace parameter where this parameter is under
  • prefix (str) The prefix of the parameter on the command line
  • required (bool) Whether this parameter is required
  • show (bool) Whether this parameter should show on help page
  • subtype The subtype of the parameter if this is a complex type
  • type_frozen (bool) Whether the type is frozen (not allowing overwritting from command line)
  • value Return the cached value if possible, otherwise calcuate one</>
Methods
  • apply_callback(all_values) (any) Apply the callback function to the value</>
  • close() Close up the parameter while scanning the command line</>
  • complete_name(current) (iterator of (str, str)) Give the completion name candidates</>
  • complete_value(current, prefix) (Union(str, iterator of (str, ...))) Give the completion candidates</>
  • consume(value) (bool) Should I consume given parameter?</>
  • copy() (Param) Copy a parameter so that it can be reused.</>
  • decendents(show_only) (list of Param) Get all decendents of this namespace parameter</>
  • full_names() (list of str) make the names with full combinations of namespaces and terminals</>
  • get_param(name, depth) (Param) Get the paraemeter by given name</>
  • name(which, with_prefix) (str) Get the shortest/longest name of the parameter</>
  • namespaces(index) (Union(list of str, int)) Get the namespaces at the given index or number of namespaces</>
  • namestr(sep, with_prefix) (str) Get all names connected with a separator.</>
  • on_register() Opens opportunity to do something when a parameter is registered</>
  • optstr() (str) Get the string representation of the parameter names and types in the optname section in help page</>
  • overwrite_type(param_type) (Param) Try to overwrite the type</>
  • push(item, depth) Push the parameter under this namespace.</>
  • to(to_type) (Param) Generate a different type of parameter using current settings</>
  • typestr() (str) Get the string representation of the type</>
  • usagestr() (str) Get the string representation of the parameter in the default usage constructor</>
method

complete_value(current, prefix='')

Give the completion candidates

Parameters
  • current (str) Current prefix
Returns (Union(str, iterator of (str, ...)))

None when there are no candidates, nor should we have next paramters/commands as candidates (requiring a value). An empty string if we should put next parameters/commands as candidates. Otherwise yields The candidates should be either 1-, 2-, or 3-element tuple. If 1-element, type plain and no description implied. If 2-element, type plain and 2nd element should be description. If 3-element, 2nd element the type, 3rd the description.

generator

complete_name(current)

Give the completion name candidates

Parameters
  • current (str) The current prefix or word under cursor
Returns (iterator of (str, str))

An iterator of a tuple including the prefixed name and description.

classmethod

on_register()

Opens opportunity to do something when a parameter is registered

method

namespaces(index='len')

Get the namespaces at the given index or number of namespaces

Parameters
  • index (int or str, optional) The index or a length indicator
Returns (Union(list of str, int))

The length of the namespaces or the namespaces at index.

method

full_names()

make the names with full combinations of namespaces and terminals

Since one can define a parameter like n.arg but namespace n can have aliases (i.e. ns). This makes sure the names of n.arg expands to n.arg and ns.arg

Returns (list of str)

The names with full combinations of namespaces and terminals

method

close()

Close up the parameter while scanning the command line

We are mostly doing nothing, only if, say, param is bool and it was just hit, we should push a true value to it.

method

overwrite_type(param_type)

Try to overwrite the type

Only when param_type is not None and it's different from mine A new param will be returned if different

Parameters
  • param_type (str) The type to overwrite
Returns (Param)

Self when type not changed otherwise a new parameter with the given type

method

name(which, with_prefix=True)

Get the shortest/longest name of the parameter

A name is ensured to be returned. It does not mean it is the real short/long name, but just the shortest/longest name among all the names

Parameters
  • which (str) Whether get the shortest or longest name Could use short or long for short.
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

The shortest/longest name of the parameter

method

namestr(sep=', ', with_prefix=True)

Get all names connected with a separator.

Parameters
  • sep (str, optional) The separator to connect the names
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

the connected names

method

typestr()

Get the string representation of the type

Returns (str)

the string representation of the type

method

usagestr()

Get the string representation of the parameter in the default usage constructor

Returns (str)

the string representation of the parameter in the default usage

method

optstr()

Get the string representation of the parameter names and types in the optname section in help page

Returns (str)

the string representation of the parameter names and types in the optname section in help page

method

to(to_type)

Generate a different type of parameter using current settings

Parameters
  • to_type (str) the type of parameter to generate
Returns (Param)

the generated parameter with different type

method

decendents(show_only=False)

Get all decendents of this namespace parameter

Parameters
  • show_only (optional) Load params with show=True only?
Returns (list of Param)

The decendents of this namespace parameter

method

consume(value) → bool

Should I consume given parameter?

method

get_param(name, depth=0)

Get the paraemeter by given name

This parameter is like '-a', and the name can be 'a.b.c.d'

Parameters
  • name (str) The name of the parameter to get
  • depth (int, optional) The depth
Returns (Param)

The parameter we get with the given name

method

push(item, depth=0)

Push the parameter under this namespace.

We are not pushing any values to this namespace, but pushing parameters that are under it.

method

copy()

Copy a parameter so that it can be reused.

Returns (Param)

The copy of the parameter

method

apply_callback(all_values)

Apply the callback function to the value

Parameters
  • all_values (Namespace) The namespace of values of all parameters
Returns (any)

The value after the callback applied

Raises
  • PyParamTypeError When exceptions raised or returned from callback
class

pyparam.param.ParamNamespace(*args, **kwargs)

A pseudo parameter serving as a namespace for parameters under it

So that it is possible to do:

prog --namespace.arg1 1 --namespace.arg2 2

Parameters
  • **kwargs (dict(str: any)) Additional keyword arguments
Attributes
  • _desc (list of str) The raw description of the parameter
  • _kwargs (dict(str: any)) other kwargs
  • _stack (list of any) The stack to push the values
  • _value_cached (any) The cached value calculated from the stack
  • argname_shorten (bool) Whether show shortened name for the parameters under namespace parameters
  • callback (callable) The callback to modify the final value
  • complete_callback (callable) The callback for complete the values of the parameter
  • default The default value
  • default_group (str) Get the default group of the parameter</>
  • desc (list of str) The formatted description using attributes and _kwargs</>
  • desc_with_default (list of str) Namespace parameters do not have a default value</>
  • hit (bool) Whether the parameter is just hit
  • is_help (bool) Whether this is a help parameter
  • is_positional Tell if this parameter is positional</>
  • names The names of the parameter
  • ns_param (ParamNamespace) The namespace parameter where this parameter is under
  • prefix (str) The prefix of the parameter on the command line
  • required (bool) Whether this parameter is required
  • show (bool) Whether this parameter should show on help page
  • subtype The subtype of the parameter if this is a complex type
  • type_frozen (bool) Whether the type is frozen (not allowing overwritting from command line)
  • value Return the cached value if possible, otherwise calcuate one</>
Methods
  • apply_callback(all_values) (any) Apply the callback function to the value</>
  • close() Close up the parameter while scanning the command line</>
  • complete_name(current) (iterator of (str, str)) Give the completion name candidates</>
  • complete_value(current, prefix) (Union(str, iterator of (str, ...))) Give the completion candidates</>
  • consume(value) (bool) Should I consume given parameter?</>
  • copy() (Param) Copy a parameter so that it can be reused.</>
  • decendents(show_only) (list of Param) Get all decendents of this namespace parameter</>
  • full_names() (list of str) make the names with full combinations of namespaces and terminals</>
  • get_param(name, depth) (Param) Get the paraemeter by given name</>
  • name(which, with_prefix) (str) Get the shortest/longest name of the parameter</>
  • namespaces(index) (Union(list of str, int)) Get the namespaces at the given index or number of namespaces</>
  • namestr(sep, with_prefix) (str) Get all names connected with a separator.</>
  • on_register() Opens opportunity to do something when a parameter is registered</>
  • optstr() (str) Get the string representation of the parameter names and types in the optname section in help page</>
  • overwrite_type(param_type) (Param) Try to overwrite the type</>
  • push(item, depth) Push the parameter under this namespace.</>
  • to(to_type) (Param) Generate a different type of parameter using current settings</>
  • typestr() (str) Get the string representation of the type</>
  • usagestr() (str) Get the string representation of the parameter in the default usage constructor</>
method

complete_value(current, prefix='')

Give the completion candidates

Parameters
  • current (str) Current prefix
Returns (Union(str, iterator of (str, ...)))

None when there are no candidates, nor should we have next paramters/commands as candidates (requiring a value). An empty string if we should put next parameters/commands as candidates. Otherwise yields The candidates should be either 1-, 2-, or 3-element tuple. If 1-element, type plain and no description implied. If 2-element, type plain and 2nd element should be description. If 3-element, 2nd element the type, 3rd the description.

generator

complete_name(current)

Give the completion name candidates

Parameters
  • current (str) The current prefix or word under cursor
Returns (iterator of (str, str))

An iterator of a tuple including the prefixed name and description.

classmethod

on_register()

Opens opportunity to do something when a parameter is registered

method

namespaces(index='len')

Get the namespaces at the given index or number of namespaces

Parameters
  • index (int or str, optional) The index or a length indicator
Returns (Union(list of str, int))

The length of the namespaces or the namespaces at index.

method

full_names()

make the names with full combinations of namespaces and terminals

Since one can define a parameter like n.arg but namespace n can have aliases (i.e. ns). This makes sure the names of n.arg expands to n.arg and ns.arg

Returns (list of str)

The names with full combinations of namespaces and terminals

method

close()

Close up the parameter while scanning the command line

We are mostly doing nothing, only if, say, param is bool and it was just hit, we should push a true value to it.

method

overwrite_type(param_type)

Try to overwrite the type

Only when param_type is not None and it's different from mine A new param will be returned if different

Parameters
  • param_type (str) The type to overwrite
Returns (Param)

Self when type not changed otherwise a new parameter with the given type

method

name(which, with_prefix=True)

Get the shortest/longest name of the parameter

A name is ensured to be returned. It does not mean it is the real short/long name, but just the shortest/longest name among all the names

Parameters
  • which (str) Whether get the shortest or longest name Could use short or long for short.
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

The shortest/longest name of the parameter

method

namestr(sep=', ', with_prefix=True)

Get all names connected with a separator.

Parameters
  • sep (str, optional) The separator to connect the names
  • with_prefix (bool, optional) Whether to include the prefix or not
Returns (str)

the connected names

method

typestr()

Get the string representation of the type

Returns (str)

the string representation of the type

method

usagestr()

Get the string representation of the parameter in the default usage constructor

Returns (str)

the string representation of the parameter in the default usage

method

optstr()

Get the string representation of the parameter names and types in the optname section in help page

Returns (str)

the string representation of the parameter names and types in the optname section in help page

method

to(to_type)

Generate a different type of parameter using current settings

Parameters
  • to_type (str) the type of parameter to generate
Returns (Param)

the generated parameter with different type

method

decendents(show_only=False)

Get all decendents of this namespace parameter

Parameters
  • show_only (optional) Load params with show=True only?
Returns (list of Param)

The decendents of this namespace parameter

method

consume(value) → bool

Should I consume given parameter?

method

get_param(name, depth=0)

Get the paraemeter by given name

This parameter is like '-a', and the name can be 'a.b.c.d'

Parameters
  • name (str) The name of the parameter to get
  • depth (int, optional) The depth
Returns (Param)

The parameter we get with the given name

method

push(item, depth=0)

Push the parameter under this namespace.

We are not pushing any values to this namespace, but pushing parameters that are under it.

method

copy()

Copy a parameter so that it can be reused.

Returns (Param)

The copy of the parameter

method

apply_callback(all_values)

Apply the callback function to the value

Parameters
  • all_values (Namespace) The namespace of values of all parameters
Returns (any)

The value after the callback applied

Raises
  • PyParamTypeError When exceptions raised or returned from callback
function

pyparam.param.register_param(param)

Register a parameter class

Parameters
  • param (type of Param) The param to register A param class should include a type You can also define type alias for a param type