quart.cli module

class quart.cli.AppGroup(name: Optional[str] = None, commands: Optional[Union[Dict[str, Command], Sequence[Command]]] = None, **attrs: Any)

Bases: Group

This works similar to a regular click Group but it changes the behavior of the command() decorator so that it automatically wraps the functions in with_appcontext().

Not to be confused with QuartGroup.

command(*args: Any, **kwargs: Any) Callable

This works exactly like the method of the same name on a regular click.Group but it wraps callbacks in with_appcontext() if it’s enabled by passing with_appcontext=True.

group(*args: Any, **kwargs: Any) Callable

A shortcut decorator for declaring and attaching a group to the group. This takes the same arguments as group() and immediately registers the created group with this group by calling add_command().

To customize the group class used, set the group_class attribute.

Changed in version 8.0: Added the group_class attribute.

exception quart.cli.NoAppException(message: str, ctx: Optional[Context] = None)

Bases: UsageError

class quart.cli.QuartGroup(add_default_commands: bool = True, create_app: Callable[..., Quart] | None = None, add_version_option: bool = True, load_dotenv: bool = True, set_debug_flag: bool = True, **extra: Any)

Bases: AppGroup

get_command(ctx: Context, name: str) Command

Given a context and a command name, this returns a Command object if it exists or returns None.

list_commands(ctx: Context) List[str]

Returns a list of subcommand names in the order they should appear.

make_context(info_name: str | None, args: list[str], parent: click.core.Context | None = None, **extra: Any) Context

This function when given an info name and arguments will kick off the parsing and create a new Context. It does not invoke the actual command callback though.

To quickly customize the context class used without overriding this method, set the context_class attribute.

Parameters
  • info_name – the info name for this invocation. Generally this is the most descriptive name for the script or command. For the toplevel script it’s usually the name of the script, for commands below it it’s the name of the command.

  • args – the arguments to parse as list of strings.

  • parent – the parent context if available.

  • extra – extra keyword arguments forwarded to the context constructor.

Changed in version 8.0: Added the context_class attribute.

parse_args(ctx: Context, args: list[str]) list[str]

Given a context and a list of arguments this creates the parser and parses the arguments, then modifies the context as necessary. This is automatically invoked by make_context().

class quart.cli.ScriptInfo(app_import_path: Optional[str] = None, create_app: Optional[Callable[..., Quart]] = None, set_debug_flag: bool = True)

Bases: object

load_app() Quart
quart.cli.find_app_by_string(module: ModuleType, app_name: str) Quart
quart.cli.find_best_app(module: ModuleType) Quart
quart.cli.get_version(ctx: Any, param: Any, value: Any) None
quart.cli.load_dotenv(path: str | os.PathLike | None = None) bool

Load “dotenv” files in order of precedence to set environment variables. If an env var is already set it is not overwritten, so earlier files in the list are preferred over later files. This is a no-op if `python-dotenv`_ is not installed. .. _python-dotenv: https://github.com/theskumar/python-dotenv#readme :param path: Load the file at this location instead of searching. :return: True if a file was loaded.

quart.cli.locate_app(module_name: str, app_name: str) Optional[Quart]
quart.cli.main() None
quart.cli.prepare_import(path: str) str

Given a filename this will try to calculate the python path, add it to the search path and return the actual module name that is expected.

quart.cli.with_appcontext(fn: Optional[Callable] = None) Callable