{"id":8642,"library":"simple-settings","title":"Simple Settings","description":"Simple Settings is a Python library designed to provide a flexible and straightforward way to manage project configurations, inspired by Django's settings system. It allows loading settings from various file formats (Python modules, CFG, YAML, JSON, TOML) and supports dynamic settings backends like AWS S3, Memcached, and SQL databases. The current version is 1.2.0, and it maintains an active, though irregular, release cadence.","status":"active","version":"1.2.0","language":"en","source_language":"en","source_url":"https://github.com/drgarcia1986/simple-settings","tags":["settings","configuration","django-inspired","config-management"],"install":[{"cmd":"pip install simple-settings","lang":"bash","label":"Basic Installation"},{"cmd":"pip install simple-settings[all]","lang":"bash","label":"Installation with all optional dependencies"}],"dependencies":[{"reason":"Required for loading settings from YAML files.","package":"PyYAML","optional":true},{"reason":"Required for loading settings from TOML files.","package":"toml","optional":true},{"reason":"Required for using AWS S3 as a dynamic settings backend.","package":"boto3","optional":true},{"reason":"Required for using Memcached as a dynamic settings backend.","package":"python-memcached","optional":true},{"reason":"Required for using a database (via SQLAlchemy) as a dynamic settings backend.","package":"SQLAlchemy","optional":true}],"imports":[{"note":"The `settings` object is a singleton that gets populated when the settings module is identified.","wrong":"import simple_settings.settings","symbol":"settings","correct":"from simple_settings import settings"},{"note":"Use `LazySettings` for explicit control over settings file loading, or when avoiding the global singleton.","symbol":"LazySettings","correct":"from simple_settings import LazySettings"}],"quickstart":{"code":"import os\nimport sys\nfrom simple_settings import settings\n\n# --- Create a dummy settings file for demonstration ---\nsettings_content = \"\"\"\nFOO = 'bar'\nBAZ = 123\nSIMPLE_SETTINGS = {'required_settings': ['FOO']}\n\"\"\"\n\nsettings_dir = 'my_project_settings'\nos.makedirs(settings_dir, exist_ok=True)\nwith open(os.path.join(settings_dir, 'development.py'), 'w') as f:\n    f.write(settings_content)\n\n# Add the settings directory to Python's path so it can be imported\nsys.path.insert(0, os.getcwd())\n\n# Method 1: Set environment variable (deprecated but common in older setups)\n# os.environ['SIMPLE_SETTINGS'] = 'my_project_settings.development'\n\n# Method 2: Command line argument (preferred for non-programmatic loading)\n# For programmatic loading, you'd typically use LazySettings or a custom loader\n# For this quickstart, we'll demonstrate direct access after 'setting' the module path implicitly.\n# In a real app, you would run like: python your_script.py --settings=my_project_settings.development\n\n# As a workaround for a runnable quickstart, we'll manually set the internal _SETTINGS_MODULE\n# This is NOT how you'd normally configure it in production for the 'settings' singleton\n# Normally, the --settings CLI arg or SIMPLE_SETTINGS env var would handle this.\n# Using LazySettings is the programmatic alternative.\n\n# For this demonstration, we'll mimic the effect of `settings.configure()`\n# if the env var or CLI was set.\n# In a real application, you'd run `python your_app.py --settings=my_project_settings.development`\n# and then `from simple_settings import settings` would automatically pick it up.\n# To make this runnable without CLI args or env vars, we use LazySettings.\n\ntry:\n    # Using LazySettings for a self-contained programmatic example\n    app_settings = LazySettings('my_project_settings.development')\n    print(f\"FOO setting: {app_settings.FOO}\")\n    print(f\"BAZ setting: {app_settings.BAZ}\")\n\n    # Demonstrate a missing required setting (this would raise an error)\n    # with open(os.path.join(settings_dir, 'broken_settings.py'), 'w') as f:\n    #     f.write(\"BAZ = 456\")\n    # broken_app_settings = LazySettings('my_project_settings.broken_settings')\n    # print(f\"Broken FOO: {broken_app_settings.FOO}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # Clean up dummy settings file and directory\n    os.remove(os.path.join(settings_dir, 'development.py'))\n    # if os.path.exists(os.path.join(settings_dir, 'broken_settings.py')):\n    #     os.remove(os.path.join(settings_dir, 'broken_settings.py'))\n    os.rmdir(settings_dir)\n    sys.path.pop(0)\n","lang":"python","description":"This quickstart demonstrates how to define a Python settings file and load it using `LazySettings`. In a typical application, the settings module would be specified via a `--settings` command-line argument (e.g., `python your_app.py --settings=my_project_settings.development`) or the `SIMPLE_SETTINGS` environment variable, after which the global `simple_settings.settings` object becomes populated. Using `LazySettings` allows for explicit, programmatic control over which settings module to load."},"warnings":[{"fix":"Prefer using `python your_app.py --settings=your_module_path` or instantiate `LazySettings('your_module_path')`.","message":"The `SIMPLE_SETTINGS` environment variable for specifying the settings module is deprecated. While still functional, it's recommended to use the `--settings` command-line argument for explicit configuration or `LazySettings` for programmatic loading.","severity":"deprecated","affected_versions":"<=1.2.0"},{"fix":"Ensure all special settings are defined in a Python `.py` settings file.","message":"Special settings, such as `SIMPLE_SETTINGS` for defining `required_settings` or `CONFIGURE_LOGGING`, are only recognized and applied when defined within a Python settings module (e.g., `settings.py`). They are ignored when settings are loaded from INI, YAML, JSON, or TOML files.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Install `simple-settings` with the `[all]` extra (`pip install simple-settings[all]`) or install the specific dependency for the backend you intend to use (e.g., `pip install simple-settings[s3]`).","message":"Loading dynamic settings from backends like AWS S3, Memcached, or a database requires installing the respective optional dependencies (e.g., `boto3`, `python-memcached`, `SQLAlchemy`). If these are missing, `ImportError` or similar runtime errors will occur when attempting to use those backends.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Verify the settings module path (e.g., `my_project.settings.development`). Ensure the directory containing `my_project` (or the top-level package) is in `PYTHONPATH` or added to `sys.path`.","cause":"The Python interpreter cannot find the specified settings module. This usually means the module path provided via `--settings` or `SIMPLE_SETTINGS` is incorrect, or the directory containing the settings file is not in Python's `sys.path`.","error":"ModuleNotFoundError: No module named 'your_settings_module'"},{"fix":"Upgrade to `simple-settings` version 1.1.0 or newer. Ensure configuration files are not entirely empty, or at least contain valid, minimal content if intended to be empty (e.g., `{}` for JSON/YAML).","cause":"In versions prior to 1.1.0, loading an entirely empty settings file (e.g., an empty YAML or JSON file) could lead to a TypeError. This was fixed in 1.1.0 but could appear in older installations or specific edge cases.","error":"TypeError: 'NoneType' object is not iterable (or similar error related to empty config files)"}]}