Skip to content

main

Application factory

This module sets up the FastAPI application that serves the Fractal Server.

check_settings()

Check and register the settings

Verify the consistency of the settings, in particular that required variables are set.

Raises:

Type Description
ValidationError

If the configuration is invalid.

Source code in fractal_server/main.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def check_settings() -> None:
    """
    Check and register the settings

    Verify the consistency of the settings, in particular that required
    variables are set.

    Raises:
        ValidationError: If the configuration is invalid.
    """
    settings = Inject(get_settings)
    settings.check()

    logger = set_logger("fractal_server_settings")
    logger.debug("Fractal Settings:")
    for key, value in settings.dict().items():
        if any(s in key.upper() for s in ["PASSWORD", "SECRET"]):
            value = "*****"
        logger.debug(f"  {key}: {value}")
    reset_logger_handlers(logger)

collect_routers(app)

Register the routers to the application

Parameters:

Name Type Description Default
app FastAPI

The application to register the routers to.

required
Source code in fractal_server/main.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def collect_routers(app: FastAPI) -> None:
    """
    Register the routers to the application

    Args:
        app:
            The application to register the routers to.
    """
    from .app.routes.api import router_api
    from .app.routes.api.v1 import router_api_v1
    from .app.routes.api.v2 import router_api_v2
    from .app.routes.admin.v1 import router_admin_v1
    from .app.routes.admin.v2 import router_admin_v2
    from .app.routes.auth.router import router_auth

    settings = Inject(get_settings)

    app.include_router(router_api, prefix="/api")
    if settings.FRACTAL_API_V1_MODE.startswith("include"):
        app.include_router(router_api_v1, prefix="/api/v1")
        app.include_router(
            router_admin_v1, prefix="/admin/v1", tags=["V1 Admin area"]
        )
    app.include_router(router_api_v2, prefix="/api/v2")
    app.include_router(
        router_admin_v2, prefix="/admin/v2", tags=["V2 Admin area"]
    )
    app.include_router(router_auth, prefix="/auth", tags=["Authentication"])

start_application()

Create the application, initialise it and collect all available routers.

Returns:

Name Type Description
app FastAPI

The fully initialised application.

Source code in fractal_server/main.py
148
149
150
151
152
153
154
155
156
157
158
def start_application() -> FastAPI:
    """
    Create the application, initialise it and collect all available routers.

    Returns:
        app:
            The fully initialised application.
    """
    app = FastAPI(lifespan=lifespan)
    collect_routers(app)
    return app