Skip to content

Configuration

Purpose

This page documents the Gipity configuration module.

The configuration module centralizes environment-variable handling, filesystem paths, runtime constants, model lists, prompt constants, API key lookup, logging configuration, and application-level defaults.

Responsibilities

config.py is responsible for:

  • Reading environment variables.
  • Normalizing Boolean, integer, floating-point, text, and path values.
  • Defining application paths.
  • Defining OpenAI and Google service key variables.
  • Defining model options and workflow constants.
  • Defining local database and logging paths.
  • Providing constants used by the Streamlit application and provider wrappers.

API Reference

config


Assembly:                Gipity
Filename:                config.md
Author:                  Terry D. Eppler
Created:                 05-31-2022

Last Modified By:        Terry D. Eppler
Last Modified On:        05-01-2025

       config.md
       Copyright ©  2022  Terry Eppler

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You can contact me at: terryeppler@gmail.com or eppler.terry@epa.gov

config.md

throw_if

throw_if(name: str, value: object) -> None

Validate that a required value is present.

Purpose

Provides a compact guard for required arguments and configuration values. A value is considered invalid when it evaluates to false in Python.

Parameters:

Name Type Description Default
name str

Name of the argument or configuration value being validated.

required
value object

Value to validate.

required

Raises:

Type Description
ValueError

Raised when value is falsy.

Source code in config.py
def throw_if( name: str, value: object ) -> None:
	"""Validate that a required value is present.

	Purpose:
	    Provides a compact guard for required arguments and configuration values. A value is
	    considered invalid when it evaluates to false in Python.

	Args:
	    name (str): Name of the argument or configuration value being validated.
	    value (object): Value to validate.

	Raises:
	    ValueError: Raised when ``value`` is falsy.
	"""
	if not value:
		raise ValueError( f'Argument "{name}" cannot be empty!' )

get_bool

get_bool(name: str, default: bool = False) -> bool

Read a Boolean environment variable.

Purpose

Converts environment-variable text into a deterministic Boolean value. Missing variables return the caller-provided default. Values of 1, true, yes, y, and on are treated as True; all other defined values are treated as False.

Parameters:

Name Type Description Default
name str

Environment variable name.

required
default bool

Default value used when the environment variable is not defined.

False

Returns:

Name Type Description
bool bool

Parsed Boolean value, or default when the variable is missing or parsing

bool

fails.

Source code in config.py
def get_bool( name: str, default: bool = False ) -> bool:
	"""Read a Boolean environment variable.

	Purpose:
	    Converts environment-variable text into a deterministic Boolean value. Missing
	    variables return the caller-provided default. Values of ``1``, ``true``, ``yes``,
	    ``y``, and ``on`` are treated as ``True``; all other defined values are treated as
	    ``False``.

	Args:
	    name (str): Environment variable name.
	    default (bool): Default value used when the environment variable is not defined.

	Returns:
	    bool: Parsed Boolean value, or ``default`` when the variable is missing or parsing
	    fails.
	"""
	try:
		throw_if( 'name', name )
		value = os.getenv( name )
		return default if value is None else value.strip( ).lower( ) in (
				'1',
				'true',
				'yes',
				'y',
				'on'
		)
	except Exception:
		return default

get_int

get_int(name: str, default: int) -> int

Read an integer environment variable.

Purpose

Parses an optional environment variable as an integer while preserving a safe default when the variable is missing, empty, or invalid.

Parameters:

Name Type Description Default
name str

Environment variable name.

required
default int

Default integer value used when parsing is not possible.

required

Returns:

Name Type Description
int int

Parsed integer value, or default when parsing fails.

Source code in config.py
def get_int( name: str, default: int ) -> int:
	"""Read an integer environment variable.

	Purpose:
	    Parses an optional environment variable as an integer while preserving a safe default
	    when the variable is missing, empty, or invalid.

	Args:
	    name (str): Environment variable name.
	    default (int): Default integer value used when parsing is not possible.

	Returns:
	    int: Parsed integer value, or ``default`` when parsing fails.
	"""
	try:
		throw_if( 'name', name )
		value = os.getenv( name )
		return default if value in (None, '') else int( str( value ).strip( ) )
	except Exception:
		return default

get_float

get_float(name: str, default: float) -> float

Read a floating-point environment variable.

Purpose

Parses an optional environment variable as a float while preserving a safe default when the variable is missing, empty, or invalid.

Parameters:

Name Type Description Default
name str

Environment variable name.

required
default float

Default floating-point value used when parsing is not possible.

required

Returns:

Name Type Description
float float

Parsed floating-point value, or default when parsing fails.

Source code in config.py
def get_float( name: str, default: float ) -> float:
	"""Read a floating-point environment variable.

	Purpose:
	    Parses an optional environment variable as a float while preserving a safe default
	    when the variable is missing, empty, or invalid.

	Args:
	    name (str): Environment variable name.
	    default (float): Default floating-point value used when parsing is not possible.

	Returns:
	    float: Parsed floating-point value, or ``default`` when parsing fails.
	"""
	try:
		throw_if( 'name', name )
		value = os.getenv( name )
		return default if value in (None, '') else float( str( value ).strip( ) )
	except Exception:
		return default

get_path

get_path(name: str, default: Path) -> Path

Read a path environment variable.

Purpose

Resolves optional filesystem configuration from the environment. Missing variables return the resolved default path. Invalid values return the resolved default path rather than interrupting module import.

Parameters:

Name Type Description Default
name str

Environment variable name.

required
default Path

Default path used when the environment variable is not defined.

required

Returns:

Name Type Description
Path Path

Resolved path value, or the resolved default path.

Source code in config.py
def get_path( name: str, default: Path ) -> Path:
	"""Read a path environment variable.

	Purpose:
	    Resolves optional filesystem configuration from the environment. Missing variables
	    return the resolved default path. Invalid values return the resolved default path
	    rather than interrupting module import.

	Args:
	    name (str): Environment variable name.
	    default (Path): Default path used when the environment variable is not defined.

	Returns:
	    Path: Resolved path value, or the resolved default path.
	"""
	try:
		throw_if( 'name', name )
		throw_if( 'default', default )
		value = os.getenv( name )
		return Path( value ).resolve( ) if value else default.resolve( )
	except Exception:
		return default.resolve( )

get_text

get_text(name: str, default: str) -> str

Read a text environment variable.

Purpose

Returns an environment variable as text while preserving the supplied default when the variable is missing or empty.

Parameters:

Name Type Description Default
name str

Environment variable name.

required
default str

Default text value.

required

Returns:

Name Type Description
str str

Environment value, or default when the variable is missing or empty.

Source code in config.py
def get_text( name: str, default: str ) -> str:
	"""Read a text environment variable.

	Purpose:
	    Returns an environment variable as text while preserving the supplied default when
	    the variable is missing or empty.

	Args:
	    name (str): Environment variable name.
	    default (str): Default text value.

	Returns:
	    str: Environment value, or ``default`` when the variable is missing or empty.
	"""
	try:
		throw_if( 'name', name )
		value = os.getenv( name )
		return default if value in (None, '') else str( value )
	except Exception:
		return default