Module

_importer

Application importer — resolves string references to ASGI callables.

Handles the standard "module:attribute" pattern used by ASGI servers:

"myapp:app"              → import myapp; return myapp.app
"myapp.web:app"          → import myapp.web; return myapp.web.app
"myapp:create_app()"     → import myapp; return myapp.create_app()

For development mode,reimport_app() clears project-local modules fromsys.modulesbefore re-importing, so that code changes on disk are picked up without a full process restart.

Functions

import_app 1 ASGIApp
Resolve an application string to an ASGI callable.
def import_app(app_path: str) -> ASGIApp
Parameters
Name Type Description
app_path str

Application reference in "module:attribute" format. Optionally, the attribute may end with "()" to call a factory.

Returns
ASGIApp
reimport_app 2 ASGIApp
Re-import an ASGI app, clearing cached local modules first. Evicts all ``sys.m…
def reimport_app(app_path: str, base_dirs: list[str] | None = None) -> ASGIApp

Re-import an ASGI app, clearing cached local modules first.

Evicts allsys.modulesentries whose source file lives under one of the base_dirs (defaults to the current working directory), then re-imports the application viaimport_app(). This forces Python to re-execute module source, picking up code changes saved since the last load.

Parameters
Name Type Description
app_path str

Application reference in"module:attribute"format.

base_dirs list[str] | None

Directories whose modules should be evicted from the module cache. Defaults to[os.getcwd()].

Default:None
Returns
ASGIApp
_clear_local_modules 1 list[str]
Remove project-local modules from ``sys.modules``. A module is considered "loc…
def _clear_local_modules(base_dirs: list[str] | None = None) -> list[str]

Remove project-local modules fromsys.modules.

A module is considered "local" when its__file__attribute resolves to a path under one of the base_dirs. Third-party packages (installed in site-packages) and the standard library are left untouched.

Parameters
Name Type Description
base_dirs list[str] | None

Directories to treat as project roots. Defaults to[os.getcwd()].

Default:None
Returns
list[str]