module documentation

Undocumented

Class AppGroup This works similar to a regular click :class:`~click.Group` but it changes the behavior of the :meth:`command` decorator so that it automatically wraps the functions in :func:`with_appcontext`.
Class CertParamType Click option type for the ``--cert`` option. Allows either an existing file, the string ``'adhoc'``, or an import for a :class:`~ssl.SSLContext` object.
Class FlaskGroup Special subclass of the :class:`AppGroup` group that supports loading more commands from the configured Flask app. Normally a developer does not have to interface with this class but there are some very advanced use cases for which it makes sense to create an instance of this...
Class NoAppException Raised if an application cannot be found or loaded.
Class ScriptInfo Helper object to deal with Flask applications. This is usually not necessary to interface with as it's used internally in the dispatching to click. In future versions of Flask this object will most likely play a bigger role...
Class SeparatedPathType Click option type that accepts a list of values separated by the OS's path separator (``:``, ``;`` on Windows). Each value is validated as a :class:`click.Path` type.
Function find_app_by_string Check if the given string is a variable name or a function. Call a function to get the app instance, or return the variable directly.
Function find_best_app Given a module instance this tries to find the best possible application in the module or raises an exception.
Function get_version Undocumented
Function load_dotenv Load "dotenv" files in order of precedence to set environment variables.
Function locate_app Undocumented
Function main Undocumented
Function prepare_import 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.
Function routes_command Show all registered routes with endpoints and methods.
Function run_command Run a local development server.
Function shell_command Run an interactive Python shell in the context of a given Flask application. The application will populate the default namespace of this shell according to its configuration.
Function show_server_banner Show extra startup messages the first time the server is run, ignoring the reloader.
Function with_appcontext Wraps a callback so that it's guaranteed to be executed with the script's application context.
Variable cli Undocumented
Variable pass_script_info Undocumented
Variable version_option Undocumented
Function _called_with_wrong_args Check whether calling a function raised a ``TypeError`` because the call failed or because something in the factory raised the error.
Function _env_file_callback Undocumented
Function _path_is_ancestor Take ``other`` and remove the length of ``path`` from it. Then join it to ``path``. If it is the original value, ``path`` is an ancestor of ``other``.
Function _set_app Undocumented
Function _set_debug Undocumented
Function _validate_key The ``--key`` option must be specified when ``--cert`` is a file. Modifies the ``cert`` param to be a ``(cert, key)`` pair if needed.
Variable _app_option Undocumented
Variable _debug_option Undocumented
Variable _env_file_option Undocumented
def find_app_by_string(module, app_name): (source)

Check if the given string is a variable name or a function. Call a function to get the app instance, or return the variable directly.

def find_best_app(module): (source)

Given a module instance this tries to find the best possible application in the module or raises an exception.

def get_version(ctx, param, value): (source)

Undocumented

def load_dotenv(path: (str|os.PathLike)|None = None) -> bool: (source)

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. .. versionchanged:: 2.0 The current directory is not changed to the location of the loaded file. .. versionchanged:: 2.0 When loading the env files, set the default encoding to UTF-8. .. versionchanged:: 1.1.0 Returns ``False`` when python-dotenv is not installed, or when the given path isn't a file. .. versionadded:: 1.0

def locate_app(module_name, app_name, raise_if_not_found=True): (source)

Undocumented

def main(): (source)

Undocumented

def prepare_import(path): (source)

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.

@click.command('routes', short_help='Show the routes for the app.')
@click.option('--sort', '-s', type=click.Choice(('endpoint', 'methods', 'rule', 'match')), default='endpoint', help='Method to sort routes by. "match" is the order that Flask will match routes when dispatching a request.')
@click.option('--all-methods', is_flag=True, help='Show HEAD and OPTIONS methods.')
@with_appcontext
def routes_command(sort: str, all_methods: bool): (source)

Show all registered routes with endpoints and methods.

@click.command('run', short_help='Run a development server.')
@click.option('--host', '-h', default='127.0.0.1', help='The interface to bind to.')
@click.option('--port', '-p', default=5000, help='The port to bind to.')
@click.option('--cert', type=CertParamType(), help='Specify a certificate file to use HTTPS.', is_eager=True)
@click.option('--key', type=click.Path(exists=True, dir_okay=False, resolve_path=True), callback=_validate_key, expose_value=False, help='The key file to use when specifying a certificate.')
@click.option('--reload/--no-reload', default=None, help='Enable or disable the reloader. By default the reloader is active if debug is enabled.')
@click.option('--debugger/--no-debugger', default=None, help='Enable or disable the debugger. By default the debugger is active if debug is enabled.')
@click.option('--with-threads/--without-threads', default=True, help='Enable or disable multithreading.')
@click.option('--extra-files', default=None, type=SeparatedPathType(), help=f"""Extra files that trigger a reload on change. Multiple paths are separated by {os.path.pathsep!r}.""")
@click.option('--exclude-patterns', default=None, type=SeparatedPathType(), help=f"""Files matching these fnmatch patterns will not trigger a reload on change. Multiple patterns are separated by {os.path.pathsep!r}.""")
@pass_script_info
def run_command(info, host, port, reload, debugger, with_threads, cert, extra_files, exclude_patterns): (source)

Run a local development server. This server is for development purposes only. It does not provide the stability, security, or performance of production WSGI servers. The reloader and debugger are enabled by default with the '--debug' option.

@click.command('shell', short_help='Run a shell in the app context.')
@with_appcontext
def shell_command(): (source)

Run an interactive Python shell in the context of a given Flask application. The application will populate the default namespace of this shell according to its configuration. This is useful for executing small snippets of management code without having to manually configure the application.

def show_server_banner(debug, app_import_path): (source)

Show extra startup messages the first time the server is run, ignoring the reloader.

def with_appcontext(f): (source)

Wraps a callback so that it's guaranteed to be executed with the script's application context. Custom commands (and their options) registered under ``app.cli`` or ``blueprint.cli`` will always have an app context available, this decorator is not required in that case. .. versionchanged:: 2.2 The app context is active for subcommands as well as the decorated callback. The app context is always available to ``app.cli`` command and parameter callbacks.

Undocumented

pass_script_info = (source)

Undocumented

version_option = (source)

Undocumented

def _called_with_wrong_args(f): (source)

Check whether calling a function raised a ``TypeError`` because the call failed or because something in the factory raised the error. :param f: The function that was called. :return: ``True`` if the call failed.

def _env_file_callback(ctx: click.Context, param: click.Option, value: str|None) -> str|None: (source)

Undocumented

def _path_is_ancestor(path, other): (source)

Take ``other`` and remove the length of ``path`` from it. Then join it to ``path``. If it is the original value, ``path`` is an ancestor of ``other``.

def _set_app(ctx: click.Context, param: click.Option, value: str|None) -> str|None: (source)

Undocumented

def _set_debug(ctx: click.Context, param: click.Option, value: bool) -> bool|None: (source)

Undocumented

def _validate_key(ctx, param, value): (source)

The ``--key`` option must be specified when ``--cert`` is a file. Modifies the ``cert`` param to be a ``(cert, key)`` pair if needed.

_app_option = (source)

Undocumented

_debug_option = (source)

Undocumented

_env_file_option = (source)

Undocumented