mud_server.config ================= .. py:module:: mud_server.config .. autoapi-nested-parse:: Server configuration management. This module handles loading and accessing server configuration from multiple sources with a clear priority order: 1. Environment variables (highest priority) - for containerized deployments 2. Config file (config/server.ini) - for static deployments 3. Built-in defaults (lowest priority) - sensible fallbacks Configuration is loaded once at module import time and cached. The ServerConfig dataclass provides typed access to all settings. Usage: from mud_server.config import config # Access settings print(config.server.host) print(config.security.cors_origins) print(config.is_production) Environment Variable Mapping: MUD_HOST -> server.host MUD_PORT -> server.port MUD_PRODUCTION -> security.production MUD_CORS_ORIGINS -> security.cors_origins MUD_DB_PATH -> database.path MUD_LOG_LEVEL -> logging.level MUD_SESSION_TTL_MINUTES -> session.ttl_minutes MUD_SESSION_SLIDING_EXPIRATION -> session.sliding_expiration MUD_SESSION_ALLOW_MULTIPLE -> session.allow_multiple_sessions MUD_SESSION_ACTIVE_WINDOW_MINUTES -> session.active_window_minutes MUD_CHAR_DEFAULT_SLOTS -> characters.default_slots MUD_CHAR_MAX_SLOTS -> characters.max_slots Attributes ---------- .. autoapisummary:: mud_server.config.PROJECT_ROOT mud_server.config.CONFIG_DIR mud_server.config.CONFIG_FILE mud_server.config.CONFIG_EXAMPLE mud_server.config.config Classes ------- .. autoapisummary:: mud_server.config.ServerSettings mud_server.config.SecuritySettings mud_server.config.SessionSettings mud_server.config.DatabaseSettings mud_server.config.LoggingSettings mud_server.config.RateLimitSettings mud_server.config.CharacterSettings mud_server.config.FeatureSettings mud_server.config.WorldSettings mud_server.config.ServerConfig mud_server.config.use_test_database Functions --------- .. autoapisummary:: mud_server.config.load_config mud_server.config.reload_config mud_server.config.get_config_status mud_server.config.print_config_summary Module Contents --------------- .. py:data:: PROJECT_ROOT .. py:data:: CONFIG_DIR .. py:data:: CONFIG_FILE .. py:data:: CONFIG_EXAMPLE .. py:class:: ServerSettings Network server configuration. .. py:attribute:: host :type: str :value: '0.0.0.0' .. py:attribute:: port :type: int :value: 8000 .. py:class:: SecuritySettings Security-related configuration. .. py:attribute:: production :type: bool :value: False .. py:attribute:: cors_origins :type: list[str] :value: ['http://localhost:7860'] .. py:attribute:: cors_allow_credentials :type: bool :value: True .. py:attribute:: cors_allow_methods :type: list[str] :value: ['*'] .. py:attribute:: cors_allow_headers :type: list[str] :value: ['*'] .. py:attribute:: docs_enabled :type: Literal['auto', 'enabled', 'disabled'] :value: 'auto' .. py:class:: SessionSettings Session management configuration. .. py:attribute:: ttl_minutes :type: int :value: 480 .. py:attribute:: sliding_expiration :type: bool :value: True .. py:attribute:: allow_multiple_sessions :type: bool :value: False .. py:attribute:: active_window_minutes :type: int :value: 30 .. py:class:: DatabaseSettings Database configuration. .. py:attribute:: path :type: str :value: 'data/mud.db' .. py:property:: absolute_path :type: pathlib.Path Get absolute path to database file. .. py:class:: LoggingSettings Logging configuration. .. py:attribute:: level :type: str :value: 'INFO' .. py:attribute:: format :type: Literal['simple', 'detailed', 'json'] :value: 'detailed' .. py:class:: RateLimitSettings Rate limiting configuration. .. py:attribute:: enabled :type: bool :value: False .. py:attribute:: login_per_minute :type: int :value: 5 .. py:attribute:: register_per_minute :type: int :value: 5 .. py:attribute:: api_per_second :type: int :value: 30 .. py:class:: CharacterSettings Character slot limits and defaults. .. py:attribute:: default_slots :type: int :value: 2 .. py:attribute:: max_slots :type: int :value: 10 .. py:class:: FeatureSettings Feature flags. .. py:attribute:: ollama_enabled :type: bool :value: True .. py:attribute:: verbose_errors :type: bool :value: False .. py:class:: WorldSettings Multi-world configuration settings. .. py:attribute:: worlds_root :type: str :value: 'data/worlds' .. py:attribute:: default_world_id :type: str :value: 'pipeworks_web' .. py:attribute:: allow_multi_world_characters :type: bool :value: False .. py:class:: ServerConfig Complete server configuration. This is the main configuration object that aggregates all settings sections. Access via the module-level `config` singleton. .. py:attribute:: server :type: ServerSettings .. py:attribute:: security :type: SecuritySettings .. py:attribute:: session :type: SessionSettings .. py:attribute:: database :type: DatabaseSettings .. py:attribute:: logging :type: LoggingSettings .. py:attribute:: rate_limit :type: RateLimitSettings .. py:attribute:: characters :type: CharacterSettings .. py:attribute:: features :type: FeatureSettings .. py:attribute:: worlds :type: WorldSettings .. py:property:: is_production :type: bool Convenience property for production mode check. .. py:property:: docs_should_be_enabled :type: bool Determine if API docs should be enabled based on settings. .. py:function:: load_config() Load configuration from all sources with proper priority. Priority (highest wins): 1. Environment variables 2. config/server.ini 3. config/server.example.ini (fallback for development) 4. Built-in defaults :returns: Fully populated configuration object. :rtype: ServerConfig .. py:function:: reload_config() Reload configuration from disk and environment. This updates the module-level `config` singleton. Use sparingly as it doesn't update already-running server middleware. :returns: The newly loaded configuration. :rtype: ServerConfig .. py:data:: config .. py:function:: get_config_status() Get configuration status for diagnostics. Returns a dictionary with configuration source information, useful for debugging and admin dashboards. .. py:function:: print_config_summary() Print a summary of current configuration to stdout. .. py:class:: use_test_database(db_path) Context manager for using a temporary test database. This is the recommended way to set up test databases. It properly configures the config system to use a temporary database path. Usage: from mud_server.config import use_test_database def test_something(tmp_path): db_path = tmp_path / "test.db" with use_test_database(db_path): # Database operations will use db_path database.init_database() :param db_path: Path to the test database file .. py:attribute:: db_path .. py:attribute:: original_path :type: str | None :value: None