A simple TOML configurator for Python
Project description
Simple TOML Configurator
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.
Features
-
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. -
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.
-
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.
-
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.
-
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.
-
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.
-
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
pip install simple-toml-configurator
Usage Example
See Usage for more examples.
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",
},
}
}
# Initialize the Simple TOML Configurator
settings = Configuration("config", default_config, "app_config")
# 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.update_config({"app_ip": "1.2.3.4"})
print(settings.app_ip) # Output: '1.2.3.4'
# Access all settings as a dictionary
all_settings = settings.get_settings()
print(all_settings)
# Output: {'app_ip': '1.2.3.4', 'app_host': '', 'app_port': 5000, 'app_upload_folder': 'uploads'}
# Modify values directly in the config dictionary
settings.config["mysql"]["databases"]["prod"] = "db3"
settings.update()
print(settings.mysql_databases["prod"]) # Output: 'db3'
app_config.toml
contents
[app]
ip = "1.2.3.4"
host = ""
port = 5000
upload_folder = "uploads"
[mysql]
user = "root"
password = "root"
[mysql.databases]
prod = "db3"
dev = "db2"
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Simple-TOML-Configurator-1.0.1.tar.gz
.
File metadata
- Download URL: Simple-TOML-Configurator-1.0.1.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5f5c999a5f78457af72e29c6b822d7881ad5cb7fc0bd86b91f55f0921823f16 |
|
MD5 | 07057f8ffd48261f22f42392a7bf5d94 |
|
BLAKE2b-256 | e48e320dce001cdd0b471f81729e60ef8b35d4b6f7a0be65b84bbe0417887f5d |
File details
Details for the file Simple_TOML_Configurator-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: Simple_TOML_Configurator-1.0.1-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebf13fc03b8500377c447baa30c71afbc3aa247ec05447da23d1fab353427948 |
|
MD5 | 3ca9f4a9b98bcb2e09b266c6b3f1bffa |
|
BLAKE2b-256 | da4261614c42f2e59f8f0a68cbfc1b83363cd727f5c788f9c2c5f7991a7d7877 |