Index
template_python ¶
Core initialization module for the template-python package.
This module serves as the primary entry point for the library, exposing the public API components such as logging settings, application configuration, and version metadata for convenient access by downstream consumers.
LoggingSettings ¶
Bases: BaseSettings
Settings model for configuring the loguru logging infrastructure.
This Pydantic model loads configuration from environment variables prefixed with TEMPLATE_PYTHON__LOGGING__ and provides typed fields for controlling log output, formatting, and OpenTelemetry integration.
Example: .. code-block:: python
from template_python.logging import LoggingSettings, configure_logger
settings = LoggingSettings(enabled=True, level="DEBUG")
configure_logger(settings)
Source code in src/template_python/logging.py
model_config = SettingsConfigDict(env_prefix='TEMPLATE_PYTHON__LOGGING__', env_nested_delimiter='__') class-attribute ¶
Pydantic configuration dict dictating environment variable prefixes.
Settings ¶
Bases: BaseSettings
Configuration state for the application.
This class aggregates and prioritizes configuration from multiple sources, providing a unified state for the application. It is built on top of pydantic-settings to allow validation, default values, and type coercion.
Example: .. code-block:: python
from template_python.settings import Settings
settings = Settings(environment="production")
print(settings.project_root)
Source code in src/template_python/settings.py
model_config = SettingsConfigDict(arbitrary_types_allowed=True, extra='ignore', populate_by_name=True, validate_assignment=True, env_prefix='TEMPLATE_PYTHON__') class-attribute ¶
Pydantic config dict dictating environment prefixes and validation.
__repr__() ¶
Return a detailed string representation of the settings.
Returns:
| Type | Description |
|---|---|
str | A detailed string representation suitable for debugging. |
Source code in src/template_python/settings.py
__str__() ¶
Return a concise string representation of the settings.
Returns:
| Type | Description |
|---|---|
str | A concise, human-readable string summary of the settings. |
Source code in src/template_python/settings.py
configure_logger(settings=None) ¶
Initializes the loguru logger with the provided settings or from the environment.
This function configures the global loguru logger instance based on the provided LoggingSettings. It handles enabling/disabling the logger, managing sinks, and injecting the appropriate formatter (including OpenTelemetry).
Example: .. code-block:: python
from template_python.logging import configure_logger, LoggingSettings
configure_logger(LoggingSettings(level="DEBUG"))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings | LoggingSettings | None | An optional instance of | None |
Returns:
| Type | Description |
|---|---|
None | None |
Raises:
| Type | Description |
|---|---|
ImportError | If OpenTelemetry formatting is explicitly enabled but the package is not installed. |