Skip to content

fastapi_tools.params.env_type

Deployment environment type.

Classes:

EnvLocationType

Bases: Enum

Deployment environment location type.

Methods:

  • from_env_var

    Get the environment from the environment variable ENV_LOCATION_TYPE.

from_env_var classmethod

from_env_var(default_env: str = 'local') -> EnvLocationType

Get the environment from the environment variable ENV_LOCATION_TYPE.

Parameters:

  • default_env (str, default: 'local' ) –

    The default environment. Defaults to "local".

Returns:

Source code in src/fastapi_tools/params/env_type.py
@classmethod
def from_env_var(cls, default_env: str = "local") -> EnvLocationType:
    """Get the environment from the environment variable ``ENV_LOCATION_TYPE``.

    Args:
        default_env (str): The default environment.
            Defaults to "local".

    Returns:
        EnvLocationType: The environment type.
    """
    env = os.getenv("ENV_LOCATION_TYPE", default_env)
    lg.success(f"EnvLocationType: {env}")
    return EnvLocationType(env)

EnvStageType

Bases: Enum

Deployment environment stage type.

Methods:

  • from_env_var

    Get the environment from the environment variable ENV_STAGE_TYPE.

from_env_var classmethod

from_env_var(default_env: str = 'dev') -> EnvStageType

Get the environment from the environment variable ENV_STAGE_TYPE.

Parameters:

  • default_env (str, default: 'dev' ) –

    The default environment. Defaults to "dev".

Returns:

Source code in src/fastapi_tools/params/env_type.py
@classmethod
def from_env_var(cls, default_env: str = "dev") -> EnvStageType:
    """Get the environment from the environment variable ``ENV_STAGE_TYPE``.

    Args:
        default_env (str): The default environment.
            Defaults to "dev".

    Returns:
        EnvStageType: The environment type.
    """
    env = os.getenv("ENV_STAGE_TYPE", default_env)
    lg.success(f"EnvStageType: {env}")
    return EnvStageType(env)

EnvType dataclass

EnvType(stage: EnvStageType, location: EnvLocationType)

Deployment environment type.

Methods:

  • __str__

    Return the string representation of the environment.

  • from_env_var

    Initialize the environment from environment variables.

__str__

__str__() -> str

Return the string representation of the environment.

Source code in src/fastapi_tools/params/env_type.py
def __str__(self) -> str:
    """Return the string representation of the environment."""
    return f"EnvType: {self.stage.value}-{self.location.value}"

from_env_var classmethod

from_env_var() -> EnvType

Initialize the environment from environment variables.

Source code in src/fastapi_tools/params/env_type.py
@classmethod
def from_env_var(cls) -> EnvType:
    """Initialize the environment from environment variables."""
    stage = EnvStageType.from_env_var()
    location = EnvLocationType.from_env_var()
    return EnvType(stage, location)

UnknownEnvLocationError

UnknownEnvLocationError(location: EnvLocationType)

Bases: Exception

Raised when an unknown or unsupported environment location is encountered.

Parameters:

  • location (EnvLocationType) –

    the environment location that caused the error

Initialize with the invalid location.

Parameters:

Source code in src/fastapi_tools/params/env_type.py
def __init__(self, location: EnvLocationType) -> None:
    """Initialize with the invalid location.

    Args:
        location: The unknown environment location
    """
    self.location = location
    message = f"Unknown environment location: {location}"
    super().__init__(message)

UnknownEnvStageError

UnknownEnvStageError(stage: EnvStageType)

Bases: Exception

Raised when an unknown or unsupported environment stage is encountered.

Parameters:

  • stage (EnvStageType) –

    the environment stage that caused the error

Initialize with the invalid stage.

Parameters:

Source code in src/fastapi_tools/params/env_type.py
def __init__(self, stage: EnvStageType) -> None:
    """Initialize with the invalid stage.

    Args:
        stage: The unknown environment stage
    """
    self.stage = stage
    message = f"Unknown environment stage: {stage}"
    super().__init__(message)