mud_server.config
Server configuration management.
This module handles loading and accessing server configuration from multiple sources with a clear priority order:
Environment variables (highest priority) - for containerized deployments
Config file (config/server.ini) - for static deployments
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 MUD_ENTITY_STATE_ENABLED -> integrations.entity_state_enabled MUD_ENTITY_STATE_BASE_URL -> integrations.entity_state_base_url MUD_ENTITY_STATE_TIMEOUT_SECONDS -> integrations.entity_state_timeout_seconds MUD_ENTITY_STATE_INCLUDE_PROMPTS -> integrations.entity_state_include_prompts MUD_NAMEGEN_ENABLED -> integrations.namegen_enabled MUD_NAMEGEN_BASE_URL -> integrations.namegen_base_url MUD_NAMEGEN_TIMEOUT_SECONDS -> integrations.namegen_timeout_seconds MUD_REGISTRATION_MODE -> registration.account_registration_mode MUD_GUEST_REGISTRATION_ENABLED -> registration.guest_registration_enabled MUD_PLAYER_SELF_CREATE_ENABLED -> character_creation.player_self_create_enabled MUD_CHAR_CREATE_DEFAULT_MODE -> character_creation.default_creation_mode MUD_CHAR_CREATE_DEFAULT_NAMING -> character_creation.default_naming_mode MUD_CHAR_CREATE_DEFAULT_SLOT_LIMIT -> character_creation.default_world_slot_limit MUD_TRANSLATION_ENABLED -> ollama_translation.enabled MUD_TRANSLATION_OLLAMA_URL -> ollama_translation.base_url MUD_TRANSLATION_TIMEOUT -> ollama_translation.timeout_seconds
Attributes
Classes
Network server configuration. |
|
Security-related configuration. |
|
Session management configuration. |
|
Database configuration. |
|
Logging configuration. |
|
Rate limiting configuration. |
|
Character slot limits and defaults. |
|
Account-registration policy controls. |
|
Character-creation policy for a specific world. |
|
Global character-creation policy and world-level overrides. |
|
Feature flags. |
|
Multi-world configuration settings. |
|
Optional integration settings for provisioning and name generation. |
|
Server-level controls for the OOC→IC translation layer. |
|
Complete server configuration. |
|
Context manager for using a temporary test database. |
Functions
Load configuration from all sources with proper priority. |
|
Reload configuration from disk and environment. |
|
Get configuration status for diagnostics. |
|
|
Print a summary of current configuration to stdout. |
Module Contents
- mud_server.config.PROJECT_ROOT
- mud_server.config.CONFIG_DIR
- mud_server.config.CONFIG_FILE
- mud_server.config.CONFIG_EXAMPLE
- class mud_server.config.SecuritySettings[source]
Security-related configuration.
- docs_enabled: Literal['auto', 'enabled', 'disabled'] = 'auto'
- class mud_server.config.DatabaseSettings[source]
Database configuration.
- property absolute_path: pathlib.Path
Get absolute path to database file.
- class mud_server.config.LoggingSettings[source]
Logging configuration.
- format: Literal['simple', 'detailed', 'json'] = 'detailed'
- class mud_server.config.RegistrationSettings[source]
Account-registration policy controls.
- account_registration_mode: Literal['open', 'closed'] = 'open'
- class mud_server.config.WorldCharacterPolicy[source]
Character-creation policy for a specific world.
- creation_mode
openallows account holders to self-create in the world.inviterequires explicit world permission.
- naming_mode
generatedmeans the server mints names.manualis currently reserved for admin/superuser workflows.
- slot_limit_per_account
Maximum characters an account may own in this world.
- creation_mode: Literal['open', 'invite'] = 'invite'
- naming_mode: Literal['generated', 'manual'] = 'generated'
- class mud_server.config.CharacterCreationSettings[source]
Global character-creation policy and world-level overrides.
The defaults define baseline behavior for all worlds. Per-world sections in INI (
[world_policy.<world_id>]) can override individual fields.- default_creation_mode: Literal['open', 'invite'] = 'invite'
- default_naming_mode: Literal['generated', 'manual'] = 'generated'
- world_policy_overrides: dict[str, WorldCharacterPolicy]
- class mud_server.config.IntegrationSettings[source]
Optional integration settings for provisioning and name generation.
- class mud_server.config.OllamaTranslationSettings[source]
Server-level controls for the OOC→IC translation layer.
Acts as the master switch and provides server-wide defaults. Per-world config in
world.jsonis checked second; both must be enabled for translation to activate.
- class mud_server.config.ServerConfig[source]
Complete server configuration.
This is the main configuration object that aggregates all settings sections. Access via the module-level config singleton.
- server: ServerSettings
- security: SecuritySettings
- session: SessionSettings
- database: DatabaseSettings
- logging: LoggingSettings
- rate_limit: RateLimitSettings
- characters: CharacterSettings
- registration: RegistrationSettings
- character_creation: CharacterCreationSettings
- features: FeatureSettings
- worlds: WorldSettings
- integrations: IntegrationSettings
- ollama_translation: OllamaTranslationSettings
- mud_server.config.load_config()[source]
Load configuration from all sources with proper priority.
- Priority (highest wins):
Environment variables
config/server.ini
config/server.example.ini (fallback for development)
Built-in defaults
- Returns:
Fully populated configuration object.
- Return type:
- mud_server.config.reload_config()[source]
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.
- Return type:
- mud_server.config.config
- mud_server.config.get_config_status()[source]
Get configuration status for diagnostics.
Returns a dictionary with configuration source information, useful for debugging and admin dashboards.
- mud_server.config.print_config_summary(*, resolved_host=None, resolved_port=None)[source]
Print a summary of current configuration to stdout.
- class mud_server.config.use_test_database(db_path)[source]
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()
- Parameters:
db_path (pathlib.Path | str) – Path to the test database file
- db_path