Skip to content

fastapi_tools.params.fastapi_tools_params

FastapiTools project params.

Parameters are actual value of the config.

The class is a singleton, so it can be accessed from anywhere in the code.

There is a parameter regarding the environment type (stage and location), which is used to load different paths and other parameters based on the environment.

Classes:

Functions:

FastapiToolsParams

FastapiToolsParams()

FastapiTools project parameters.

Load the FastapiTools params.

Methods:

  • __repr__

    Return the string representation of the object.

  • __str__

    Return the string representation of the object.

  • load_config

    Load the fastapi_tools configuration.

  • set_env_type

    Set the environment type.

Source code in src/fastapi_tools/params/fastapi_tools_params.py
def __init__(self) -> None:
    """Load the FastapiTools params."""
    lg.info("Loading FastapiTools params")
    self.set_env_type()

__repr__

__repr__() -> str

Return the string representation of the object.

Source code in src/fastapi_tools/params/fastapi_tools_params.py
def __repr__(self) -> str:
    """Return the string representation of the object."""
    return str(self)

__str__

__str__() -> str

Return the string representation of the object.

Source code in src/fastapi_tools/params/fastapi_tools_params.py
def __str__(self) -> str:
    """Return the string representation of the object."""
    s = "FastapiToolsParams:"
    s += f"\n{self.paths}"
    s += f"\n{self.sample}"
    return s

load_config

load_config() -> None

Load the fastapi_tools configuration.

Source code in src/fastapi_tools/params/fastapi_tools_params.py
def load_config(self) -> None:
    """Load the fastapi_tools configuration."""
    self.paths = FastapiToolsPaths(env_type=self.env_type)
    self.sample = SampleParams()

set_env_type

set_env_type(env_type: EnvType | None = None) -> None

Set the environment type.

Parameters:

  • env_type (EnvType | None, default: None ) –

    The environment type. If None, it will be set from the environment variables. Defaults to None.

Source code in src/fastapi_tools/params/fastapi_tools_params.py
def set_env_type(self, env_type: EnvType | None = None) -> None:
    """Set the environment type.

    Args:
        env_type (EnvType | None): The environment type.
            If None, it will be set from the environment variables.
            Defaults to None.
    """
    if env_type is not None:
        self.env_type = env_type
    else:
        self.env_type = EnvType.from_env_var()
    self.load_config()

get_fastapi_tools_params

get_fastapi_tools_params() -> FastapiToolsParams

Get the fastapi_tools params.

Source code in src/fastapi_tools/params/fastapi_tools_params.py
def get_fastapi_tools_params() -> FastapiToolsParams:
    """Get the fastapi_tools params."""
    return FastapiToolsParams()

get_fastapi_tools_paths

get_fastapi_tools_paths() -> FastapiToolsPaths

Get the fastapi_tools paths.

Source code in src/fastapi_tools/params/fastapi_tools_params.py
def get_fastapi_tools_paths() -> FastapiToolsPaths:
    """Get the fastapi_tools paths."""
    return get_fastapi_tools_params().paths