# ๐ ConfigSet - Enhanced Configuration Management Library
๐ **A powerful and flexible configuration management library that supports both INI, JSON and YAML formats with automatic type conversion, list/dictionary parsing, and class-based interfaces.**
## ๐ Table of Contents
* [โจ Features](#features)
* [๐ฆ Installation](#installation)
* [๐ Quick Start](#quick-start)
* [๐ Documentation](#documentation)
* [๐ฏ Usage Examples](#usage-examples)
* [๐ฅ๏ธ Command Line Interface](#command-line-interface)
* [๐๏ธ Advanced Usage](#advanced-usage)
* [๐ง Configuration](#configuration)
* [๐ค Contributing](#contributing)
* [๐ License](#license)
## โจ Features
| Feature | Description | Icon |
|---------|-------------|------|
| INI Support | Full INI file configuration management | ๐ |
| JSON Support | JSON configuration with attribute-based access | ๐๏ธ |
| Auto Type Conversion | Automatic string to bool/int/float conversion | ๐ |
| List Parsing | Parse comma-separated, newline-separated, and JSON arrays | ๐ |
| Dictionary Parsing | Parse key:value pairs and JSON objects | ๐๏ธ |
| Class-based Interface | Metaclass-powered configuration classes | ๐๏ธ |
| CLI Interface | Command-line tool for configuration management | ๐ป |
| Search Functionality | Find sections and options with case sensitivity control | ๐ |
| Pretty Printing | Enhanced output with optional color support | ๐จ |
| Python 2/3 Compatible | Works with both Python 2.7+ and Python 3.6+ | ๐ |
## ๐ฆ Installation
### ๐ Basic Installation
```bash
# Install from PyPI
pip install configset
# Or clone the repository
git clone https://github.com/cumulus13/configset.git
cd configset
# Install the package in editable/development mode
pip install -e .
# Or install the latest development version directly from GitHub
pip install git+https://github.com/cumulus13/configset.git
```
### ๐จ With Optional Dependencies (Recommended)
```bash
# Install with enhanced output support
pip install -e .[full]
# Or install dependencies manually
pip install rich jsoncolor make-colors
```
### ๐ Requirements
* **Python 2.7+ or Python 3.6+**
* **Optional**: rich, jsoncolor, make-colors for enhanced output
## ๐ Quick Start
### ๐ Basic INI Configuration
```python
from configset import ConfigSet
# or from configset import configset
# Create configuration instance
config = ConfigSet('myapp.ini')
# or config = configset('myapp.ini')
# Write configuration
config.write_config('database', 'host', 'localhost')
config.write_config('database', 'port', 5432)
config.write_config('database', 'ssl', True)
# Read configuration (with automatic type conversion)
host = config.get_config('database', 'host') # Returns: 'localhost'
port = config.get_config('database', 'port') # Returns: 5432 (int)
ssl = config.get_config('database', 'ssl') # Returns: True (bool)
```
### ๐๏ธ Class-based Configuration
```python
from configset import CONFIG
class AppConfig(CONFIG):
CONFIGFILE = 'myapp.ini'
# Use as class methods
AppConfig.write_config('api', 'endpoint', 'https://api.example.com')
endpoint = AppConfig.get_config('api', 'endpoint')
# JSON-style attribute access
config = AppConfig()
config.api_key = 'secret123'
config.debug_mode = True
print(f"API Key: {config.api_key}") # Output: API Key: secret123
```
## ๐ Documentation
### ๐ง ConfigSet Class
The main class for INI file configuration management.
#### ๐ Constructor
```python
ConfigSet(config_file='', auto_write=True, **kwargs)
```
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| config_file | str | '' | Path to configuration file |
| auto_write | bool | True | Auto-create missing files/sections |
| **kwargs | dict | {} | Additional ConfigParser arguments |
#### ๐ Key Methods
| Method | Description | Return Type |
|--------|-------------|-------------|
| get_config(section, option, default=None) | Get config value with type conversion | Any |
| write_config(section, option, value) | Write config value to file | Any |
| remove_config(section, option=None) | Remove section or specific option | bool |
| get_config_as_list(section, option, default=None) | Parse value as list | List[Any] |
| get_config_as_dict(section, option, default=None) | Parse value as dictionary | Dict[str, Any] |
| find(query, case_sensitive=True, verbose=False) | Search sections/options | bool |
| print_all_config(sections=None) | Print all configuration | List[Tuple] |
## ๐ฏ Usage Examples
### ๐ List Configuration
```python
config = ConfigSet('servers.ini')
# Write list data (multiple formats supported)
config.write_config('cluster', 'servers', 'server1.com, server2.com, server3.com')
config.write_config('cluster', 'ports', '[8080, 8081, 8082]')
config.write_config('cluster', 'features', '''
load_balancer
ssl_support
monitoring
''')
# Read as lists (automatic parsing)
servers = config.get_config_as_list('cluster', 'servers')
# Returns: ['server1.com', 'server2.com', 'server3.com']
ports = config.get_config_as_list('cluster', 'ports')
# Returns: [8080, 8081, 8082]
features = config.get_config_as_list('cluster', 'features')
# Returns: ['load_balancer', 'ssl_support', 'monitoring']
```
### ๐๏ธ Dictionary Configuration
```python
config = ConfigSet('settings.ini')
# Write dictionary data
config.write_config('limits', 'quotas', 'users:1000, files:5000, bandwidth:100')
config.write_config('features', 'enabled', '{"auth": true, "cache": false, "debug": true}')
# Read as dictionaries
quotas = config.get_config_as_dict('limits', 'quotas')
# Returns: {'users': 1000, 'files': 5000, 'bandwidth': 100}
features = config.get_config_as_dict('features', 'enabled')
# Returns: {'auth': True, 'cache': False, 'debug': True}
```
### ๐ Search and Remove
```python
config = ConfigSet('myapp.ini')
# Search for sections/options
found = config.find('database') # Returns: True if found
config.find('host', verbose=True) # Print found items
# Remove operations
config.remove_config('old_section') # Remove entire section
config.remove_config('database', 'old_option') # Remove specific option
```
## ๐ฅ๏ธ Command Line Interface
The ConfigSet library includes a powerful CLI for configuration management.
### ๐ Basic Commands
```bash
# Show help
python -m configset --help
# Read all configuration
python -m configset myapp.ini --all
# Read specific value
python -m configset myapp.ini --read --section database --option host
# Write configuration
python -m configset myapp.ini --write --section database --option host --value localhost
# Remove section
python -m configset myapp.ini --delete --section old_section
# Remove specific option
python -m configset myapp.ini --delete --section database --option password
```
### ๐๏ธ Advanced CLI Usage
```bash
# Parse as list
python -m configset myapp.ini --read --section cluster --option servers --list
# Parse as dictionary
python -m configset myapp.ini --read --section limits --option quotas --dict
# Enable debug mode
DEBUG=1 python -m configset myapp.ini --all
```
## ๐๏ธ Advanced Usage
### ๐จ Custom Configuration Classes
```python
from configset import CONFIG, ConfigSet
class DatabaseConfig(CONFIG):
CONFIGFILE = 'database.ini'
@classmethod
def get_connection_string(cls):
host = cls.get_config('database', 'host')
port = cls.get_config('database', 'port')
db = cls.get_config('database', 'name')
return f"postgresql://{host}:{port}/{db}"
class APIConfig(CONFIG):
CONFIGFILE = 'api.ini'
def __init__(self):
super().__init__()
# Set default values
if not hasattr(self, 'timeout'):
self.timeout = 30
if not hasattr(self, 'retries'):
self.retries = 3
# Usage
db_config = DatabaseConfig()
connection = db_config.get_connection_string()
api_config = APIConfig()
api_config.endpoint = 'https://api.example.com'
print(f"Timeout: {api_config.timeout}") # Output: Timeout: 30
```
### ๐ Configuration Migration
```python
def migrate_config_v1_to_v2(old_config_file, new_config_file):
"""Migrate configuration from v1 to v2 format."""
old_config = ConfigSet(old_config_file)
new_config = ConfigSet(new_config_file)
# Copy all sections and options
for section_name, section_data in old_config.get_all_config():
for option, value in section_data.items():
# Apply any transformations needed
if section_name == 'database' and option == 'ssl':
value = 'enabled' if value else 'disabled'
new_config.write_config(section_name, option, value)
print(f"โ
Migration completed: {old_config_file} โ {new_config_file}")
# Usage
migrate_config_v1_to_v2('old_app.ini', 'new_app.ini')
```
### ๐งช Configuration Validation
```python
from configset import ConfigSet
class ValidatedConfig(ConfigSet):
"""Configuration with validation rules."""
REQUIRED_SECTIONS = ['database', 'api', 'logging']
REQUIRED_OPTIONS = {
'database': ['host', 'port', 'name'],
'api': ['endpoint', 'key'],
'logging': ['level', 'file']
}
def validate(self):
"""Validate configuration against rules."""
errors = []
# Check required sections
for section in self.REQUIRED_SECTIONS:
if not self.has_section(section):
errors.append(f"โ Missing required section: [{section}]")
continue
# Check required options
required_opts = self.REQUIRED_OPTIONS.get(section, [])
for option in required_opts:
if not self.has_option(section, option):
errors.append(f"โ Missing required option: [{section}] {option}")
if errors:
print("\n".join(errors))
return False
print("โ
Configuration validation passed!")
return True
# Usage
config = ValidatedConfig('validated_app.ini')
if config.validate():
# Proceed with application
pass
```
## ๐ง Configuration
### ๐ Environment Variables
| Variable | Description | Values |
|----------|-------------|--------|
| DEBUG | Enable debug output | 1, true, yes |
| DEBUG_SERVER | Enable server debug mode | 1, true, yes |
| SHOW_CONFIGNAME | Show config file path | 1, true, yes |
### ๐จ Optional Dependencies
```bash
# Enhanced output with colors and formatting
pip install rich # Rich text and tables
pip install jsoncolor # JSON syntax highlighting
pip install make-colors # Terminal color support
```
## ๐ Migration Guide
### ๐ From v1.x to v2.x
**Breaking Changes:**
* Removed redundant methods (read_config2, read_config3, etc.)
* Simplified method signatures
* Enhanced type conversion
**Migration Steps:**
```python
# Old v1.x code
config.read_config2('section', 'option')
# New v2.x code
config.get_config_as_list('section', 'option')
```
### ๐ง Configuration File Format
**INI Format Example:**
```ini
[database]
host = localhost
port = 5432
ssl = true
features = load_balancer, ssl_support, monitoring
[api]
endpoint = https://api.example.com
timeout = 30
headers = {"Content-Type": "application/json", "Accept": "application/json"}
```
**JSON Format Example:**
```json
{
"database_host": "localhost",
"database_port": 5432,
"api_key": "secret123",
"debug_mode": true,
"feature_flags": ["auth", "cache", "monitoring"]
}
```
## ๐งช Testing
### ๐ Run Tests
```bash
# Install test dependencies
pip install pytest pytest-cov
# Run all tests
pytest tests/
# Run with coverage
pytest --cov=configset tests/
# Run specific test file
pytest tests/test_configset.py -v
```
### ๐ Test Example
```python
import pytest
from configset import ConfigSet
import tempfile
import os
def test_config_basic_operations():
"""Test basic configuration operations."""
with tempfile.NamedTemporaryFile(suffix='.ini', delete=False) as f:
config_file = f.name
try:
config = ConfigSet(config_file)
# Test write and read
config.write_config('test', 'key', 'value')
assert config.get_config('test', 'key') == 'value'
# Test type conversion
config.write_config('test', 'number', '42')
assert config.get_config('test', 'number') == 42
assert isinstance(config.get_config('test', 'number'), int)
# Test boolean
config.write_config('test', 'flag', 'true')
assert config.get_config('test', 'flag') is True
finally:
os.unlink(config_file)
```
## ๐ค Contributing
We welcome contributions! ๐
### ๐ Development Setup
```bash
# Clone repository
git clone https://github.com/cumulus13/configset.git
cd configset
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install development dependencies
pip install -e .[dev]
pip install pytest pytest-cov black isort mypy
```
### ๐ง Code Standards
```bash
# Format code
black configset/
isort configset/
# Type checking
mypy configset/
# Run tests
pytest tests/ --cov=configset
```
### ๐ Contributing Guidelines
1. ๐ด **Fork** the repository
2. ๐ **Create** a feature branch (`git checkout -b feature/amazing-feature`)
3. โ
**Add tests** for your changes
4. ๐ **Update documentation** if needed
5. ๐ฏ **Commit** your changes (`git commit -m 'Add amazing feature'`)
6. ๐ค **Push** to the branch (`git push origin feature/amazing-feature`)
7. ๐ **Open** a Pull Request
## ๐ Changelog
### ๐ v1.56 (Latest)
* โจ **New Features:**
* Enhanced type conversion system
* List and dictionary parsing
* Class-based configuration interface
* Improved CLI with delete operations
* Search functionality
* Pretty printing with colors
* ๐ง **Improvements:**
* Better error handling
* Python 2/3 compatibility
* Comprehensive documentation
* Unit tests coverage
* Type hints support
* ๐๏ธ **Removed:**
* Deprecated methods (read_config2, read_config3, etc.)
* Redundant functionality
### ๐ v1.x (Legacy)
* Basic INI file support
* Simple read/write operations
* Limited type conversion
## ๐ License
This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.
```
MIT License
Copyright (c) 2024 Hadi Cahyadi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
## ๐ Acknowledgments
* ๐ **Python ConfigParser** - Foundation for INI file handling
* ๐จ **Rich Library** - Enhanced terminal output
* ๐ **Make Colors** - Terminal color support
* ๐ฏ **JSONColor** - JSON syntax highlighting
* ๐ฅ **Contributors** - Thank you to all contributors!
## ๐ Support & Contact
* ๐ง **Email**: cumulus13@gmail.com
* ๐ **Issues**: [GitHub Issues](https://github.com/cumulus13/configset/issues)
* ๐ฌ **Discussions**: [GitHub Discussions](https://github.com/cumulus13/configset/discussions)
* ๐ **Documentation**: [Wiki](https://github.com/cumulus13/configset/wiki)
**โญ If you find ConfigSet useful, please consider giving it a star! โญ**
Made with โค๏ธ by developers, for developers.
[๐ Back to Top](#configset---enhanced-configuration-management-library)
## Support
* Python 2.7+, 3.x+
* Windows, Linux, Mac
## Author
[Hadi Cahyadi](mailto:cumulus13@gmail.com)
[Support me on Patreon](https://www.patreon.com/cumulus13)
[Medium](https://medium.com/@cumulus13/configset-a-powerful-python-configuration-management-library-that-actually-makes-sense-67bd622d059f)
Raw data
{
"_id": null,
"home_page": "https://github.com/cumulus13/configset",
"name": "configset",
"maintainer": "cumulus13",
"docs_url": null,
"requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7",
"maintainer_email": "cumulus13@gmail.com",
"keywords": "configuration, config, ini, json, settings, configparser, management, file, parser, setup",
"author": "Hadi Cahyadi",
"author_email": "cumulus13@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/63/0f/e11b312df34441eeff31d85e69b59251eb7b075d285a1fc50c5e44b92dfd/configset-1.86.tar.gz",
"platform": "any",
"description": "# \ud83d\udccb ConfigSet - Enhanced Configuration Management Library\r\n\r\n\ud83d\ude80 **A powerful and flexible configuration management library that supports both INI, JSON and YAML formats with automatic type conversion, list/dictionary parsing, and class-based interfaces.**\r\n\r\n## \ud83d\udcd6 Table of Contents\r\n\r\n* [\u2728 Features](#features)\r\n* [\ud83d\udce6 Installation](#installation)\r\n* [\ud83d\ude80 Quick Start](#quick-start)\r\n* [\ud83d\udcda Documentation](#documentation)\r\n* [\ud83c\udfaf Usage Examples](#usage-examples)\r\n* [\ud83d\udda5\ufe0f Command Line Interface](#command-line-interface)\r\n* [\ud83d\uddc3\ufe0f Advanced Usage](#advanced-usage)\r\n* [\ud83d\udd27 Configuration](#configuration)\r\n* [\ud83e\udd1d Contributing](#contributing)\r\n* [\ud83d\udcc4 License](#license)\r\n\r\n## \u2728 Features\r\n\r\n| Feature | Description | Icon |\r\n|---------|-------------|------|\r\n| INI Support | Full INI file configuration management | \ud83d\udcc4 |\r\n| JSON Support | JSON configuration with attribute-based access | \ud83d\uddc2\ufe0f |\r\n| Auto Type Conversion | Automatic string to bool/int/float conversion | \ud83d\udd04 |\r\n| List Parsing | Parse comma-separated, newline-separated, and JSON arrays | \ud83d\udcdd |\r\n| Dictionary Parsing | Parse key:value pairs and JSON objects | \ud83d\uddc3\ufe0f |\r\n| Class-based Interface | Metaclass-powered configuration classes | \ud83c\udfdb\ufe0f |\r\n| CLI Interface | Command-line tool for configuration management | \ud83d\udcbb |\r\n| Search Functionality | Find sections and options with case sensitivity control | \ud83d\udd0d |\r\n| Pretty Printing | Enhanced output with optional color support | \ud83c\udfa8 |\r\n| Python 2/3 Compatible | Works with both Python 2.7+ and Python 3.6+ | \ud83d\udc0d |\r\n\r\n## \ud83d\udce6 Installation\r\n\r\n### \ud83d\udccb Basic Installation\r\n\r\n```bash\r\n# Install from PyPI\r\npip install configset\r\n\r\n# Or clone the repository\r\ngit clone https://github.com/cumulus13/configset.git\r\ncd configset\r\n\r\n# Install the package in editable/development mode\r\npip install -e .\r\n\r\n# Or install the latest development version directly from GitHub\r\npip install git+https://github.com/cumulus13/configset.git\r\n```\r\n\r\n### \ud83c\udfa8 With Optional Dependencies (Recommended)\r\n\r\n```bash\r\n# Install with enhanced output support\r\npip install -e .[full]\r\n\r\n# Or install dependencies manually\r\npip install rich jsoncolor make-colors\r\n```\r\n\r\n### \ud83d\udccb Requirements\r\n\r\n* **Python 2.7+ or Python 3.6+**\r\n* **Optional**: rich, jsoncolor, make-colors for enhanced output\r\n\r\n## \ud83d\ude80 Quick Start\r\n\r\n### \ud83d\udcc4 Basic INI Configuration\r\n\r\n```python\r\nfrom configset import ConfigSet\r\n# or from configset import configset\r\n\r\n# Create configuration instance\r\nconfig = ConfigSet('myapp.ini')\r\n# or config = configset('myapp.ini')\r\n\r\n# Write configuration\r\nconfig.write_config('database', 'host', 'localhost')\r\nconfig.write_config('database', 'port', 5432)\r\nconfig.write_config('database', 'ssl', True)\r\n\r\n# Read configuration (with automatic type conversion)\r\nhost = config.get_config('database', 'host') # Returns: 'localhost'\r\nport = config.get_config('database', 'port') # Returns: 5432 (int)\r\nssl = config.get_config('database', 'ssl') # Returns: True (bool)\r\n```\r\n\r\n### \ud83c\udfdb\ufe0f Class-based Configuration\r\n\r\n```python\r\nfrom configset import CONFIG\r\n\r\nclass AppConfig(CONFIG):\r\n CONFIGFILE = 'myapp.ini'\r\n\r\n# Use as class methods\r\nAppConfig.write_config('api', 'endpoint', 'https://api.example.com')\r\nendpoint = AppConfig.get_config('api', 'endpoint')\r\n\r\n# JSON-style attribute access\r\nconfig = AppConfig()\r\nconfig.api_key = 'secret123'\r\nconfig.debug_mode = True\r\nprint(f\"API Key: {config.api_key}\") # Output: API Key: secret123\r\n```\r\n\r\n## \ud83d\udcda Documentation\r\n\r\n### \ud83d\udd27 ConfigSet Class\r\n\r\nThe main class for INI file configuration management.\r\n\r\n#### \ud83c\udfd7 Constructor\r\n\r\n```python\r\nConfigSet(config_file='', auto_write=True, **kwargs)\r\n```\r\n\r\n| Parameter | Type | Default | Description |\r\n|-----------|------|---------|-------------|\r\n| config_file | str | '' | Path to configuration file |\r\n| auto_write | bool | True | Auto-create missing files/sections |\r\n| **kwargs | dict | {} | Additional ConfigParser arguments |\r\n\r\n#### \ud83d\udd11 Key Methods\r\n\r\n| Method | Description | Return Type |\r\n|--------|-------------|-------------|\r\n| get_config(section, option, default=None) | Get config value with type conversion | Any |\r\n| write_config(section, option, value) | Write config value to file | Any |\r\n| remove_config(section, option=None) | Remove section or specific option | bool |\r\n| get_config_as_list(section, option, default=None) | Parse value as list | List[Any] |\r\n| get_config_as_dict(section, option, default=None) | Parse value as dictionary | Dict[str, Any] |\r\n| find(query, case_sensitive=True, verbose=False) | Search sections/options | bool |\r\n| print_all_config(sections=None) | Print all configuration | List[Tuple] |\r\n\r\n## \ud83c\udfaf Usage Examples\r\n\r\n### \ud83d\udccb List Configuration\r\n\r\n```python\r\nconfig = ConfigSet('servers.ini')\r\n\r\n# Write list data (multiple formats supported)\r\nconfig.write_config('cluster', 'servers', 'server1.com, server2.com, server3.com')\r\nconfig.write_config('cluster', 'ports', '[8080, 8081, 8082]')\r\nconfig.write_config('cluster', 'features', '''\r\n load_balancer\r\n ssl_support\r\n monitoring\r\n''')\r\n\r\n# Read as lists (automatic parsing)\r\nservers = config.get_config_as_list('cluster', 'servers')\r\n# Returns: ['server1.com', 'server2.com', 'server3.com']\r\n\r\nports = config.get_config_as_list('cluster', 'ports')\r\n# Returns: [8080, 8081, 8082]\r\n\r\nfeatures = config.get_config_as_list('cluster', 'features')\r\n# Returns: ['load_balancer', 'ssl_support', 'monitoring']\r\n```\r\n\r\n### \ud83d\uddc3\ufe0f Dictionary Configuration\r\n\r\n```python\r\nconfig = ConfigSet('settings.ini')\r\n\r\n# Write dictionary data\r\nconfig.write_config('limits', 'quotas', 'users:1000, files:5000, bandwidth:100')\r\nconfig.write_config('features', 'enabled', '{\"auth\": true, \"cache\": false, \"debug\": true}')\r\n\r\n# Read as dictionaries\r\nquotas = config.get_config_as_dict('limits', 'quotas')\r\n# Returns: {'users': 1000, 'files': 5000, 'bandwidth': 100}\r\n\r\nfeatures = config.get_config_as_dict('features', 'enabled')\r\n# Returns: {'auth': True, 'cache': False, 'debug': True}\r\n```\r\n\r\n### \ud83d\udd0d Search and Remove\r\n\r\n```python\r\nconfig = ConfigSet('myapp.ini')\r\n\r\n# Search for sections/options\r\nfound = config.find('database') # Returns: True if found\r\nconfig.find('host', verbose=True) # Print found items\r\n\r\n# Remove operations\r\nconfig.remove_config('old_section') # Remove entire section\r\nconfig.remove_config('database', 'old_option') # Remove specific option\r\n```\r\n\r\n## \ud83d\udda5\ufe0f Command Line Interface\r\n\r\nThe ConfigSet library includes a powerful CLI for configuration management.\r\n\r\n### \ud83d\udccb Basic Commands\r\n\r\n```bash\r\n# Show help\r\npython -m configset --help\r\n\r\n# Read all configuration\r\npython -m configset myapp.ini --all\r\n\r\n# Read specific value\r\npython -m configset myapp.ini --read --section database --option host\r\n\r\n# Write configuration\r\npython -m configset myapp.ini --write --section database --option host --value localhost\r\n\r\n# Remove section\r\npython -m configset myapp.ini --delete --section old_section\r\n\r\n# Remove specific option\r\npython -m configset myapp.ini --delete --section database --option password\r\n```\r\n\r\n### \ud83c\udf9b\ufe0f Advanced CLI Usage\r\n\r\n```bash\r\n# Parse as list\r\npython -m configset myapp.ini --read --section cluster --option servers --list\r\n\r\n# Parse as dictionary\r\npython -m configset myapp.ini --read --section limits --option quotas --dict\r\n\r\n# Enable debug mode\r\nDEBUG=1 python -m configset myapp.ini --all\r\n```\r\n\r\n## \ud83d\uddc3\ufe0f Advanced Usage\r\n\r\n### \ud83c\udfa8 Custom Configuration Classes\r\n\r\n```python\r\nfrom configset import CONFIG, ConfigSet\r\n\r\nclass DatabaseConfig(CONFIG):\r\n CONFIGFILE = 'database.ini'\r\n \r\n @classmethod\r\n def get_connection_string(cls):\r\n host = cls.get_config('database', 'host')\r\n port = cls.get_config('database', 'port')\r\n db = cls.get_config('database', 'name')\r\n return f\"postgresql://{host}:{port}/{db}\"\r\n\r\nclass APIConfig(CONFIG):\r\n CONFIGFILE = 'api.ini'\r\n \r\n def __init__(self):\r\n super().__init__()\r\n # Set default values\r\n if not hasattr(self, 'timeout'):\r\n self.timeout = 30\r\n if not hasattr(self, 'retries'):\r\n self.retries = 3\r\n\r\n# Usage\r\ndb_config = DatabaseConfig()\r\nconnection = db_config.get_connection_string()\r\n\r\napi_config = APIConfig()\r\napi_config.endpoint = 'https://api.example.com'\r\nprint(f\"Timeout: {api_config.timeout}\") # Output: Timeout: 30\r\n```\r\n\r\n### \ud83d\udd04 Configuration Migration\r\n\r\n```python\r\ndef migrate_config_v1_to_v2(old_config_file, new_config_file):\r\n \"\"\"Migrate configuration from v1 to v2 format.\"\"\"\r\n old_config = ConfigSet(old_config_file)\r\n new_config = ConfigSet(new_config_file)\r\n \r\n # Copy all sections and options\r\n for section_name, section_data in old_config.get_all_config():\r\n for option, value in section_data.items():\r\n # Apply any transformations needed\r\n if section_name == 'database' and option == 'ssl':\r\n value = 'enabled' if value else 'disabled'\r\n \r\n new_config.write_config(section_name, option, value)\r\n \r\n print(f\"\u2705 Migration completed: {old_config_file} \u2192 {new_config_file}\")\r\n\r\n# Usage\r\nmigrate_config_v1_to_v2('old_app.ini', 'new_app.ini')\r\n```\r\n\r\n### \ud83e\uddea Configuration Validation\r\n\r\n```python\r\nfrom configset import ConfigSet\r\n\r\nclass ValidatedConfig(ConfigSet):\r\n \"\"\"Configuration with validation rules.\"\"\"\r\n \r\n REQUIRED_SECTIONS = ['database', 'api', 'logging']\r\n REQUIRED_OPTIONS = {\r\n 'database': ['host', 'port', 'name'],\r\n 'api': ['endpoint', 'key'],\r\n 'logging': ['level', 'file']\r\n }\r\n \r\n def validate(self):\r\n \"\"\"Validate configuration against rules.\"\"\"\r\n errors = []\r\n \r\n # Check required sections\r\n for section in self.REQUIRED_SECTIONS:\r\n if not self.has_section(section):\r\n errors.append(f\"\u274c Missing required section: [{section}]\")\r\n continue\r\n \r\n # Check required options\r\n required_opts = self.REQUIRED_OPTIONS.get(section, [])\r\n for option in required_opts:\r\n if not self.has_option(section, option):\r\n errors.append(f\"\u274c Missing required option: [{section}] {option}\")\r\n \r\n if errors:\r\n print(\"\\n\".join(errors))\r\n return False\r\n \r\n print(\"\u2705 Configuration validation passed!\")\r\n return True\r\n\r\n# Usage\r\nconfig = ValidatedConfig('validated_app.ini')\r\nif config.validate():\r\n # Proceed with application\r\n pass\r\n```\r\n\r\n## \ud83d\udd27 Configuration\r\n\r\n### \ud83c\udf0d Environment Variables\r\n\r\n| Variable | Description | Values |\r\n|----------|-------------|--------|\r\n| DEBUG | Enable debug output | 1, true, yes |\r\n| DEBUG_SERVER | Enable server debug mode | 1, true, yes |\r\n| SHOW_CONFIGNAME | Show config file path | 1, true, yes |\r\n\r\n### \ud83c\udfa8 Optional Dependencies\r\n\r\n```bash\r\n# Enhanced output with colors and formatting\r\npip install rich # Rich text and tables\r\npip install jsoncolor # JSON syntax highlighting \r\npip install make-colors # Terminal color support\r\n```\r\n\r\n## \ud83d\udcc4 Migration Guide\r\n\r\n### \ud83d\udcc8 From v1.x to v2.x\r\n\r\n**Breaking Changes:**\r\n\r\n* Removed redundant methods (read_config2, read_config3, etc.)\r\n* Simplified method signatures\r\n* Enhanced type conversion\r\n\r\n**Migration Steps:**\r\n\r\n```python\r\n# Old v1.x code\r\nconfig.read_config2('section', 'option')\r\n\r\n# New v2.x code \r\nconfig.get_config_as_list('section', 'option')\r\n```\r\n\r\n### \ud83d\udd27 Configuration File Format\r\n\r\n**INI Format Example:**\r\n\r\n```ini\r\n[database]\r\nhost = localhost\r\nport = 5432\r\nssl = true\r\nfeatures = load_balancer, ssl_support, monitoring\r\n\r\n[api]\r\nendpoint = https://api.example.com\r\ntimeout = 30\r\nheaders = {\"Content-Type\": \"application/json\", \"Accept\": \"application/json\"}\r\n```\r\n\r\n**JSON Format Example:**\r\n\r\n```json\r\n{\r\n \"database_host\": \"localhost\",\r\n \"database_port\": 5432,\r\n \"api_key\": \"secret123\",\r\n \"debug_mode\": true,\r\n \"feature_flags\": [\"auth\", \"cache\", \"monitoring\"]\r\n}\r\n```\r\n\r\n## \ud83e\uddea Testing\r\n\r\n### \ud83d\ude80 Run Tests\r\n\r\n```bash\r\n# Install test dependencies\r\npip install pytest pytest-cov\r\n\r\n# Run all tests\r\npytest tests/\r\n\r\n# Run with coverage\r\npytest --cov=configset tests/\r\n\r\n# Run specific test file\r\npytest tests/test_configset.py -v\r\n```\r\n\r\n### \ud83d\udd0d Test Example\r\n\r\n```python\r\nimport pytest\r\nfrom configset import ConfigSet\r\nimport tempfile\r\nimport os\r\n\r\ndef test_config_basic_operations():\r\n \"\"\"Test basic configuration operations.\"\"\"\r\n with tempfile.NamedTemporaryFile(suffix='.ini', delete=False) as f:\r\n config_file = f.name\r\n \r\n try:\r\n config = ConfigSet(config_file)\r\n \r\n # Test write and read\r\n config.write_config('test', 'key', 'value')\r\n assert config.get_config('test', 'key') == 'value'\r\n \r\n # Test type conversion\r\n config.write_config('test', 'number', '42')\r\n assert config.get_config('test', 'number') == 42\r\n assert isinstance(config.get_config('test', 'number'), int)\r\n \r\n # Test boolean\r\n config.write_config('test', 'flag', 'true')\r\n assert config.get_config('test', 'flag') is True\r\n \r\n finally:\r\n os.unlink(config_file)\r\n```\r\n\r\n## \ud83e\udd1d Contributing\r\n\r\nWe welcome contributions! \ud83c\udf89\r\n\r\n### \ud83d\udccb Development Setup\r\n\r\n```bash\r\n# Clone repository\r\ngit clone https://github.com/cumulus13/configset.git\r\ncd configset\r\n\r\n# Create virtual environment\r\npython -m venv venv\r\nsource venv/bin/activate # On Windows: venv\\Scripts\\activate\r\n\r\n# Install development dependencies\r\npip install -e .[dev]\r\npip install pytest pytest-cov black isort mypy\r\n```\r\n\r\n### \ud83d\udd27 Code Standards\r\n\r\n```bash\r\n# Format code\r\nblack configset/\r\nisort configset/\r\n\r\n# Type checking\r\nmypy configset/\r\n\r\n# Run tests\r\npytest tests/ --cov=configset\r\n```\r\n\r\n### \ud83d\udcdd Contributing Guidelines\r\n\r\n1. \ud83c\udf74 **Fork** the repository\r\n2. \ud83c\udf1f **Create** a feature branch (`git checkout -b feature/amazing-feature`)\r\n3. \u2705 **Add tests** for your changes\r\n4. \ud83d\udcdd **Update documentation** if needed\r\n5. \ud83c\udfaf **Commit** your changes (`git commit -m 'Add amazing feature'`)\r\n6. \ud83d\udce4 **Push** to the branch (`git push origin feature/amazing-feature`)\r\n7. \ud83d\udcc4 **Open** a Pull Request\r\n\r\n## \ud83d\udcca Changelog\r\n\r\n### \ud83c\udf89 v1.56 (Latest)\r\n\r\n* \u2728 **New Features:**\r\n * Enhanced type conversion system\r\n * List and dictionary parsing\r\n * Class-based configuration interface\r\n * Improved CLI with delete operations\r\n * Search functionality\r\n * Pretty printing with colors\r\n* \ud83d\udd27 **Improvements:**\r\n * Better error handling\r\n * Python 2/3 compatibility\r\n * Comprehensive documentation\r\n * Unit tests coverage\r\n * Type hints support\r\n* \ud83d\uddd1\ufe0f **Removed:**\r\n * Deprecated methods (read_config2, read_config3, etc.)\r\n * Redundant functionality\r\n\r\n### \ud83d\udcda v1.x (Legacy)\r\n\r\n* Basic INI file support\r\n* Simple read/write operations\r\n* Limited type conversion\r\n\r\n## \ud83d\udcc4 License\r\n\r\nThis project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.\r\n\r\n```\r\nMIT License\r\n\r\nCopyright (c) 2024 Hadi Cahyadi\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy\r\nof this software and associated documentation files (the \"Software\"), to deal\r\nin the Software without restriction, including without limitation the rights\r\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, and to permit persons to whom the Software is\r\nfurnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all\r\ncopies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\nSOFTWARE.\r\n```\r\n\r\n## \ud83d\ude4f Acknowledgments\r\n\r\n* \ud83d\udc0d **Python ConfigParser** - Foundation for INI file handling\r\n* \ud83c\udfa8 **Rich Library** - Enhanced terminal output\r\n* \ud83c\udf08 **Make Colors** - Terminal color support\r\n* \ud83c\udfaf **JSONColor** - JSON syntax highlighting\r\n* \ud83d\udc65 **Contributors** - Thank you to all contributors!\r\n\r\n## \ud83d\udcde Support & Contact\r\n\r\n* \ud83d\udce7 **Email**: cumulus13@gmail.com\r\n* \ud83d\udc1b **Issues**: [GitHub Issues](https://github.com/cumulus13/configset/issues)\r\n* \ud83d\udcac **Discussions**: [GitHub Discussions](https://github.com/cumulus13/configset/discussions)\r\n* \ud83d\udcd6 **Documentation**: [Wiki](https://github.com/cumulus13/configset/wiki)\r\n\r\n**\u2b50 If you find ConfigSet useful, please consider giving it a star! \u2b50**\r\n\r\nMade with \u2764\ufe0f by developers, for developers.\r\n\r\n[\ud83d\udd1d Back to Top](#configset---enhanced-configuration-management-library)\r\n\r\n## Support\r\n\r\n* Python 2.7+, 3.x+\r\n* Windows, Linux, Mac\r\n\r\n## Author\r\n\r\n[Hadi Cahyadi](mailto:cumulus13@gmail.com)\r\n\r\n[Support me on Patreon](https://www.patreon.com/cumulus13)\r\n\r\n[Medium](https://medium.com/@cumulus13/configset-a-powerful-python-configuration-management-library-that-actually-makes-sense-67bd622d059f)\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A powerful and flexible configuration management library that supports both INI and JSON formats with automatic type conversion, list/dictionary parsing, and class-based interfaces.",
"version": "1.86",
"project_urls": {
"Bug Tracker": "https://github.com/cumulus13/configset/issues",
"Changelog": "https://github.com/cumulus13/configset/releases",
"Documentation": "https://github.com/cumulus13/configset/wiki",
"Homepage": "https://github.com/cumulus13/configset",
"Source Code": "https://github.com/cumulus13/configset"
},
"split_keywords": [
"configuration",
" config",
" ini",
" json",
" settings",
" configparser",
" management",
" file",
" parser",
" setup"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "595bce29fb36d405647bd4b256d880b7c79c1610870e2d7e1b1c25066d93637b",
"md5": "7e4899dcfa6e75713065a77afbb8d885",
"sha256": "2cd96ae2cac5d2c3590354c77df4771e664b2ce4ff7abd8920b646ea07d54b64"
},
"downloads": -1,
"filename": "configset-1.86-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "7e4899dcfa6e75713065a77afbb8d885",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7",
"size": 55165,
"upload_time": "2025-09-13T14:44:07",
"upload_time_iso_8601": "2025-09-13T14:44:07.928247Z",
"url": "https://files.pythonhosted.org/packages/59/5b/ce29fb36d405647bd4b256d880b7c79c1610870e2d7e1b1c25066d93637b/configset-1.86-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "630fe11b312df34441eeff31d85e69b59251eb7b075d285a1fc50c5e44b92dfd",
"md5": "6fa8df75e0be0d961ab748746f9a2ac9",
"sha256": "bad7eb730932851ccd24cf2c8ffadf1d451ea47f06f203b36eb5d22633b82e2a"
},
"downloads": -1,
"filename": "configset-1.86.tar.gz",
"has_sig": false,
"md5_digest": "6fa8df75e0be0d961ab748746f9a2ac9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7",
"size": 62961,
"upload_time": "2025-09-13T14:44:10",
"upload_time_iso_8601": "2025-09-13T14:44:10.452848Z",
"url": "https://files.pythonhosted.org/packages/63/0f/e11b312df34441eeff31d85e69b59251eb7b075d285a1fc50c5e44b92dfd/configset-1.86.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-13 14:44:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cumulus13",
"github_project": "configset",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "rich",
"specs": [
[
">=",
"10.0.0"
]
]
},
{
"name": "pyyaml",
"specs": []
}
],
"lcname": "configset"
}