Home / Function/ run() — flask Function Reference

run() — flask Function Reference

Architecture documentation for the run() function in app.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  bd6f23cb_dba0_e4d4_5806_2956f407d349["run()"]
  9f8cc56e_d5c4_e7a8_438a_3124c0dd5de5["Flask"]
  bd6f23cb_dba0_e4d4_5806_2956f407d349 -->|defined in| 9f8cc56e_d5c4_e7a8_438a_3124c0dd5de5
  36bfda2d_4c0b_0fa1_7108_9f786fa1b2bc["get_load_dotenv()"]
  bd6f23cb_dba0_e4d4_5806_2956f407d349 -->|calls| 36bfda2d_4c0b_0fa1_7108_9f786fa1b2bc
  aa03072d_fb08_de41_1ce0_535b2a2f9d00["get_debug_flag()"]
  bd6f23cb_dba0_e4d4_5806_2956f407d349 -->|calls| aa03072d_fb08_de41_1ce0_535b2a2f9d00
  c1644887_6834_cf5b_9551_6a1aa07a77d7["get()"]
  bd6f23cb_dba0_e4d4_5806_2956f407d349 -->|calls| c1644887_6834_cf5b_9551_6a1aa07a77d7
  25bac11e_b768_4e46_78ef_bee02f544a58["setdefault()"]
  bd6f23cb_dba0_e4d4_5806_2956f407d349 -->|calls| 25bac11e_b768_4e46_78ef_bee02f544a58
  style bd6f23cb_dba0_e4d4_5806_2956f407d349 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/app.py lines 631–752

    def run(
        self,
        host: str | None = None,
        port: int | None = None,
        debug: bool | None = None,
        load_dotenv: bool = True,
        **options: t.Any,
    ) -> None:
        """Runs the application on a local development server.

        Do not use ``run()`` in a production setting. It is not intended to
        meet security and performance requirements for a production server.
        Instead, see :doc:`/deploying/index` for WSGI server recommendations.

        If the :attr:`debug` flag is set the server will automatically reload
        for code changes and show a debugger in case an exception happened.

        If you want to run the application in debug mode, but disable the
        code execution on the interactive debugger, you can pass
        ``use_evalex=False`` as parameter.  This will keep the debugger's
        traceback screen active, but disable code execution.

        It is not recommended to use this function for development with
        automatic reloading as this is badly supported.  Instead you should
        be using the :command:`flask` command line script's ``run`` support.

        .. admonition:: Keep in Mind

           Flask will suppress any server error with a generic error page
           unless it is in debug mode.  As such to enable just the
           interactive debugger without the code reloading, you have to
           invoke :meth:`run` with ``debug=True`` and ``use_reloader=False``.
           Setting ``use_debugger`` to ``True`` without being in debug mode
           won't catch any exceptions because there won't be any to
           catch.

        :param host: the hostname to listen on. Set this to ``'0.0.0.0'`` to
            have the server available externally as well. Defaults to
            ``'127.0.0.1'`` or the host in the ``SERVER_NAME`` config variable
            if present.
        :param port: the port of the webserver. Defaults to ``5000`` or the
            port defined in the ``SERVER_NAME`` config variable if present.
        :param debug: if given, enable or disable debug mode. See
            :attr:`debug`.
        :param load_dotenv: Load the nearest :file:`.env` and :file:`.flaskenv`
            files to set environment variables. Will also change the working
            directory to the directory containing the first file found.
        :param options: the options to be forwarded to the underlying Werkzeug
            server. See :func:`werkzeug.serving.run_simple` for more
            information.

        .. versionchanged:: 1.0
            If installed, python-dotenv will be used to load environment
            variables from :file:`.env` and :file:`.flaskenv` files.

            The :envvar:`FLASK_DEBUG` environment variable will override :attr:`debug`.

            Threaded mode is enabled by default.

        .. versionchanged:: 0.10
            The default port is now picked from the ``SERVER_NAME``
            variable.
        """
        # Ignore this call so that it doesn't start another server if
        # the 'flask run' command is used.
        if os.environ.get("FLASK_RUN_FROM_CLI") == "true":
            if not is_running_from_reloader():
                click.secho(
                    " * Ignoring a call to 'app.run()' that would block"
                    " the current 'flask' CLI command.\n"
                    "   Only call 'app.run()' in an 'if __name__ =="
                    ' "__main__"\' guard.',
                    fg="red",
                )

            return

        if get_load_dotenv(load_dotenv):
            cli.load_dotenv()

            # if set, env var overrides existing value

Subdomains

Defined In

Frequently Asked Questions

What does run() do?
run() is a function in the flask codebase, defined in src/flask/app.py.
Where is run() defined?
run() is defined in src/flask/app.py at line 631.
What does run() call?
run() calls 4 function(s): get, get_debug_flag, get_load_dotenv, setdefault.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free