Simple-TOML-Configurator


NameSimple-TOML-Configurator JSON
Version 1.2.2 PyPI version JSON
download
home_page
SummaryA simple TOML configurator for Python
upload_time2024-03-10 20:10:40
maintainer
docs_urlNone
author
requires_python>=3.7.0
licenseMIT License
keywords configuration toml settings management python
VCS
bugtrack_url
requirements tomlkit python-dateutil
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Simple TOML Configurator

[![PyPI version](https://badge.fury.io/py/Simple-TOML-Configurator.svg)](https://badge.fury.io/py/Simple-TOML-Configurator)
![PyPI - License](https://img.shields.io/pypi/l/Simple-TOML-Configurator)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/Simple-TOML-Configurator)
![PyPI - Wheel](https://img.shields.io/pypi/wheel/Simple-TOML-Configurator)
![Build](https://github.com/gilbn/Simple-TOML-Configurator/actions/workflows/tests.yml/badge.svg?event=push)

The **Simple TOML Configurator** is a versatile Python library designed to streamline the handling and organization of configuration settings across various types of applications. This library facilitates the management of configuration values through a user-friendly interface and stores these settings in TOML file format for easy readability and accessibility.

## Documentation

https://gilbn.github.io/Simple-TOML-Configurator/

## Features

1. **Effortless Configuration Management:** The heart of the library is the `Configuration` class, which simplifies the management of configuration settings. It provides intuitive methods to load, update, and store configurations, ensuring a smooth experience for developers.

2. **Universal Applicability:** The **Simple TOML Configurator** is designed to work seamlessly with any type of Python application, ranging from web frameworks like Flask, Django, and FastAPI to standalone scripts and command-line utilities.

3. **TOML File Storage:** Configuration settings are stored in TOML files, a popular human-readable format. This enables developers to review, modify, and track configuration changes easily.

4. **Attribute-Based Access:** Accessing configuration values is straightforward, thanks to the attribute-based approach. Settings can be accessed and updated as attributes, making it convenient for both reading and modifying values.

5. **Environment Variable Support:** Configuration values are automatically set as environment variables, making it easier to use the configuration values in your application. Environment variable are set as uppercase. e.g. `APP_HOST` and `APP_PORT` or `PROJECT_APP_HOST` and `PROJECT_APP_PORT` if `env_prefix` is set to "project". This also works for nested values. ex: `TABLE_KEY_LEVEL1_KEY_LEVEL2_KEY`. This works for any level of nesting.**Environment variables set before the configuration is loaded will not be overwritten, but instead will overwrite the existing config value.**

6. **Default Values:** Developers can define default values for various configuration sections and keys. The library automatically incorporates new values and manages the removal of outdated ones.

7. **Customization Capabilities:** The `Configuration` class can be extended and customized to cater to application-specific requirements. Developers can implement custom logic with getters and setters to handle unique settings or scenarios.

## Installation

Install with
```bash
pip install simple-toml-configurator
```

## Usage Example

See [Usage](https://gilbn.github.io/Simple-TOML-Configurator/latest/usage-examples/) for more examples.

```python
import os
from simple_toml_configurator import Configuration

# Define default configuration values
default_config = {
    "app": {
        "ip": "0.0.0.0",
        "host": "",
        "port": 5000,
        "upload_folder": "uploads",
    },
    "mysql": {
        "user": "root",
        "password": "root",
        "databases": {
            "prod": "db1",
            "dev": "db2",
            },
    }
}

# Set environment variables
os.environ["PROJECT_APP_UPLOAD_FOLDER"] = "overridden_uploads"

# Initialize the Simple TOML Configurator
settings = Configuration(config_path="config", defaults=default_config, config_file_name="app_config", env_prefix="project")
# Creates an `app_config.toml` file in the `config` folder at the current working directory.

# Access and update configuration values
print(settings.app.ip)  # Output: '0.0.0.0'
settings.app.ip = "1.2.3.4"
settings.update()
print(settings.app_ip)  # Output: '1.2.3.4'

# Access nested configuration values
print(settings.mysql.databases.prod)  # Output: 'db1'
settings.mysql.databases.prod = 'new_value'
settings.update()
print(settings.mysql.databases.prod)  # Output: 'new_value'

# Access and update configuration values
print(settings.app_ip)  # Output: '1.2.3.4'
settings.update_config({"app_ip": "1.1.1.1"})
print(settings.app_ip)  # Output: '1.1.1.1'

# Access all settings as a dictionary
all_settings = settings.get_settings()
print(all_settings)
# Output: {'app_ip': '1.1.1.1', 'app_host': '', 'app_port': 5000, 'app_upload_folder': 'overridden_uploads', 'mysql_user': 'root', 'mysql_password': 'root', 'mysql_databases': {'prod': 'new_value', 'dev': 'db2'}}

# Modify values directly in the config dictionary
settings.config["mysql"]["databases"]["prod"] = "db3"
settings.update()
print(settings.mysql_databases["prod"])  # Output: 'db3'

# Access environment variables
print(os.environ["PROJECT_MYSQL_DATABASES_PROD"])  # Output: 'db3'
print(os.environ["PROJECT_APP_UPLOAD_FOLDER"])  # Output: 'overridden_uploads'
```

**`app_config.toml` contents**

```toml
[app]
ip = "1.1.1.1"
host = ""
port = 5000
upload_folder = "overridden_uploads"

[mysql]
user = "root"
password = "root"

[mysql.databases]
prod = "db3"
dev = "db2"
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "Simple-TOML-Configurator",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7.0",
    "maintainer_email": "",
    "keywords": "configuration,TOML,settings,management,Python",
    "author": "",
    "author_email": "GilbN <me@gilbn.dev>",
    "download_url": "https://files.pythonhosted.org/packages/ab/4f/7bbd51ca3e0d4c166807d42aea96a7b911a09618e34ae3444058a8ae0e82/Simple-TOML-Configurator-1.2.2.tar.gz",
    "platform": null,
    "description": "# Simple TOML Configurator\n\n[![PyPI version](https://badge.fury.io/py/Simple-TOML-Configurator.svg)](https://badge.fury.io/py/Simple-TOML-Configurator)\n![PyPI - License](https://img.shields.io/pypi/l/Simple-TOML-Configurator)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/Simple-TOML-Configurator)\n![PyPI - Wheel](https://img.shields.io/pypi/wheel/Simple-TOML-Configurator)\n![Build](https://github.com/gilbn/Simple-TOML-Configurator/actions/workflows/tests.yml/badge.svg?event=push)\n\nThe **Simple TOML Configurator** is a versatile Python library designed to streamline the handling and organization of configuration settings across various types of applications. This library facilitates the management of configuration values through a user-friendly interface and stores these settings in TOML file format for easy readability and accessibility.\n\n## Documentation\n\nhttps://gilbn.github.io/Simple-TOML-Configurator/\n\n## Features\n\n1. **Effortless Configuration Management:** The heart of the library is the `Configuration` class, which simplifies the management of configuration settings. It provides intuitive methods to load, update, and store configurations, ensuring a smooth experience for developers.\n\n2. **Universal Applicability:** The **Simple TOML Configurator** is designed to work seamlessly with any type of Python application, ranging from web frameworks like Flask, Django, and FastAPI to standalone scripts and command-line utilities.\n\n3. **TOML File Storage:** Configuration settings are stored in TOML files, a popular human-readable format. This enables developers to review, modify, and track configuration changes easily.\n\n4. **Attribute-Based Access:** Accessing configuration values is straightforward, thanks to the attribute-based approach. Settings can be accessed and updated as attributes, making it convenient for both reading and modifying values.\n\n5. **Environment Variable Support:** Configuration values are automatically set as environment variables, making it easier to use the configuration values in your application. Environment variable are set as uppercase. e.g. `APP_HOST` and `APP_PORT` or `PROJECT_APP_HOST` and `PROJECT_APP_PORT` if `env_prefix` is set to \"project\". This also works for nested values. ex: `TABLE_KEY_LEVEL1_KEY_LEVEL2_KEY`. This works for any level of nesting.**Environment variables set before the configuration is loaded will not be overwritten, but instead will overwrite the existing config value.**\n\n6. **Default Values:** Developers can define default values for various configuration sections and keys. The library automatically incorporates new values and manages the removal of outdated ones.\n\n7. **Customization Capabilities:** The `Configuration` class can be extended and customized to cater to application-specific requirements. Developers can implement custom logic with getters and setters to handle unique settings or scenarios.\n\n## Installation\n\nInstall with\n```bash\npip install simple-toml-configurator\n```\n\n## Usage Example\n\nSee [Usage](https://gilbn.github.io/Simple-TOML-Configurator/latest/usage-examples/) for more examples.\n\n```python\nimport os\nfrom simple_toml_configurator import Configuration\n\n# Define default configuration values\ndefault_config = {\n    \"app\": {\n        \"ip\": \"0.0.0.0\",\n        \"host\": \"\",\n        \"port\": 5000,\n        \"upload_folder\": \"uploads\",\n    },\n    \"mysql\": {\n        \"user\": \"root\",\n        \"password\": \"root\",\n        \"databases\": {\n            \"prod\": \"db1\",\n            \"dev\": \"db2\",\n            },\n    }\n}\n\n# Set environment variables\nos.environ[\"PROJECT_APP_UPLOAD_FOLDER\"] = \"overridden_uploads\"\n\n# Initialize the Simple TOML Configurator\nsettings = Configuration(config_path=\"config\", defaults=default_config, config_file_name=\"app_config\", env_prefix=\"project\")\n# Creates an `app_config.toml` file in the `config` folder at the current working directory.\n\n# Access and update configuration values\nprint(settings.app.ip)  # Output: '0.0.0.0'\nsettings.app.ip = \"1.2.3.4\"\nsettings.update()\nprint(settings.app_ip)  # Output: '1.2.3.4'\n\n# Access nested configuration values\nprint(settings.mysql.databases.prod)  # Output: 'db1'\nsettings.mysql.databases.prod = 'new_value'\nsettings.update()\nprint(settings.mysql.databases.prod)  # Output: 'new_value'\n\n# Access and update configuration values\nprint(settings.app_ip)  # Output: '1.2.3.4'\nsettings.update_config({\"app_ip\": \"1.1.1.1\"})\nprint(settings.app_ip)  # Output: '1.1.1.1'\n\n# Access all settings as a dictionary\nall_settings = settings.get_settings()\nprint(all_settings)\n# Output: {'app_ip': '1.1.1.1', 'app_host': '', 'app_port': 5000, 'app_upload_folder': 'overridden_uploads', 'mysql_user': 'root', 'mysql_password': 'root', 'mysql_databases': {'prod': 'new_value', 'dev': 'db2'}}\n\n# Modify values directly in the config dictionary\nsettings.config[\"mysql\"][\"databases\"][\"prod\"] = \"db3\"\nsettings.update()\nprint(settings.mysql_databases[\"prod\"])  # Output: 'db3'\n\n# Access environment variables\nprint(os.environ[\"PROJECT_MYSQL_DATABASES_PROD\"])  # Output: 'db3'\nprint(os.environ[\"PROJECT_APP_UPLOAD_FOLDER\"])  # Output: 'overridden_uploads'\n```\n\n**`app_config.toml` contents**\n\n```toml\n[app]\nip = \"1.1.1.1\"\nhost = \"\"\nport = 5000\nupload_folder = \"overridden_uploads\"\n\n[mysql]\nuser = \"root\"\npassword = \"root\"\n\n[mysql.databases]\nprod = \"db3\"\ndev = \"db2\"\n```\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A simple TOML configurator for Python",
    "version": "1.2.2",
    "project_urls": {
        "Homepage": "https://github.com/GilbN/Simple-TOML-Configurator"
    },
    "split_keywords": [
        "configuration",
        "toml",
        "settings",
        "management",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "aeb4401da69b435ac6c957a3934e3323db953c7019e348c4b0fdf5cee8370da6",
                "md5": "03877e9be44a05561f8e6c0b8afb171f",
                "sha256": "f8cb05130d2bb0af193f80dddd33693054c5c57efa28bdf2307607c767e73da9"
            },
            "downloads": -1,
            "filename": "Simple_TOML_Configurator-1.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "03877e9be44a05561f8e6c0b8afb171f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7.0",
            "size": 10018,
            "upload_time": "2024-03-10T20:10:39",
            "upload_time_iso_8601": "2024-03-10T20:10:39.322502Z",
            "url": "https://files.pythonhosted.org/packages/ae/b4/401da69b435ac6c957a3934e3323db953c7019e348c4b0fdf5cee8370da6/Simple_TOML_Configurator-1.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ab4f7bbd51ca3e0d4c166807d42aea96a7b911a09618e34ae3444058a8ae0e82",
                "md5": "9b49994df3626472cc191e8a74299c37",
                "sha256": "5f0faf82e8cc3939e5a0542e751e3a7d3ee06d2c8c65884e8d2664ad521b5f10"
            },
            "downloads": -1,
            "filename": "Simple-TOML-Configurator-1.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "9b49994df3626472cc191e8a74299c37",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7.0",
            "size": 10650,
            "upload_time": "2024-03-10T20:10:40",
            "upload_time_iso_8601": "2024-03-10T20:10:40.927209Z",
            "url": "https://files.pythonhosted.org/packages/ab/4f/7bbd51ca3e0d4c166807d42aea96a7b911a09618e34ae3444058a8ae0e82/Simple-TOML-Configurator-1.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-10 20:10:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "GilbN",
    "github_project": "Simple-TOML-Configurator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "tomlkit",
            "specs": [
                [
                    ">=",
                    "0.12.1"
                ]
            ]
        },
        {
            "name": "python-dateutil",
            "specs": [
                [
                    ">=",
                    "2.8.2"
                ]
            ]
        }
    ],
    "lcname": "simple-toml-configurator"
}
        
Elapsed time: 0.20165s