class PdArgumentParser(dataclass_types: Union[DataClassType, Iterable[DataClassType]], **kwargs)[source]

Bases: argparse.ArgumentParser

This subclass of argparse.ArgumentParser uses type hints on dataclasses to generate arguments.

The class is designed to play well with the native argparse. In particular, you can add more (non-dataclass backed) arguments to the parser after initialization and you’ll get the output back after parsing as an additional namespace. Optional: To create sub argument groups use the _argument_group_name attribute in the dataclass.

parse_args_into_dataclasses(args=None, return_remaining_strings=False, look_for_args_file=True, args_filename=None)Tuple[DataClass, ][source]

Parse command-line args into instances of the specified dataclass types.

This relies on argparse’s ArgumentParser.parse_known_args. See the doc at:

  • args – List of strings to parse. The default is taken from sys.argv. (same as argparse.ArgumentParser)

  • return_remaining_strings – If true, also return a list of remaining argument strings.

  • look_for_args_file – If true, will look for a “.args” file with the same base name as the entry point script for this process, and will append its potential content to the command line args.

  • args_filename – If not None, will uses this file instead of the “.args” file specified in the previous argument.


  • the dataclass instances in the same order as they were passed to the initializer.abspath

  • if applicable, an additional namespace for more (non-dataclass backed) arguments added to the parser after initialization.

  • The potential list of remaining argument strings. (same as argparse.ArgumentParser.parse_known_args)

Return type

Tuple consisting of

parse_json_file(json_file: str)Tuple[DataClass, ][source]

Alternative helper method that does not use argparse at all, instead loading a json file and populating the dataclass types.

parse_dict(args: dict)Tuple[DataClass, ][source]

Alternative helper method that does not use argparse at all, instead uses a dict and populating the dataclass types.