Skip to content

settings

PixelApiSettings

Bases: BaseSettings

Settings for the Pixel API client

Source code in src/pixel_client/settings.py
13
14
15
16
17
18
19
20
21
22
23
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
class PixelApiSettings(BaseSettings):
    """
    Settings for the Pixel API client
    """

    @classmethod
    def from_env_file(cls, env_file: Path | str) -> "PixelApiSettings":
        """Instantiate the settings from an environment file.

        Warning:
            Environment variables will always take precedence over the values in the file.
        """
        return cls(_env_file=env_file)  # type: ignore

    model_config = SettingsConfigDict(frozen=True, extra="ignore")  # Makes it hashable



    PIXEL_ENV: Literal["dev", "test", "prod"] = Field(validation_alias=pixel_env_choices, default="prod")

    PIXEL_USERNAME: str = Field(validation_alias=pixel_username_choices)
    """The client secret for the Keycloak server"""

    PIXEL_PASSWORD: SecretStr = Field(validation_alias=pixel_password_choices)
    """The password for the Keycloak"""

    PIXEL_TENANT: str = Field(validation_alias=pixel_realm_choices)
    """The realm for the Keycloak server"""

    PIXEL_SERVER_URL_OVERRIDE: str | None = Field(alias="PIXEL_SERVER_URL", default=None)
    PIXEL_API_URL_OVERRIDE: str | None = Field(alias="PIXEL_API_URL", default=None)

    @property
    def PIXEL_CLIENT_ID(self):
        return "frontend"


    @property
    def PIXEL_REALM(self):
        return self.PIXEL_TENANT.capitalize()

    @property
    def PIXEL_API_URL(self): 
        return self.PIXEL_API_URL_OVERRIDE or f"https://{self.PIXEL_ENV}.api.geodatapixel.no/{self.PIXEL_REALM.lower()}"

    @property
    def PIXEL_SERVER_URL(self):
        return self.PIXEL_SERVER_URL_OVERRIDE or f"https://{self.PIXEL_ENV}.keycloak.geodatapixel.no"

    PIXEL_CLIENT_NO_VERSION_CHECK: bool = False
    """If True, the client will not check for a newer version of the pixel-client package on startup."""

PIXEL_ENV class-attribute instance-attribute

PIXEL_ENV: Literal["dev", "test", "prod"] = Field(
    validation_alias=pixel_env_choices, default="prod"
)

PIXEL_USERNAME class-attribute instance-attribute

PIXEL_USERNAME: str = Field(
    validation_alias=pixel_username_choices
)

The client secret for the Keycloak server

PIXEL_PASSWORD class-attribute instance-attribute

PIXEL_PASSWORD: SecretStr = Field(
    validation_alias=pixel_password_choices
)

The password for the Keycloak

PIXEL_TENANT class-attribute instance-attribute

PIXEL_TENANT: str = Field(
    validation_alias=pixel_realm_choices
)

The realm for the Keycloak server

PIXEL_SERVER_URL_OVERRIDE class-attribute instance-attribute

PIXEL_SERVER_URL_OVERRIDE: str | None = Field(
    alias="PIXEL_SERVER_URL", default=None
)

PIXEL_API_URL_OVERRIDE class-attribute instance-attribute

PIXEL_API_URL_OVERRIDE: str | None = Field(
    alias="PIXEL_API_URL", default=None
)

PIXEL_CLIENT_ID property

PIXEL_CLIENT_ID

PIXEL_REALM property

PIXEL_REALM

PIXEL_API_URL property

PIXEL_API_URL

PIXEL_SERVER_URL property

PIXEL_SERVER_URL

PIXEL_CLIENT_NO_VERSION_CHECK class-attribute instance-attribute

PIXEL_CLIENT_NO_VERSION_CHECK: bool = False

If True, the client will not check for a newer version of the pixel-client package on startup.

from_env_file classmethod

from_env_file(env_file: Path | str) -> PixelApiSettings

Instantiate the settings from an environment file.

Warning

Environment variables will always take precedence over the values in the file.

Source code in src/pixel_client/settings.py
18
19
20
21
22
23
24
25
@classmethod
def from_env_file(cls, env_file: Path | str) -> "PixelApiSettings":
    """Instantiate the settings from an environment file.

    Warning:
        Environment variables will always take precedence over the values in the file.
    """
    return cls(_env_file=env_file)  # type: ignore