Skip to content

config

mlte/backend/core/config.py

Configuration management for FastAPI application.

Settings

Bases: BaseSettings

The BaseSettings class from pydantic automatically manages reading environment variables from the environment or a .env file if configured properly.

Source code in mlte/backend/core/config.py
24
25
26
27
28
29
30
31
32
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class Settings(BaseSettings):
    """
    The BaseSettings class from pydantic automatically manages
    reading environment variables from the environment or a
    .env file if configured properly.
    """

    ENVIRONMENT: str = "default"
    """Used to check the type of settings being used."""

    API_PREFIX: str = "/api"
    """The global API prefix."""

    BACKEND_HOST: str = "localhost"
    """The host to which the server binds."""

    BACKEND_PORT: str = "8080"
    """The port to which the server binds."""

    @field_validator("BACKEND_PORT", mode="before")
    @classmethod
    def validate_app_port(cls, v: str) -> str:
        try:
            int(v)
        except ValueError:
            raise ValueError(
                f"Failed to parse int from BACKEND_PORT: {v}."
            ) from None
        return v

    STORE_URI: str = StoreURI.get_default_prefix(StoreType.LOCAL_MEMORY)
    """The store URI string; defaults to in-memory store."""

    CATALOG_URIS: Dict[str, str] = {
        "local": StoreURI.get_default_prefix(StoreType.LOCAL_MEMORY)
    }
    """The dict of catalog URI strings; defaults to one in-memory store."""

    LOG_LEVEL: str = "ERROR"
    """The application log level; defaults to ERROR."""

    @field_validator("LOG_LEVEL", mode="before")
    @classmethod
    def validate_log_level(cls, v: str) -> str:
        if v not in _LOG_LEVELS:
            raise ValueError(f"Unsupported log level: {v}.")
        return v

    ALLOWED_ORIGINS: List[str] = [
        DEFAULT_FRONTEND_ADDRESS,
        DEFAULT_DEV_FRONTEND_ADDRESS,
    ]
    """A list of allowed CORS origins."""

    JWT_SECRET_KEY: str = (
        "399fd92f61c99e35d7f2f6fdb9d65293c4047f9ac500af1886b8868b495f20b3"
    )
    """The secret key used to encode/decode JWT tokens."""

    model_config = SettingsConfigDict(
        case_sensitive=True, env_file=".env.backend"
    )

ALLOWED_ORIGINS = [DEFAULT_FRONTEND_ADDRESS, DEFAULT_DEV_FRONTEND_ADDRESS] class-attribute instance-attribute

A list of allowed CORS origins.

API_PREFIX = '/api' class-attribute instance-attribute

The global API prefix.

BACKEND_HOST = 'localhost' class-attribute instance-attribute

The host to which the server binds.

BACKEND_PORT = '8080' class-attribute instance-attribute

The port to which the server binds.

CATALOG_URIS = {'local': StoreURI.get_default_prefix(StoreType.LOCAL_MEMORY)} class-attribute instance-attribute

The dict of catalog URI strings; defaults to one in-memory store.

ENVIRONMENT = 'default' class-attribute instance-attribute

Used to check the type of settings being used.

JWT_SECRET_KEY = '399fd92f61c99e35d7f2f6fdb9d65293c4047f9ac500af1886b8868b495f20b3' class-attribute instance-attribute

The secret key used to encode/decode JWT tokens.

LOG_LEVEL = 'ERROR' class-attribute instance-attribute

The application log level; defaults to ERROR.

STORE_URI = StoreURI.get_default_prefix(StoreType.LOCAL_MEMORY) class-attribute instance-attribute

The store URI string; defaults to in-memory store.