YAML Configuration
Lexigram uses a hierarchical configuration system that merges user-defined YAML files, environment variables, and code defaults into a single, immutable configuration object.
1. The Configuration File
Section titled “1. The Configuration File”The primary configuration file is application.yaml, typically located in the project root.
app_name: "order-service"debug: falseenv: "production"
database: url: "${DB_URL:sqlite:///dev.db}" # Environment interpolation with default pool_size: 10
cache: backend: "redis"Loading Config
Section titled “Loading Config”from lexigram import LexigramConfig
# Auto-discovers application.yaml in the project rootconfig = LexigramConfig.from_yaml()
# Or from a specific pathconfig = LexigramConfig.from_yaml("path/to/application.yaml")2. Environment Interpolation
Section titled “2. Environment Interpolation”Lexigram supports dynamic values in your YAML files via the ${VAR:default} syntax.
${PORT}: Resolves to thePORTenvironment variable. Fails if unset.${PORT:8080}: Resolves toPORTor defaults to8080.${DB_URL:${LOCAL_DB_URL}}: Supports nested interpolation.
database: url: "${DATABASE_URL:sqlite:///./dev.db}" password: "${DB_PASSWORD}"3. Configuration Profiles
Section titled “3. Configuration Profiles”You can override base settings for different environments (Development, Staging, Production) using profile-specific files.
- Base:
application.yaml - Production Overrides:
application.production.yaml
To activate a profile, set the LEX_PROFILE environment variable:
LEX_PROFILE=production lexigram runProfile Loading Order
Section titled “Profile Loading Order”application.yaml(base)application.{profile}.yaml(profile overlay)- Environment variables (highest priority)
4. Precedence Rules
Section titled “4. Precedence Rules”When resolving a configuration key, Lexigram follows this strict order (highest priority wins):
- Environment Variables:
LEX_WEB__PORT=9000overrides everything - Profile YAML: Values from
application.{profile}.yaml - Base YAML: Values from
application.yaml - Code Defaults: Values defined in
Configclass constructors
Env Var Mapping
Section titled “Env Var Mapping”Configuration keys are mapped to environment variables by converting to uppercase and using double underscores for nesting:
web.port → LEX_WEB__PORTdatabase.url → LEX_DATABASE__URLai.llm.provider → LEX_AI__LLM__PROVIDER5. Typed Configuration Sections
Section titled “5. Typed Configuration Sections”LexigramConfig has typed fields for top-level settings:
@dataclassclass LexigramConfig(BaseConfig): app_name: str = "lexigram-app" debug: bool = False env: Environment = Environment.DEVELOPMENT logging: LoggingConfig = Field(default_factory=LoggingConfig) modules: list[str] = Field(default_factory=list)For dynamic sections (plugins, extension packages), use get_section():
from lexigram import LexigramConfig
config = LexigramConfig.from_yaml()
# Typed access to known sectionsconfig.app_name # "my-app"config.debug # Falseconfig.env # Environment.DEVELOPMENT
# Dynamic section access (for plugin/extension sections)db_config = config.get_section("database", DatabaseConfig)
# Dotted path traversalrag_config = config.get_section("ai.rag", RagConfig)
# Check existenceconfig.has_section("web") # True6. Profile Examples
Section titled “6. Profile Examples”debug: truelogging: level: DEBUG format: textdatabase: url: "sqlite:///./dev.db"debug: falselogging: level: WARNING format: jsondatabase: url: "${DATABASE_URL}"cache: backend: redis