|
1 |
| -# Simple-TOML-Configurator |
2 |
| -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. |
| 1 | +# Simple TOML Configurator |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | +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. |
| 10 | + |
| 11 | +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. |
| 12 | + |
| 13 | +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. |
| 14 | + |
| 15 | +5. **Updating Configurations:** The library enables the updating of configuration settings from a dictionary, ensuring that the changes are accurately reflected both in-memory and in the stored TOML file. |
| 16 | + |
| 17 | +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. |
| 18 | + |
| 19 | +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. |
| 20 | + |
| 21 | +## Usage Example |
| 22 | + |
| 23 | +```python |
| 24 | +from simple_toml_configurator import Configuration |
| 25 | + |
| 26 | +# Define default configuration values |
| 27 | +default_config = { |
| 28 | + "app": { |
| 29 | + "ip": "0.0.0.0", |
| 30 | + "host": "", |
| 31 | + "port": 5000, |
| 32 | + "upload_folder": "uploads" |
| 33 | + } |
| 34 | + "mysql": { |
| 35 | + "user": "root", |
| 36 | + "password": "root" |
| 37 | + "databases": { |
| 38 | + "prod": "db1", |
| 39 | + "dev": "db2" |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +# Initialize the Simple TOML Configurator |
| 45 | +settings = Configuration() |
| 46 | +settings.init_config("config", default_config, "app_config") |
| 47 | +# Stores an app_config.toml file in the `config` folder at the current working directory. |
| 48 | + |
| 49 | +# Access and update configuration values |
| 50 | +print(settings.app_ip) # Output: '0.0.0.0' |
| 51 | +settings.update_config({"app_ip": "1.2.3.4"}) |
| 52 | +print(settings.app_ip) # Output: '1.2.3.4' |
| 53 | + |
| 54 | +# Access all settings as a dictionary |
| 55 | +all_settings = settings.get_settings() |
| 56 | +print(all_settings) |
| 57 | +# Output: {'app_ip': '1.2.3.4', 'app_host': '', 'app_port': 5000, 'app_upload_folder': 'uploads'} |
| 58 | + |
| 59 | +# Modify values directly in the config dictionary |
| 60 | +settings.config["mysql"]["databases"]["prod"] = "db3" |
| 61 | +settings.update() |
| 62 | +print(settings.mysql_databases["prod"]) # Output: 'db3' |
| 63 | +``` |
| 64 | + |
| 65 | +The **Simple TOML Configurator** empowers developers to efficiently manage configuration settings across a wide range of Python applications. Whether you're building a web application, a command-line tool, or a standalone script, this library provides the tools you need to maintain and access configuration values with ease and clarity. |
0 commit comments