🏠 Home | ⚙️ API Reference | ⚙️ Settings API
⚙️ Settings API (Base Configuration)
This section describes the base configuration patterns used across Codex projects.
BaseCommonSettings
BaseCommonSettings is a Pydantic Settings model that handles Redis URLs and environment variable loading.
base
Environment-driven base settings shared across all codex_tools services.
Provides :class:BaseCommonSettings, the canonical superclass for
every application settings class in the codex_tools ecosystem (Django
web server, Telegram bot, async worker, CLI tool, etc.).
Design decisions:
- No automatic .env loading —
env_fileis intentionally absent from the basemodel_config. Each consuming project must overridemodel_configwith the project-local.envpath. This prevents the library from silently reading an unexpected file when imported. - Redis by default — Redis connection parameters are present at the base level because every codex_tools service uses Redis as a shared cache / broker. Services that do not use Redis can simply leave the defaults in place.
- Computed properties — :attr:
redis_url, :attr:is_production, and :attr:is_developmentare read-only properties rather than stored fields to ensure they are always derived from the current field values and cannot be set incorrectly via environment variables.
Usage::
from codex_core.settings import BaseCommonSettings
from pathlib import Path
from pydantic_settings import SettingsConfigDict
class BookingSettings(BaseCommonSettings):
calendar_api_key: str
model_config = SettingsConfigDict(
env_file=Path(__file__).parent / ".env",
env_file_encoding="utf-8",
extra="ignore",
)
settings = BookingSettings()
Classes
BaseCommonSettings
Bases: BaseSettings
Shared environment-driven settings for all codex_tools services.
Subclass this in each project and override model_config to
point at the project's .env file. All fields defined here
can be overridden via environment variables following pydantic-
settings conventions (upper-case, optional prefix).
Attributes:
| Name | Type | Description |
|---|---|---|
debug |
bool
|
When |
redis_host |
str
|
Hostname or IP of the Redis server. |
redis_port |
int
|
TCP port of the Redis server. |
redis_password |
str | None
|
Optional password for Redis AUTH. When set,
it is URL-encoded before being embedded in
:attr: |
redis_max_connections |
int
|
Maximum number of connections in the connection pool. |
redis_timeout |
int
|
Socket timeout in seconds for Redis operations. |
Note
model_config at this level intentionally omits env_file
so that child classes control which .env file is loaded.
Do not add env_file here.
Example
from codex_core.settings import BaseCommonSettings
from pathlib import Path
from pydantic_settings import SettingsConfigDict
class ProjectSettings(BaseCommonSettings):
my_api_key: str = "changeme"
model_config = SettingsConfigDict(
env_file=Path(__file__).parent / ".env",
env_file_encoding="utf-8",
extra="ignore",
)
settings = ProjectSettings()
print(settings.redis_url) # → "redis://localhost:6379"
print(settings.is_production) # → False (debug=True by default)
Source code in src/codex_core/settings/base.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
Attributes
is_development
property
Return True when the service is running in development mode.
Development mode is defined as debug=True (the default).
Convenience inverse of :attr:is_production.
Returns:
| Type | Description |
|---|---|
bool
|
|
is_production
property
Return True when the service is running in production mode.
Production mode is defined as debug=False. Use this
property in conditional code paths that must behave differently
in production (e.g. disabling detailed tracebacks in API
responses).
Returns:
| Type | Description |
|---|---|
bool
|
|
redis_url
property
Construct a Redis connection URL from the current field values.
Uses urllib.parse.quote_plus to percent-encode the password
so that special characters (@, /, #, etc.) do not
corrupt the URL structure.
Returns:
| Type | Description |
|---|---|
str
|
A |
str
|
|
str
|
|